From 60add3be86e855a04fdb4f5bb820f20096f36ea3 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 6 Jul 2024 12:02:58 +1200 Subject: [PATCH] db: add common errunsupported --- db_badger.go | 5 ++--- db_bolt.go | 2 +- db_debconf.go | 5 ++--- db_none.go | 6 ++---- db_pebble.go | 5 ++--- db_redis.go | 3 +-- db_sqlite.go | 3 +-- loadedDatabase.go | 1 + 8 files changed, 12 insertions(+), 18 deletions(-) diff --git a/db_badger.go b/db_badger.go index 18e908c..40e5fcf 100644 --- a/db_badger.go +++ b/db_badger.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "path/filepath" "unsafe" @@ -85,7 +84,7 @@ func (ld *badgerLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) { } func (n *badgerLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error { - return errors.New("Editing is not supported") + return ErrNotSupported } func (ld *badgerLoadedDatabase) NavChildren(ndata *navData) ([]string, error) { @@ -104,7 +103,7 @@ func (ld *badgerLoadedDatabase) NavContext(ndata *navData) ([]contextAction, err } func (ld *badgerLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error { - return errors.New("Badger doesn't support querying") + return ErrNotSupported } func (ld *badgerLoadedDatabase) Close() { diff --git a/db_bolt.go b/db_bolt.go index 3e43c76..de09827 100644 --- a/db_bolt.go +++ b/db_bolt.go @@ -186,7 +186,7 @@ func (ld *boltLoadedDatabase) DeleteBucket(ndata *navData) { } func (ld *boltLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error { - return errors.New("Bolt doesn't support querying") + return ErrNotSupported } func (ld *boltLoadedDatabase) Close() { diff --git a/db_debconf.go b/db_debconf.go index 1e632cb..a0c44d3 100644 --- a/db_debconf.go +++ b/db_debconf.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "os" "path/filepath" @@ -71,7 +70,7 @@ func (ld *debconfLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) { } func (n *debconfLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error { - return errors.New("Editing is not supported") + return ErrNotSupported } func (ld *debconfLoadedDatabase) NavChildren(ndata *navData) ([]string, error) { @@ -90,7 +89,7 @@ func (ld *debconfLoadedDatabase) NavContext(ndata *navData) ([]contextAction, er } func (ld *debconfLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error { - return errors.New("debconf doesn't support querying") + return ErrNotSupported } func (ld *debconfLoadedDatabase) Close() { diff --git a/db_none.go b/db_none.go index 1d75b4b..c509e83 100644 --- a/db_none.go +++ b/db_none.go @@ -1,8 +1,6 @@ package main import ( - "errors" - "github.com/ying32/govcl/vcl" ) @@ -25,11 +23,11 @@ func (n *noLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) { } func (n *noLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error { - return errors.New("Editing is not supported") + return ErrNotSupported } func (n *noLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error { - return nil + return ErrNotSupported } func (n *noLoadedDatabase) NavChildren(ndata *navData) ([]string, error) { diff --git a/db_pebble.go b/db_pebble.go index 0ea2f98..31f7f34 100644 --- a/db_pebble.go +++ b/db_pebble.go @@ -2,7 +2,6 @@ package main import ( "context" - "errors" "fmt" "path/filepath" "unsafe" @@ -76,7 +75,7 @@ func (ld *pebbleLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) { } func (n *pebbleLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error { - return errors.New("Editing is not supported") + return ErrNotSupported } func (ld *pebbleLoadedDatabase) NavChildren(ndata *navData) ([]string, error) { @@ -95,7 +94,7 @@ func (ld *pebbleLoadedDatabase) NavContext(ndata *navData) ([]contextAction, err } func (ld *pebbleLoadedDatabase) ExecQuery(query string, resultArea *vcl.TStringGrid) error { - return errors.New("pebble doesn't support querying") + return ErrNotSupported } func (ld *pebbleLoadedDatabase) Close() { diff --git a/db_redis.go b/db_redis.go index d4dd5a4..8073b42 100644 --- a/db_redis.go +++ b/db_redis.go @@ -2,7 +2,6 @@ package main import ( "context" - "errors" "fmt" "strconv" "unsafe" @@ -139,7 +138,7 @@ func (ld *redisLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) { } func (n *redisLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error { - return errors.New("Editing is not supported") + return ErrNotSupported } func (ld *redisLoadedDatabase) NavChildren(ndata *navData) ([]string, error) { diff --git a/db_sqlite.go b/db_sqlite.go index a7fe190..c792b17 100644 --- a/db_sqlite.go +++ b/db_sqlite.go @@ -2,7 +2,6 @@ package main import ( "database/sql" - "errors" "fmt" "path/filepath" "unsafe" @@ -98,7 +97,7 @@ func (ld *sqliteLoadedDatabase) RenderForNav(f *TMainForm, ndata *navData) { } func (n *sqliteLoadedDatabase) ApplyChanges(f *TMainForm, ndata *navData) error { - return errors.New("Editing is not supported") + return ErrNotSupported } func (ld *sqliteLoadedDatabase) sqliteGetColumnNamesForTable(tableName string) ([]string, error) { diff --git a/loadedDatabase.go b/loadedDatabase.go index 0d7eef0..3ea6381 100644 --- a/loadedDatabase.go +++ b/loadedDatabase.go @@ -7,6 +7,7 @@ import ( ) var ErrNavNotExist error = errors.New("The selected item no longer exists") +var ErrNotSupported error = errors.New("Unsupported action for this database type") type contextAction struct { Name string