Skip to content

fix: put "invalid value" before the cause in parse errors - #228

Merged
obalunenko merged 2 commits into
masterfrom
fix/error-message-order
Nov 15, 2026
Merged

obalunenko merged 2 commits into
masterfrom
fix/error-message-order

Conversation

@obalunenko

Copy link
Copy Markdown
Owner

Description

Two small fixes found in a review of the repository.

Error message order. Parse wrapped the parser error first and ErrInvalidValue last, so the message read backwards:

failed to parse environment variable[KEY]: strconv.ParseInt: parsing "x": invalid syntax: invalid value

The operands are swapped, so the message goes from the general error to its cause:

failed to parse environment variable[KEY]: invalid value: strconv.ParseInt: parsing "x": invalid syntax

Stale doc comment. option.Option was described as "a contract for EnvParser parameters options", but the EnvParser interface went away with the parser hierarchy in #223. The comment now says what an option does.

Github Issue

None.

Possible failures/side-effects

  • Only the error text changes. errors.Is still matches both ErrInvalidValue and the cause (TestEnvErrorSentinels, the fuzz test of the error contract).
  • Code that compares error strings will see the new text. Go does not treat error strings as API, so this is a fix, not a breaking change.
  • ExampleEnv and its copy in README.md show the new message.

Testing

  • go test -race ./... passes.
  • FuzzParse ran for 10s without failures.
  • make lint-full: vet, fmt, goimports and golangci-lint report 0 issues.

🤖 Generated with Claude Code

obalunenko and others added 2 commits November 16, 2026 00:26
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>
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8a2e8ae) to head (9744de6).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #228   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           99        99           
=========================================
  Hits            99        99           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@obalunenko
obalunenko merged commit 0898a6e into master Nov 15, 2026
11 checks passed
@obalunenko
obalunenko deleted the fix/error-message-order branch November 15, 2026 20:55
obalunenko added a commit that referenced this pull request Nov 15, 2026
master has #228 squashed; its tree equals 9744de6, which this branch
already contains, so the branch tree stays as it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant