Simplify errors

This commit is contained in:
Tobie Morgan Hitchcock 2019-11-28 16:33:09 +00:00
parent e84fe44959
commit 9deae2c466
3 changed files with 5 additions and 31 deletions

View file

@ -492,8 +492,6 @@ func status(e error) (s string) {
return "OK" return "OK"
case *kvs.DBError: case *kvs.DBError:
return "ERR_DB" return "ERR_DB"
case *kvs.KVError:
return "ERR_KV"
case *PermsError: case *PermsError:
return "ERR_PE" return "ERR_PE"
case *ExistError: case *ExistError:

View file

@ -24,19 +24,5 @@ type DBError struct {
// Error returns the string representation of the error. // Error returns the string representation of the error.
func (e *DBError) Error() string { func (e *DBError) Error() string {
return fmt.Sprintf("Unable to write to the database") return fmt.Sprintf("Unable to write to the database: %s", e.Err)
}
// KVError is an error which occurs when there is a
// problem with a conditional put or delete.
type KVError struct {
Err error
Key []byte
Val []byte
Exp []byte
}
// Error returns the string representation of the error.
func (e *KVError) Error() string {
return fmt.Sprintf("Database record already exists")
} }

View file

@ -27,13 +27,8 @@ type TX struct {
func one(res *rixxdb.KV, err error) (kvs.KV, error) { func one(res *rixxdb.KV, err error) (kvs.KV, error) {
switch err { if err != nil {
case nil: return nil, &kvs.DBError{Err: err}
break
default:
return nil, &kvs.DBError{}
case rixxdb.ErrTxNotExpectedValue:
return nil, &kvs.KVError{}
} }
return res, err return res, err
@ -42,13 +37,8 @@ func one(res *rixxdb.KV, err error) (kvs.KV, error) {
func many(res []*rixxdb.KV, err error) ([]kvs.KV, error) { func many(res []*rixxdb.KV, err error) ([]kvs.KV, error) {
switch err { if err != nil {
case nil: return nil, &kvs.DBError{Err: err}
break
default:
return nil, &kvs.DBError{}
case rixxdb.ErrTxNotExpectedValue:
return nil, &kvs.KVError{}
} }
var out = make([]kvs.KV, len(res)) var out = make([]kvs.KV, len(res))