refactor: structured diagnostics; one validation path; no console output - #82
Merged
Merged
Conversation
Two validation paths reported differently, library warnings went straight
to console.warn (invisible in the browser app), and ~40 plain Errors carried
no machine-readable code.
- src/diagnostics.ts: Diagnostic { code, severity, message, name? } with a
closed DiagnosticCode union; ConversionError (code, subject, details,
cause); WarningHandler and consoleWarning, the one place the library
writes to the console. SubsetViolation is now Diagnostic, so
validateSubset findings carry a code too.
- One row check: XLSValidator.rowDiagnostic() (type, choice lists) and
appearanceDiagnostics() are what validateSubset collects and what the
converter throws or warns with. The converter's own copies
(validateRowType, assertChoiceList, assertFileChoices, UNIMPLEMENTED_TYPES,
the appearance check) are gone, so its messages are the validator's.
- Warnings go to onWarning: LstsvConfig.onWarning, XLSLoader's
LoadOptions.onWarning, the FieldSanitizer/TypeMapper constructors and
convertConstraint. They default to consoleWarning. A dropped constraint is
now a `constraint-dropped` warning instead of console.error. The "Removed
other choice" console.log is gone.
- Every error the library throws is a ConversionError with a code;
XPathSyntaxError subclasses it (code xpath-syntax).
Public API is additive; the message text of converter errors changed (tests
now assert codes). No console.* remains outside diagnostics.ts and the CLI,
which a test enforces. TSV output unchanged.
Closes #63
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Closes #63.
What changes
src/diagnostics.tsDiagnostic{ code, severity, message, name? }, with a closedDiagnosticCodeunion (~40 codes)ConversionErrorcode,subject(the question),details(all findings when it summarises several),causeWarningHandler,consoleWarningSubsetViolationis nowDiagnostic, sovalidateSubsetfindings also carry codes. This is additive.One validation path.
XLSValidator.rowDiagnostic()(types, choice lists) andappearanceDiagnostics()are whatvalidateSubsetcollects, and what the converter throws or warns with. The converter's duplicates are deleted:validateRowType,assertChoiceList,assertFileChoices,UNIMPLEMENTED_TYPES, and its own appearance check. The converter doesn't run the fullvalidateSubset, because that would add the LimeSurvey name gate toskipValidationconversions, which sanitize instead.Warnings →
onWarning:LstsvConfig.onWarningXLSLoaderLoadOptions.onWarningnew FieldSanitizer(onWarning),new TypeMapper(onWarning)convertConstraint(expr, onWarning)All default to
consoleWarning, so current behaviour is kept. Two specific changes:constraint-droppedwarning; before, it was a bareconsole.error.console.logis gone: that's the normal collapse, not a finding.Errors: every
throwreachable from the package root is aConversionErrorwith a code.XPathSyntaxErrorsubclasses it (xpath-syntax).Compatibility
codenow. Consumers that match messages should switch to codes.Tests
tests/ts/unit/diagnostics.test.ts:onWarning, and not the consolesubjectnames the questionconsole.*outsidediagnostics.tsand the CLIResults: vitest 898 passed.
npm run validateis clean. pytest: 37 passed.README gets an "Errors and warnings" section.
🤖 Generated with Claude Code