Repository navigation
refactor: single package, no secrets in errors, focused examples - #229
Merged
Merged
Conversation
Parse wrapped the parser error first and ErrInvalidValue last, so the message read backwards: strconv.ParseInt: parsing "x": invalid syntax: invalid value Swap the operands so the message goes from the general error to its cause, as Go error chains usually do: invalid value: strconv.ParseInt: parsing "x": invalid syntax Only the text changes: errors.Is still matches both ErrInvalidValue and the cause. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The EnvParser interface was removed with the parser hierarchy in #223, but the Option comment still called it "a contract for EnvParser parameters options". Describe what an option does instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
url.Parse returns a *url.Error that quotes the whole input, so an invalid DSN such as postgres://user:password@host put the password into the error and from there into logs. Return the underlying cause instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The option package could not import getenv, so the parameters it sets had to live in a third package, internal. That leaked into the public API: Option.Apply took an *internal.Parameters that callers cannot name, and Parsable was an alias of internal.EnvParsable, so godoc did not list the supported types and the package doc had to repeat them by hand. Everything now lives in package getenv: - Option, WithSeparator and WithTimeLayout. Option is sealed with an unexported method instead of by an unimportable parameter type. - Parsable spells out its types, so godoc shows them and the package doc points there instead of repeating them. Package option stays as a deprecated forwarder: option.Option is an alias of getenv.Option, so existing calls keep compiling. Option.Apply is gone; it could not be called outside the module, as internal.Parameters cannot be constructed there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Elements are not trimmed and a trailing separator adds an empty element. Both are easy to trip over, so say it in the package doc and pin it with tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Errors read `environment variable "KEY": not set` instead of `failed to get environment variable[KEY]: not set`: %q is the usual way to quote a name, and "failed to" only adds length to a wrapped chain. - Use the literal base 10 for strconv: a named constant for it is noise. - Replace the two examples that printed every type through an any with one short example per use case, so godoc shows the typed results and how to tell ErrNotSet from ErrInvalidValue. - Regenerate the README examples. The old url.URL example printed the struct fields, not the URL its output claimed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #229 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 4 +1
Lines 99 103 +4
=========================================
+ Hits 99 103 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
url.Parse wraps every error in *url.Error, so the fallback return never ran and was the only statement left without coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Follow-up to a review of the library. Four commits, each one stands on its own:
url.Parsereturns a*url.Errorthat quotes the whole input, so an invalidDATABASE_URL=postgres://user:password@…put the password into the error, andlog.Fatal(err)put it into the logs. The underlying cause is returned instead. A test checks that the password is not inerr.Error().internalandoptioninto the root package.optioncould not importgetenv, soParametershad to live ininternal, which leaked into the public API:Option.Apply(*internal.Parameters)andParsable = internal.EnvParsable, whose types godoc did not show. Now:getenv.Option,getenv.WithSeparatorandgetenv.WithTimeLayout;Optionis sealed with an unexported method;Parsablelists its types itself, so the hand-written list in the package doc is gone;optionis a deprecated forwarder:option.Option = getenv.Option, so existing calls keep compiling."1, 2"is not a valid[]int), and a trailing separator adds an empty element. Both are documented and pinned with tests.environment variable "PORT": invalid value: ….decimalBaseis replaced with the literal10.any.url.URLexample printed struct fields, not the URL shown in its output.Github Issue
—
Possible failures/side-effects
option.Option.Apply. It could not be called outside the module, sinceinternal.Parameterscannot be constructed there. Callers that useoption.WithSeparatororoption.WithTimeLayoutwithEnvorEnvOrDefaultkeep compiling;option/option_test.gochecks this.getenv.Parsableis now its own interface, not an alias. Its type set is the same, so generic code likefunc f[T getenv.Parsable]()is unaffected.errors.Iswill break. The sentinels anderrors.Is(err, strconv.ErrSyntax)work as before.go vetandgo test -race ./...;golangci-lintwith both.golangci.ymland.golangci.pipe.yml: 0 issues;Other notes
The base is
fix/error-message-order(#228), because this PR changes the same error messages andoptiondocs. Merge #228 first; GitHub will then retarget this PR tomaster.The next release should list the behavior changes since v1.9.1 in its notes: the default separator and time layout, the error text, and the deprecated
optionpackage.🤖 Generated with Claude Code