Conversation
Implements opt-in strict mode for missing field handling. When ExceptionIfMissing=true, accessing a non-optional field that is absent in the data raises an exception instead of silently returning a default value (empty string for string, NaN for float). The default behavior (ExceptionIfMissing=false) is unchanged for backward compatibility. - Added GetNonOptionalValueStrict<'T> to JsonRuntime and TextRuntime - Added ExceptionIfMissing static parameter to JsonProvider and XmlProvider - Updated code generation pipeline (JsonConversionsGenerator, ConversionsGenerator) - CsvProvider and HtmlProvider always use non-strict mode (false) - Updated TypeProviderInstantiation.fs test helper - Added tests for ExceptionIfMissing behavior Also fixes a pre-existing XmlProvider bug where args.[14] was used for both UseSchemaTypeNames and PreferDateTimeOffset (should be args.[14] and args.[15]). Closes #1241 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dsyme
approved these changes
Feb 28, 2026
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 is an automated response from Repo Assist, an AI assistant.
Closes #1241
Summary
This PR implements opt-in strict mode for missing field handling in
JsonProviderandXmlProvider.Problem: When a field is missing from JSON/XML data, the type provider silently returns a default value (
""forstring,NaNforfloat, etc.), which can hide data quality issues.Solution: A new
ExceptionIfMissingstatic parameter (defaultfalse) that, whentrue, raises an exception when a non-optional field is absent from the data.Usage
Same works for
XmlProvider:Changes
JsonRuntime.fsandTextRuntime.fs: AddedGetNonOptionalValueStrict<'T>— likeGetNonOptionalValuebut without thestring/floatspecial cases that return""/NaN.JsonConversionsGenerator.fs: AddedexceptionIfMissingparameter; selectsGetNonOptionalValueStrictvsGetNonOptionalValueat code generation time.ConversionsGenerator.fs: AddedexceptionIfMissingparameter for XML/CSV/HTML string conversions.JsonGenerator.fs,XmlGenerator.fs: AddedExceptionIfMissing: boolto context records; propagated to code generation.JsonProvider.fs,XmlProvider.fs: AddedExceptionIfMissingstatic parameter (defaultfalse).CsvGenerator.fs,HtmlGenerator.fs: Always passfalse— these providers don't expose the parameter.TypeProviderInstantiation.fs: Updated test helper to include new parameter.tests/FSharp.Data.Tests/JsonProvider.fsandXmlProvider.fs.Bug Fix (incidental)
Fixes a pre-existing bug in
XmlProvider.fswhereargs.[14]was used for bothUseSchemaTypeNamesandPreferDateTimeOffset(correct:args.[14]=UseSchemaTypeNames,args.[15]=PreferDateTimeOffset,args.[16]=ExceptionIfMissing).Test Status
✅
tests/FSharp.Data.Tests— 283 tests, all passed (includes 7 new ExceptionIfMissing tests)tests/FSharp.Data.DesignTime.Tests— 218 signature tests failing with pre-existing infrastructure error (CsvFile\1[RowType] not found in target reference assembly set). This is unrelated to these changes and present onmain` as well.