Skip to content

Commit

Permalink
Rename config#InvalidArgumentError to ErrInvalidArgument
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed May 2, 2024
1 parent ea8365b commit ab032db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func New() (*Command, error) {

var cfg icingadbconfig.Config
if err := config.FromYAMLFile(flags.Config, &cfg); err != nil {
if errors.Is(err, config.InvalidArgumentError) {
if errors.Is(err, config.ErrInvalidArgument) {
return nil, err
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (
"reflect"
)

// InvalidArgumentError is the error returned by [ParseFlags] or [FromYAMLFile] if
// ErrInvalidArgument is the error returned by [ParseFlags] or [FromYAMLFile] if
// its parsing result cannot be stored in the value pointed to by the designated passed argument which
// must be a non-nil pointer.
var InvalidArgumentError = stderrors.New("invalid argument")
var ErrInvalidArgument = stderrors.New("invalid argument")

// FromYAMLFile parses the given YAML file and stores the result
// in the value pointed to by v. If v is nil or not a pointer,
// FromYAMLFile returns an [InvalidArgumentError].
// FromYAMLFile returns an [ErrInvalidArgument].
func FromYAMLFile(name string, v Validator) error {
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Pointer || rv.IsNil() {
return errors.Wrapf(InvalidArgumentError, "non-nil pointer expected, got %T", v)
return errors.Wrapf(ErrInvalidArgument, "non-nil pointer expected, got %T", v)
}

f, err := os.Open(name)
Expand Down Expand Up @@ -50,11 +50,11 @@ func FromYAMLFile(name string, v Validator) error {

// ParseFlags parses CLI flags and stores the result
// in the value pointed to by v. If v is nil or not a pointer,
// ParseFlags returns an [InvalidArgumentError].
// ParseFlags returns an [ErrInvalidArgument].
func ParseFlags(v any) error {
rv := reflect.ValueOf(v)
if rv.Kind() != reflect.Pointer || rv.IsNil() {
return errors.Wrapf(InvalidArgumentError, "non-nil pointer expected, got %T", v)
return errors.Wrapf(ErrInvalidArgument, "non-nil pointer expected, got %T", v)
}

parser := flags.NewParser(v, flags.Default)
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/unix_milli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (t UnixMilli) MarshalJSON() ([]byte, error) {
return []byte("null"), nil
}

return []byte(strconv.FormatInt(time.Time(t).UnixMilli(), 10)), nil
return []byte(strconv.FormatInt(t.Time().UnixMilli(), 10)), nil
}

// UnmarshalJSON implements the json.Unmarshaler interface.
Expand All @@ -45,7 +45,7 @@ func (t UnixMilli) MarshalText() ([]byte, error) {
return []byte{}, nil
}

return []byte(strconv.FormatInt(time.Time(t).UnixMilli(), 10)), nil
return []byte(strconv.FormatInt(t.Time().UnixMilli(), 10)), nil
}

// UnmarshalText implements the encoding.TextUnmarshaler interface.
Expand Down

0 comments on commit ab032db

Please sign in to comment.