diff --git a/.golangci.yml b/.golangci.yml index 71a9368..a2b7688 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,7 @@ linters: excludes: - G302 - G304 + - G703 revive: enable-default-rules: true exclusions: diff --git a/config.go b/config.go index 0edabeb..333bd16 100644 --- a/config.go +++ b/config.go @@ -19,7 +19,7 @@ var ( // ErrInterfaceConversion indicates that supplied T is different from cached type. ErrInterfaceConversion = errors.New("interface conversion") // ErrYAMLMarshal indicates error marshalling supplied data to YAML. - ErrYAMLMarshal = errors.New("unable to marshal data to yaml") + ErrYAMLMarshal = errors.New("unable to (un)marshal data to/from yaml") ) // Get returns the configuration data for the supplied configuration struct type T, caching it after first retrieval. @@ -111,7 +111,7 @@ func fromFile[T any](fileName string) (T, error) { return data, fmt.Errorf("read config file %w", err) } if err := yaml.Unmarshal(bytes, &data); err != nil { - return data, fmt.Errorf("unmarshal %w", err) + return data, fmt.Errorf("%w %w", ErrYAMLMarshal, err) } return data, nil } diff --git a/config_test.go b/config_test.go index 7362a82..0bd6f90 100644 --- a/config_test.go +++ b/config_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/Kairum-Labs/should" - "go.yaml.in/yaml/v4" ) // test struct. @@ -78,8 +77,7 @@ func TestRead(t *testing.T) { reset(t) // force read from file. should.NotBeError(t, os.WriteFile(filepath.Join(dir, progName, "config"), []byte("not: [valid"), permission)) config := testConfig{} - expected := &yaml.ParserError{} - should.BeErrorAs(t, Get(&config), &expected) + should.BeErrorIs(t, Get(&config), ErrYAMLMarshal) }) t.Run("filepermission", func(t *testing.T) { diff --git a/go.mod b/go.mod index c52954e..7cd28b0 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.22 require ( github.com/Kairum-Labs/should v0.2.2 - go.yaml.in/yaml/v4 v4.0.0-rc.3 + go.yaml.in/yaml/v4 v4.0.0-rc.4 ) diff --git a/go.sum b/go.sum index 833fbdb..9f99a1b 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ github.com/Kairum-Labs/should v0.2.2 h1:bO1kaMGRYRSSpq8MHsmk2MqpA1taLPblPCZy9Jnpt+U= github.com/Kairum-Labs/should v0.2.2/go.mod h1:vP/ASEjUAKoWy/M7uIrAXq69p7/IUWOpEe5R+q/+K34= -go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go= -go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= +go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U= +go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=