Skip to content

Commit

Permalink
fix: error handling for option and update comment
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Jan 24, 2024
1 parent c5553fd commit d53e69e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/db/kvs/pogreb/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func WithPath(path string) Option {

// WithBackgroundSyncInterval returns the option to sets the amount of time between background Sync() calls.
// Setting the value to 0 disables the automatic background synchronization.
// Setting the value to -1 makes the DB call Sync() after every write operation.
// Setting the value to -1 or less makes the DB call Sync() after every write operation.
func WithBackgroundSyncInterval(s string) Option {
return func(d *db) error {
if s == "" {
Expand All @@ -61,6 +61,7 @@ func WithBackgroundSyncInterval(s string) Option {
}

// WithBackgroundCompactionInterval returns the option to sets the amount of time between background Compact() calls.
// Setting the value to 0 or less disables the automatic background compaction.
func WithBackgroundCompactionInterval(s string) Option {
return func(d *db) error {
if s == "" {
Expand All @@ -73,6 +74,7 @@ func WithBackgroundCompactionInterval(s string) Option {
if d.opts == nil {
d.opts = new(pogreb.Options)
}

if dur < 0 {
dur = -1
}

Check warning on line 80 in internal/db/kvs/pogreb/options.go

View check run for this annotation

Codecov / codecov/patch

internal/db/kvs/pogreb/options.go#L79-L80

Added lines #L79 - L80 were not covered by tests
Expand Down
9 changes: 8 additions & 1 deletion internal/db/kvs/pogreb/pogreb.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/vdaas/vald/internal/conv"
"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/log"
)

// Pogreb represents an interface for operating the pogreb database.
Expand All @@ -47,7 +48,13 @@ func New(opts ...Option) (_ Pogreb, err error) {
db := new(db)
for _, opt := range append(deafultOpts, opts...) {
if err := opt(db); err != nil {
return nil, errors.ErrOptionFailed(err, reflect.ValueOf(opt))
oerr := errors.ErrOptionFailed(err, reflect.ValueOf(opt))
e := &errors.ErrCriticalOption{}
if errors.As(oerr, &e) {
log.Error(err)
return nil, oerr
}
log.Warn(oerr)

Check warning on line 57 in internal/db/kvs/pogreb/pogreb.go

View check run for this annotation

Codecov / codecov/patch

internal/db/kvs/pogreb/pogreb.go#L51-L57

Added lines #L51 - L57 were not covered by tests
}
}

Expand Down

0 comments on commit d53e69e

Please sign in to comment.