feat(core): Introduce ErrNoValue for nuanced validation#41
Merged
FranciscoKurpiel merged 1 commit intomasterfrom Sep 20, 2025
Merged
feat(core): Introduce ErrNoValue for nuanced validation#41FranciscoKurpiel merged 1 commit intomasterfrom
FranciscoKurpiel merged 1 commit intomasterfrom
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
7e75fc5 to
6bb8c4d
Compare
This commit introduces a new mechanism to allow xtypes to signal that a
provided value (such as an empty string) should be treated as if no value
was provided at all. This solves a design limitation where the validation
logic could not distinguish between a valid empty value and a "not provided"
marker for certain types.
Problem:
Previously, an xtype like `xtypes.RSAPrivateKey` would fail validation
when an optional parameter was backed by an environment variable set to an
empty string.
- The validation function (`ValueValid`) is context-agnostic and does not
know if a parameter is optional.
- If `ValueValid` returned an error for an empty string, it would
incorrectly fail optional parameters.
- If `ValueValid` did *not* return an error, it would incorrectly allow a
required parameter to be considered valid while producing a `nil` value,
without `MustParse` returning an error.
Solution:
This commit implements a sentinel error-based solution:
1. **`types.ErrNoValue`**: A new exported error, `ErrNoValue`, has been
added to the `types` package.
2. **xtype Adoption**: xtypes that need this behavior (like `RSAPrivateKey`)
can now return `types.ErrNoValue` from their `ValueValid` function when
they encounter a value (like an empty string) that should be treated as
"not provided".
3. **Core Logic Update**: The central validation function `validValue` in
`parsed.go` has been updated to recognize `ErrNoValue`. When it
receives this error, it now correctly applies the `optional`/`required`
logic as if the parameter had not been supplied at all.
Consequences:
- **For Users:** This change fixes the bug where optional `RSAPrivateKey`
parameters would fail with empty environment variables. The behavior is
now consistent and correct. The default value of an optional parameter is
now correctly used when an empty string is provided.
- **For xtype Developers:** Developers of new xtypes now have a clear,
idiomatic pattern to handle cases where certain string representations
should be considered "empty" or "not provided". They can return
`types.ErrNoValue` from `ValueValid` to trigger this behavior.
- **Testing:** A comprehensive test case (`TestRSAPrivateKey`) has been
added to `parser_test.go` to verify this new behavior and prevent future
regressions.
This change makes the validation system more robust and flexible while
maintaining safety and correctness.
6bb8c4d to
8a1b1e7
Compare
Collaborator
Author
|
/gemini review |
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.
This commit introduces a new mechanism to allow xtypes to signal that a provided value (such as an empty string) should be treated as if no value was provided at all. This solves a design limitation where the validation logic could not distinguish between a valid empty value and a "not provided" marker for certain types.
Problem:
Previously, an xtype like
xtypes.RSAPrivateKeywould fail validation when an optional parameter was backed by an environment variable set to an empty string.ValueValid) is context-agnostic and does not know if a parameter is optional.ValueValidreturned an error for an empty string, it would incorrectly fail optional parameters.ValueValiddid not return an error, it would incorrectly allow a required parameter to be considered valid while producing anilvalue, withoutMustParsereturning an error.Solution:
This commit implements a sentinel error-based solution:
types.ErrNoValue: A new exported error,ErrNoValue, has been added to thetypespackage.xtype Adoption: xtypes that need this behavior (like
RSAPrivateKey) can now returntypes.ErrNoValuefrom theirValueValidfunction when they encounter a value (like an empty string) that should be treated as "not provided".Core Logic Update: The central validation function
validValueinparsed.gohas been updated to recognizeErrNoValue. When it receives this error, it now correctly applies theoptional/requiredlogic as if the parameter had not been supplied at all.Consequences:
RSAPrivateKeyparameters would fail with empty environment variables. The behavior is now consistent and correct. The default value of an optional parameter is now correctly used when an empty string is provided.types.ErrNoValuefromValueValidto trigger this behavior.TestRSAPrivateKey) has been added toparser_test.goto verify this new behavior and prevent future regressions.This change makes the validation system more robust and flexible while maintaining safety and correctness.