2 Commits

Author SHA1 Message Date
T. von Dein
1d45b2c6fe update linter config, satisfy linter (#28) 2026-08-31 22:06:25 +02:00
T. von Dein
5c9900d985 fix #26: check db file existence before trying to read from it (#27) 2026-08-31 21:12:50 +02:00
3 changed files with 17 additions and 1 deletions

View File

@@ -92,6 +92,14 @@ func New(file string, bucket string, debug bool) (*DB, error) {
return &DB{Debug: debug, Dbfile: file, Bucket: bucket}, nil
}
func (db *DB) Exists() error {
if !common.FileExists(db.Dbfile) {
return fmt.Errorf("db file %s doesn't exist", db.Dbfile)
}
return nil
}
func (db *DB) Open() error {
slog.Debug("opening DB", "dbfile", db.Dbfile)

View File

@@ -30,7 +30,7 @@ import (
"github.com/tlinden/yadu"
)
var Version string = "v0.3.1"
var Version string = "v0.3.2"
type BucketConfig struct {
Encrypt bool

View File

@@ -107,6 +107,10 @@ func Get(conf *cfg.Config) *cobra.Command {
attr.Key = args[0]
}
if err := conf.DB.Exists(); err != nil {
return err
}
entry, err := conf.DB.Get(&attr)
if err != nil {
return err
@@ -208,6 +212,10 @@ func List(conf *cfg.Config) *cobra.Command {
conf.Mode = "wide"
}
if err := conf.DB.Exists(); err != nil {
return err
}
entries, err := conf.DB.List(&attr, conf.Fulltext)
if err != nil {
return err