From 9deae2c46661f2d72be7bf4dd2138e542e142839 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 28 Nov 2019 16:33:09 +0000 Subject: [PATCH] Simplify errors --- db/executor.go | 2 -- kvs/err.go | 16 +--------------- kvs/rixxdb/tx.go | 18 ++++-------------- 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/db/executor.go b/db/executor.go index d5497585..3716930c 100644 --- a/db/executor.go +++ b/db/executor.go @@ -492,8 +492,6 @@ func status(e error) (s string) { return "OK" case *kvs.DBError: return "ERR_DB" - case *kvs.KVError: - return "ERR_KV" case *PermsError: return "ERR_PE" case *ExistError: diff --git a/kvs/err.go b/kvs/err.go index 637bb79d..adbf5c4e 100644 --- a/kvs/err.go +++ b/kvs/err.go @@ -24,19 +24,5 @@ type DBError struct { // Error returns the string representation of the error. func (e *DBError) Error() string { - return fmt.Sprintf("Unable to write to the database") -} - -// 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") + return fmt.Sprintf("Unable to write to the database: %s", e.Err) } diff --git a/kvs/rixxdb/tx.go b/kvs/rixxdb/tx.go index 67b31582..27e6a8bc 100644 --- a/kvs/rixxdb/tx.go +++ b/kvs/rixxdb/tx.go @@ -27,13 +27,8 @@ type TX struct { func one(res *rixxdb.KV, err error) (kvs.KV, error) { - switch err { - case nil: - break - default: - return nil, &kvs.DBError{} - case rixxdb.ErrTxNotExpectedValue: - return nil, &kvs.KVError{} + if err != nil { + return nil, &kvs.DBError{Err: 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) { - switch err { - case nil: - break - default: - return nil, &kvs.DBError{} - case rixxdb.ErrTxNotExpectedValue: - return nil, &kvs.KVError{} + if err != nil { + return nil, &kvs.DBError{Err: err} } var out = make([]kvs.KV, len(res))