Explorar o código

Fixed keyExists panic when the table not exists

TC pushbot 5 %!s(int64=4) %!d(string=hai) anos
pai
achega
4fc3ae82ac
Modificáronse 1 ficheiros con 4 adicións e 0 borrados
  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))