diff --git a/go/viperutil/internal/sync/sync.go b/go/viperutil/internal/sync/sync.go index c211c5fa611..11cb028c286 100644 --- a/go/viperutil/internal/sync/sync.go +++ b/go/viperutil/internal/sync/sync.go @@ -18,7 +18,6 @@ package sync import ( "context" - "errors" "fmt" "sync" "time" @@ -28,6 +27,8 @@ import ( "github.com/spf13/viper" "vitess.io/vitess/go/viperutil/internal/log" + "vitess.io/vitess/go/vt/proto/vtrpc" + "vitess.io/vitess/go/vt/vterrors" ) // Viper is a wrapper around a pair of viper.Viper instances to provide config- @@ -89,7 +90,7 @@ func (v *Viper) Set(key string, value any) { // ErrDuplicateWatch is returned when Watch is called on a synced Viper which // has already started a watch. -var ErrDuplicateWatch = errors.New("duplicate watch") +var ErrDuplicateWatch = vterrors.New(vtrpc.Code_FAILED_PRECONDITION, "duplicate watch") // Watch starts watching the config used by the passed-in Viper. Before starting // the watch, the synced viper will perform an initial read and load from disk @@ -121,7 +122,7 @@ var ErrDuplicateWatch = errors.New("duplicate watch") // to ensure the config file can be read in properly. func (v *Viper) Watch(ctx context.Context, static *viper.Viper, minWaitInterval time.Duration) (cancel context.CancelFunc, err error) { if v.watchingConfig { - return nil, fmt.Errorf("%w: viper is already watching %s", ErrDuplicateWatch, v.disk.ConfigFileUsed()) + return nil, vterrors.Wrapf(ErrDuplicateWatch, "%s: viper is already watching %s", ErrDuplicateWatch.Error(), v.disk.ConfigFileUsed()) } ctx, cancel = context.WithCancel(ctx) diff --git a/go/viperutil/internal/value/value.go b/go/viperutil/internal/value/value.go index 9feb5caba02..a958d642bcf 100644 --- a/go/viperutil/internal/value/value.go +++ b/go/viperutil/internal/value/value.go @@ -17,7 +17,6 @@ limitations under the License. package value import ( - "errors" "fmt" "github.com/spf13/pflag" @@ -25,6 +24,8 @@ import ( "vitess.io/vitess/go/viperutil/internal/registry" "vitess.io/vitess/go/viperutil/internal/sync" + "vitess.io/vitess/go/vt/proto/vtrpc" + "vitess.io/vitess/go/vt/vterrors" ) // Registerable is the subset of the interface exposed by Values (which is @@ -59,7 +60,7 @@ func (val *Base[T]) Get() T { return val.BoundGetFunc(val.Key()) } // ErrNoFlagDefined is returned when a Value has a FlagName set, but the given // FlagSet does not define a flag with that name. -var ErrNoFlagDefined = errors.New("flag not defined") +var ErrNoFlagDefined = vterrors.New(vtrpc.Code_INVALID_ARGUMENT, "flag not defined") // Flag is part of the Registerable interface. If the given flag set has a flag // with the name of this value's configured flag, that flag is returned, along @@ -75,7 +76,7 @@ func (val *Base[T]) Flag(fs *pflag.FlagSet) (*pflag.Flag, error) { flag := fs.Lookup(val.FlagName) if flag == nil { - return nil, fmt.Errorf("%w with name %s (for key %s)", ErrNoFlagDefined, val.FlagName, val.Key()) + return nil, vterrors.Wrapf(ErrNoFlagDefined, "%s with name %s (for key %s)", ErrNoFlagDefined.Error(), val.FlagName, val.Key()) } return flag, nil