Improve DynamicValue error handling with Validation#1061
Open
AfshaZabeen-5G2 wants to merge 3 commits intozio:mainfrom
Open
Improve DynamicValue error handling with Validation#1061AfshaZabeen-5G2 wants to merge 3 commits intozio:mainfrom
AfshaZabeen-5G2 wants to merge 3 commits intozio:mainfrom
Conversation
- Replace Either (fail-fast) with Validation (error accumulation) - Add new toTypedValueValidation method for full error collection - Maintain backward compatibility for toTypedValue, toValue, toTypedValueOption - Add DecodeError.And.reduce helper for combining errors - Add comprehensive test suite for error accumulation - All existing tests pass without modification
- Replace Either[DecodeError, A] with Validation[DecodeError, A] for error accumulation - Add toTypedValueValidation method for Validation-based decoding - Maintain backward compatibility with existing toTypedValue, toValue, toTypedValueOption methods - Add DecodeError.reduceErrors to combine multiple errors - Add comprehensive test suite for error accumulation - Add .gitattributes for consistent LF line endings
211503c to
eed0ffe
Compare
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.
/claim #480
🎯 Summary
This PR improves the
DynamicValue.toTypedValueoperation by switching from a "fail-fast"Eitherapproach to an "error-accumulating"Validationapproach usingzio-prelude. This allows the library to collect all validation errors in a single pass instead of stopping at the first failure.❓ Problem
The previous implementation used
Either[DecodeError, A], which:✅ Solution
Implemented
Validation[DecodeError, A]fromzio-preludeto enable:EitherandOptionAPIs.🛠 Changes
1. New API Method
def toTypedValueValidation[A](implicit schema: Schema[A]): Validation[DecodeError, A]2. Updated Existing Methods (Backward Compatible)
toTypedValue[A]: Now projectsValidationtoEither, combining multiple errors into a single string.toValue[A]: Now projectsValidationtoEither, combining multiple errors usingDecodeError.And.toTypedValueOption[A]: Internal logic now uses validation, but still returnsNoneon any failure.3. Error Accumulation Points
Errors are now collected across:
Validation.validateWith.Validation.validateAll.decodeStructureValidation.4. Helper Methods
DecodeError.And.reduce: Helper to merge multipleDecodeErrorinstances.decodeStructureValidation: A validation-native version of the record decoding logic.🧪 Testing & Verification
Added a new test suite:
DynamicValueValidationSpec.scala.Either-based APIs still function as expected../sbt "testsJVM/test"and all tests passed (100%).📋 Checklist
toTypedValueValidationmethod added.