diff --git a/README.md b/README.md index 7597a7a6..d2abd34b 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ Output: ``` [string]: golly; err: [int]: 123; err: -[int]: 0; err: failed to parse environment variable[GH_GETENV_TEST]: strconv.ParseInt: parsing "123s4": invalid syntax: invalid value +[int]: 0; err: failed to parse environment variable[GH_GETENV_TEST]: invalid value: strconv.ParseInt: parsing "123s4": invalid syntax [time.Time]: 2022-01-20 00:00:00 +0000 UTC; err: [[]float64]: [26.89 0.67]; err: [time.Duration]: 2h35m0s; err: diff --git a/getenv_example_test.go b/getenv_example_test.go index 54d0b30a..9d0b1330 100644 --- a/getenv_example_test.go +++ b/getenv_example_test.go @@ -241,7 +241,7 @@ func ExampleEnv() { // Output: // [string]: golly; err: // [int]: 123; err: - // [int]: 0; err: failed to parse environment variable[GH_GETENV_TEST]: strconv.ParseInt: parsing "123s4": invalid syntax: invalid value + // [int]: 0; err: failed to parse environment variable[GH_GETENV_TEST]: invalid value: strconv.ParseInt: parsing "123s4": invalid syntax // [time.Time]: 2022-01-20 00:00:00 +0000 UTC; err: // [[]float64]: [26.89 0.67]; err: // [time.Duration]: 2h35m0s; err: diff --git a/internal/parse.go b/internal/parse.go index eaf5ed0e..703f4f8d 100644 --- a/internal/parse.go +++ b/internal/parse.go @@ -23,7 +23,7 @@ func Parse[T EnvParsable](raw string, p Parameters) (T, error) { if err := parseValue(&res, raw, p); err != nil { var zero T - return zero, fmt.Errorf("%w: %w", err, ErrInvalidValue) + return zero, fmt.Errorf("%w: %w", ErrInvalidValue, err) } return res, nil diff --git a/option/option.go b/option/option.go index eab81ee7..ae8dde07 100644 --- a/option/option.go +++ b/option/option.go @@ -5,7 +5,7 @@ import ( "github.com/obalunenko/getenv/internal" ) -// Option is a contract for EnvParser parameters options. +// Option configures how Env and EnvOrDefault parse the value of a variable. type Option interface { // Apply applies the option to the parameters. Apply(params *internal.Parameters)