Skip to content

Refuse NaN and infinities in the data-record number setters [patch] - #352

Open
matt-edmondson wants to merge 5 commits into
mainfrom
fix/350-refuse-non-finite-numbers
Open

matt-edmondson wants to merge 5 commits into
mainfrom
fix/350-refuse-non-finite-numbers

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #350

What changed

SchemaDataValues.SetFloat, SetDouble and SetComponents (used by SetVector2/3/4 and SetColorRgb/Rgba) stored non-finite values without complaint. JSON has no number for those values, so the record threw on its next ToJsonString. The generated editor's Issues, IsValid, ToJson and Save all go through that call, so they threw too, until the value was overwritten.

Each of these setters now throws an ArgumentOutOfRangeException naming the member before it writes anything. A vector or colour has every component checked before the array is built, so a refused assignment leaves the record as it was.

Tests (GeneratedDataEditorTests)

  • TestANonFiniteValueIsRefusedAndTheEditorKeepsWorking: on a generated record, assigning NaN, +∞ or −∞ to Weight, or a NaN component to Tint, is refused with the member named. Afterwards the record keeps its previous values, Issues matches what it was before, IsValid is true, ToJson returns the loaded text, and Save succeeds.
  • TestNonFiniteNumbersAreRefusedBeforeTheRecordChanges: covers SetDouble, SetFloat, SetVector2/3/4 and SetColorRgba directly, and checks that the record's JSON is unchanged.
  • With the fix reverted, both tests fail. With the fix, they pass.
  • Full run on net10.0: Schema.Test 720/720, Schema.Editor.Test 33/33, Schema.Cpp.Test 130/130.

Note on CI

main doesn't build right now because of #336 (CA1506 on Schema, class coupling 97 against a limit of 96). This PR doesn't touch Schema.cs, so it will show the same failure until #336 is fixed. I ran the suites above with -p:RunAnalyzers=false, then ran the analyzers on the changed test project on its own: they reported nothing. The only analyzer error in the library is the existing CA1506.


Generated by Claude Code

SetFloat, SetDouble and the vector and colour setters stored any value, and
JSON has no number for NaN or an infinity. The record then threw on the next
ToJsonString, so the generated editor's Issues, IsValid, ToJson and Save all
threw until the value was overwritten. The setters now throw an
ArgumentOutOfRangeException naming the member before anything is written.

Fixes #350

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW67k6oxx5vQPHu3V4Q
…ix CA1506 [patch]

#332 tipped Schema's class coupling to 97 against a limit of 96, and CA1506 is
an error here, so main stopped building on every target framework. Move the
data-source file-existence check and the reserved-generator-name check into an
internal SchemaEnvironmentValidator. They are the two checks that consult
something outside the schema, and with them gone Schema no longer reaches
File, the IO exceptions, SchemaGenerator or ISchemaCodeGenerator. Behaviour
is unchanged.

Fixes #336

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW67k6oxx5vQPHu3V4Q

Copy link
Copy Markdown
Contributor Author

The ci / .NET / Test failures on a2e65b7 (ubuntu and macOS) were not caused by this PR. The build stops at CA1506: 'Schema' is coupled with '97' different types in Schema/Models/Schema.cs, which is the same error that breaks main (#336). This PR doesn't touch that file.

I merged the fix from #353 into this branch (30fab8d) so CI can build. With it, the solution builds with analyzers on (0 errors, 0 warnings) and Schema.Test passes 720/720 locally. Once #353 merges first, that commit drops out of this PR's diff.


Generated by Claude Code

File.Exists returns false instead of throwing for a path it can't read,
so the IOException/UnauthorizedAccessException branch never ran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW67k6oxx5vQPHu3V4Q
@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting NaN or Infinity on a generated data record makes the editor's Issues, IsValid, ToJson and Save throw until the value is overwritten

2 participants