Skip to content

[Feature] Populate Resource.Errors with diagnostics during parse (#35)#70

Merged
samatstariongroup merged 1 commit into
developmentfrom
GH35
Jun 2, 2026
Merged

[Feature] Populate Resource.Errors with diagnostics during parse (#35)#70
samatstariongroup merged 1 commit into
developmentfrom
GH35

Conversation

@samatstariongroup
Copy link
Copy Markdown
Member

@

Summary

Closes #35.

Resource exposed Errors/Warnings (IEnumerable<Diagnostic>), but nothing ever wrote to them — parse problems were invisible to callers or silently aborted the load with a bare exception. This change populates Resource.Errors with a structured Diagnostic (carrying a source location) whenever the parser hits fatal input, before aborting.

Per the design decision on the issue, malformed/unrecognized input remains fatal and aborts the load — this does not recover with defaults. The benefit is that a caller catching the exception can now inspect Resource.Errors for a structured, located diagnostic.

Changes

  • Resource.cs — add internal AddError(message) that appends a Diagnostic (location = resource URI) to the existing backing list.
  • EObject.cs — add protected ParseBoolean/ParseInt32 helpers that, on malformed input, record an error Diagnostic and throw FormatException.
  • Route the ~19 bool.Parse/int.Parse call sites through these helpers (EClass, EDataType, EEnumLiteral, ETypedElement, EStructuralFeature, EAttribute, EReference).
  • Record an error at the unknown-xsi:type throw sites in EPackage (classifier) and EClass (structural feature) before throwing InvalidOperationException.

Tests

New DiagnosticsTestFixture asserts that, for each failure case, Load throws and Resource.Errors contains the matching diagnostic: malformed boolean, malformed integer, unknown classifier type, unknown structural-feature type, plus a Diagnostic.Location check.

Verification

  • dotnet build EcoreNetto.sln — 0 warnings.
  • dotnet test EcoreNetto.sln — green (182 tests).

🤖 Generated with Claude Code
@

#35

Parse problems were invisible to callers: Resource.Errors/Warnings were
exposed but never written to. Fatal input now records a structured
Diagnostic in Resource.Errors before aborting the load.

- Add internal Resource.AddError(message) sink (Location = resource URI).
- Add protected EObject.ParseBoolean/ParseInt32 helpers that record an
  error Diagnostic and then throw FormatException on malformed scalars.
- Route the ~19 bool.Parse/int.Parse sites (abstract, interface, ordered,
  unique, lowerBound, upperBound, enum-literal value, etc.) through them.
- Record an error at the unknown xsi:type throw sites in EPackage
  (classifier) and EClass (structural feature) before throwing.

Malformed/unrecognized input stays fatal and aborts the load; callers
that catch the exception can now inspect structured diagnostics with a
source location. Adds DiagnosticsTestFixture covering each failure case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Package Line Rate Branch Rate Complexity Health
ECoreNetto 86% 78% 415
ECoreNetto.Extensions 99% 93% 101
ECoreNetto.HandleBars 99% 98% 60
ECoreNetto.Reporting 83% 71% 181
ECoreNetto.Tools 94% 87% 59
Summary 89% (2158 / 2430) 81% (494 / 610) 816

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 2, 2026

@samatstariongroup samatstariongroup merged commit 10f2f8c into development Jun 2, 2026
13 checks passed
@samatstariongroup samatstariongroup deleted the GH35 branch June 5, 2026 06:13
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.

[Feature]: Populate Resource.Errors/Warnings during parse

1 participant