Skip to content

Commit

Permalink
!refactor: Improve naming consistency
Browse files Browse the repository at this point in the history
Rename ErrValidateTagViolation to ErrValidationTag.
  • Loading branch information
romshark committed Jul 3, 2024
1 parent 98ba4ab commit 1bdcd57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions yamagiconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
// Errors in the Go target type begin with ErrType...
// Errors in the env variables begin with ErrEnv...
var (
ErrConfigNil = errors.New("cannot load into nil config")
ErrValidation = errors.New("validation")
ErrValidateTagViolation = errors.New("violates validation rule")
ErrConfigNil = errors.New("cannot load into nil config")
ErrValidation = errors.New("validation")
ErrValidationTag = errors.New("violates validation rule")

ErrYAMLMultidoc = errors.New("multi-document YAML files are not supported")
ErrYAMLEmptyFile = errors.New("empty file")
Expand Down Expand Up @@ -190,10 +190,10 @@ func Load[T any, S string | []byte](yamlSource S, config *T) error {

// Ignored field, use Go field name instead of tag.
return fmt.Errorf("at %s: %w: %q",
err.StructNamespace(), ErrValidateTagViolation, err.Tag())
err.StructNamespace(), ErrValidationTag, err.Tag())
}
return fmt.Errorf("at %d:%d: %q %w: %q",
line, column, yamlTag, ErrValidateTagViolation, err.Tag())
line, column, yamlTag, ErrValidationTag, err.Tag())
}
return err
}
Expand All @@ -214,7 +214,7 @@ func Validate[T any](t T) error {
if err != nil {
if errs, ok := err.(validator.ValidationErrors); ok {
return fmt.Errorf("at %s: %w: %q",
errs[0].StructNamespace(), ErrValidateTagViolation, errs[0].Tag())
errs[0].StructNamespace(), ErrValidationTag, errs[0].Tag())
}
return err
}
Expand Down
4 changes: 2 additions & 2 deletions yamagiconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ container:
array-map-val-val:
- null
`)
require.ErrorIs(t, err, yamagiconf.ErrValidateTagViolation)
require.ErrorIs(t, err, yamagiconf.ErrValidationTag)
require.Equal(t,
`at 3:17: "required-str" violates validation rule: "required"`,
err.Error())
Expand Down Expand Up @@ -1800,7 +1800,7 @@ container:
array-map-val-val:
- null
`)
require.ErrorIs(t, err, yamagiconf.ErrValidateTagViolation)
require.ErrorIs(t, err, yamagiconf.ErrValidationTag)
require.Equal(t,
`at TestConfig.Container.NoYAMLStr: violates validation rule: "required"`,
err.Error())
Expand Down

0 comments on commit 1bdcd57

Please sign in to comment.