feat(core): Introduce ErrNoValue for nuanced validation #41
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.