fix: propagate validator errors from empty bool sources - #2452
sergioperezcheco wants to merge 2 commits into
Conversation
Co-Authored-By: OpenAI GPT-6.1-Sol <noreply@openai.com> Signed-off-by: sergioperezcheco <checo520@outlook.com>
|
|
Please forgive the WIP review bot 🙏🏼 |
coilysiren
left a comment
There was a problem hiding this comment.
Can you write a version of these tests that had a block of input variants at the top? As opposed to composing said variants while you walk down the for loop chain
Co-Authored-By: OpenAI GPT-6.1-Sol <noreply@openai.com> Signed-off-by: sergioperezcheco <checo520@outlook.com>
|
Updated the regression to a single table of 12 input variants at the top, with explicit expected errors, instead of constructing cases in nested loops. The environment/file, empty/false/true, and command-line override cases are preserved. Both full race-test configurations, vet, and lint pass locally. |
What type of PR is this?
What this PR does / why we need it:
An empty environment variable or file is already interpreted as
falsefor aBoolFlag, butPostParsediscards the error returned bySetin that branch. A custom validator can reject the value whileCommand.Runstill succeeds and executes the flag and command actions. Explicitfalsefrom the same source correctly returns an error.Normalize the empty bool value to
falsebefore the existing error-handling path. This preserves empty-source and fallback semantics while making validator failures consistent. The publicCommand.Runregression covers environment and file sources, explicit values, command-line overrides, and action execution.Which issue(s) this PR fixes:
No existing issue found. This is distinct from #2451, which skips empty sources for non-string/non-bool flags; it does not change the existing empty-bool-to-false behavior.
Testing
On Go 1.26.4 / macOS arm64, the new regression fails on the original production source for both empty-source cases and passes with the fix.
go test -race -count=1 ./..., itsurfave_cli_no_templatevariant,make testwith both tag configurations,make vet, golangci-lint 2.13.1, formatting,make generate,make v3diff, andmake check-binary-sizepassed. Generated API documentation is unchanged. Other OS/Go versions and documentation examples were not run locally.Implemented and tested with Hermes Agent using GPT-6.1-Sol.
Release Notes