Skip to content

Report any exception from model code instead of crashing the generator [patch] - #65

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/41-report-any-model-exception
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/41-report-any-model-exception

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

MetadataFile.Deserialize<T> caught JsonException, NotSupportedException, InvalidOperationException and ArgumentException. System.Text.Json passes the model's own constructor exceptions through unwrapped, so a model that did name.Trim() or int.Parse(size) threw NullReferenceException, FormatException or OverflowException. Those reached the driver as CS8785, and the output of every other metadata file in the run was lost with it.

Deserialize<T> now reports every exception as MetadataParseFailed, using <ExceptionType>: <message> as the reason. Two exceptions still propagate: OperationCanceledException, which the driver uses to stop a run, and OutOfMemoryException. JsonException keeps its own handler, which locates the failure. The XML remarks and the matching CLAUDE.md design note are updated.

Tests:

  • I added AnyExceptionFromModelCodeIsReportedRatherThanCrashingTheGenerator, with one DataRow each for NullReferenceException, FormatException and OverflowException. It drives a two-file fixture, ParsedPairGenerator, and asserts four things: result.Exception is null, there is exactly one MetadataParseFailed naming things.json and the exception type, and others.json still generates.
  • All three rows fail on main and pass with the change.
  • The full suite passes: 69 of 69.

Fixes #41


Generated by Claude Code

…r [patch]

Deserialize<T> caught only JsonException, NotSupportedException,
InvalidOperationException and ArgumentException, so a model constructor
that threw NullReferenceException, FormatException or OverflowException
escaped to the driver as CS8785 and lost every other file's output. It now
reports every exception except OperationCanceledException and
OutOfMemoryException, with the exception's type name in the reason.

Fixes #41

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

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 6fd5b2f into main Nov 4, 2026
15 checks passed
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.

A model constructor throwing NullReference/Format/OverflowException still crashes the generator with CS8785 and drops every file's output

2 participants