Skip to content

feat: report non-fatal import diagnostics - #439

Draft
webern wants to merge 1 commit into
mainfrom
m/mxdev-xmldiag
Draft

webern wants to merge 1 commit into
mainfrom
m/mxdev-xmldiag

Conversation

@webern

@webern webern commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Human Summary

TODO: human writes here

Summary

The generated mx::core parsers are strict about structure but lenient about values: an unknown
enum literal falls back to the first variant, a number is clamped into its schema range, malformed
text becomes a default, and a missing lyric-language/@xml:lang is filled in with und. Until now
all of that happened silently.

MusicXml::fromFile and fromStream gain Diagnostics & overloads, so the collector from #437 can
be handed to the parse and then on to getScore, gathering both layers' reports in one place. The
existing overloads are unchanged and stay silent.

Inside core, a new ParseContext is carried through every generated parser. Core keeps its own
Diagnostic type with an XML path, and mx::api maps it to the public one, so core still does not
depend on mx::api. Value types gain a parse(text, outcome) overload that says whether the text was
unreadable or was adjusted. That is what lets +01 or 1 pass quietly while 12 for an octave
is reported as adjusted to 9. Two new public codes, invalidValue and missingValueDefaulted,
join the existing valueAdjusted. All import reports are warnings.

Serialization is untouched, and parsing produces the same document with or without a collector.

Not yet reported: the bespoke value types (color, yyyy-mm-dd, comma-separated text and font family,
time-only, ending number, the SMuFL glyph names) and the Token/NameToken identity wrappers still
repair silently. They can be added as report sites later using the same parse(text, outcome) shape.

Testing

  • Core import diagnostics tests: 47 assertions in 7 test cases
  • Api diagnostics tests for fromFile, fromStream, a collection reused across fromStream and
    getScore, identical output without a collector, and a throwing handler becoming internalError
  • make test-all
    • corert: 841 test cases
    • core unit: 268 assertions in 51 test cases
    • api: 5607 assertions in 622 test cases
    • api round-trip: 414 passed, 0 failed, no baseline change
  • make wasm-test
  • make gen-test, make gen-quality, make gen-lint
  • make fmt

References

The generated core parsers repair values silently: an unknown enum
literal falls back to the first variant, numbers are clamped into
range, unreadable text becomes a default, and a missing
lyric-language/@xml:lang becomes "und".

Carry a ParseContext through every generated parser and report those
repairs with their XML path. Value types gain a parse overload that
says whether the text was invalid or adjusted, so valid alternate
spellings are not reported. MusicXml::fromFile and fromStream take an
optional Diagnostics that the same collector can then pass to
getScore. Parsing produces the same document either way.
@webern webern added feature new feature request api Affects the mx::api layer core Affects the mx::core layer gen The gen/ directory which is generating code from the spec ai Issues opened by, or through, a coding agent. labels Sep 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

gen-quality gen/

gen-quality: 84.5 / 100   (floor 84.5, +0.0)

  structure     86.5  x0.50   [fn 90.5 / file 82.6]
  cyclomatic    88.4  x0.25
  cognitive     76.6  x0.25

  409 functions across 31 files, 7702 lines (largest file 1044)
  max cc 56  max cognitive 44  max fn loc 152

Worst offenders (top 5 per axis; full lists in score.json):
  cyclomatic gen/xsd/analyze.py:311     report                             56
  cyclomatic gen/plates/build.py:956    _validate_config_against_ir        35
  cyclomatic gen/press/context.py:145   plate_context                      34
  cyclomatic gen/__main__.py:46         _ir                                23
  cyclomatic gen/tests/test_ir.py:102   _check_references                  20
  cognitive  gen/xsd/analyze.py:311     report                             44
  cognitive  gen/ir/resolve.py:119      flat_elements                      40
  cognitive  gen/tests/test_ir.py:102   _check_references                  38
  cognitive  gen/press/context.py:145   plate_context                      37
  cognitive  gen/xsd/analyze.py:207     _sccs                              37
  size       gen/xsd/analyze.py:311     report                             152
  size       gen/press/context.py:145   plate_context                      96
  size       gen/plates/build.py:533    _value_plate                       89
  size       gen/plates/build.py:956    _validate_config_against_ir        89
  size       gen/ir/resolve.py:119      flat_elements                      78

Commit c6cbe39f5ca013a0cb5fd3aafef2c45c3227239e.

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

Labels

ai Issues opened by, or through, a coding agent. api Affects the mx::api layer core Affects the mx::core layer feature new feature request gen The gen/ directory which is generating code from the spec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant