Просмотр исходного кода

Fixed keyExists panic when the table not exists

TC pushbot 5 4 лет назад
Родитель
Сommit
4fc3ae82ac
1 измененных файлов с 4 добавлено и 0 удалено
  1. 4 0
      mod/database/database.go

+ 4 - 0
mod/database/database.go

@@ -165,6 +165,10 @@ func (d *Database) Read(tableName string, key string, assignee interface{}) erro
 
 func (d *Database) KeyExists(tableName string, key string) bool {
 	resultIsNil := false
+	if !d.TableExists(tableName) {
+		//Table not exists. Do not proceed accessing key
+		return false
+	}
 	err := d.Db.View(func(tx *bolt.Tx) error {
 		b := tx.Bucket([]byte(tableName))
 		v := b.Get([]byte(key))