feat: typed, descriptive errors for mapping misuse and cardinality violations#89
Draft
jeswr wants to merge 1 commit into
Draft
feat: typed, descriptive errors for mapping misuse and cardinality violations#89jeswr wants to merge 1 commit into
jeswr wants to merge 1 commit into
Conversation
…olations Adds two error classes rooted at WrapperError and exports them from mod.ts: - MappingArgumentError: thrown when a mapping function is invoked with an undefined termAs/termFrom mapper, carrying the offending argument name. Replaces the bare 'throw new Error // TODO: Describe' in RequiredFrom, OptionalFrom, OptionalAs, SetFrom and Mapping. - CardinalityError: thrown by RequiredFrom when a singular mapping finds no value or more than one value, carrying the subject term, the predicate IRI and a 'none' | 'multiple' discriminator. Replaces the two untyped string Errors in RequiredFrom (messages unchanged) and resolves its 'TODO: Expose standard errors'. Documents the new errors with @throws tags on the throwing mapping functions and upgrades the existing assert.throws tests to assert the specific error classes and properties. Co-Authored-By: Claude Fable 5 <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.
What this does
Adds typed, descriptive errors for mapping misuse and cardinality violations, replacing the bare
throw new Error // TODO: Describestatements and the two untyped stringErrors inRequiredFrom(resolving its// TODO: Expose standard errors). Consumers can now catch and discriminate these failures programmatically instead of matching on message strings.Two new error classes, exported from
mod.ts:MappingArgumentError(extendsWrapperError) — thrown when a mapping function is invoked with anundefinedtermAs/termFrommapper (e.g. a misspeltLiteralAsmember in plain JavaScript). Carries the offending parameter name inargument. Now thrown byRequiredFrom.subjectPredicate,OptionalFrom.subjectPredicate,OptionalAs.object,SetFrom.subjectPredicateandMapping.languageDictionary.CardinalityError(extendsTermError, so rooted atWrapperError) — thrown byRequiredFrom.subjectPredicatewhen a singular mapping finds no value or more than one value. Carries the subject viaTermError.term, thepredicateIRI, and afound: "none" | "multiple"discriminator. The existing message texts are preserved verbatim, so this is not a breaking change for anyone matching on messages.Both classes carry the repo-style dense JSDoc (summary,
@remarks, titled@exampleblocks pairing Turtle with a mapping class,@see), and the five throwing mapping functions gained@param/@returns/@throwsdocumentation.npx typedocpasses with no new warnings.Tests
assert.throws(() => ...)assertions intest/unit/term_wrapper.test.tsto assert the specificCardinalityErrorclass and itsfound/predicate/termproperties (removing its// TODO: Test for specific errorsand// TODO: check for typed error singular no valuecomments).test/unit/mapping_errors.test.tscoveringMappingArgumentError(including theargumentname) from all five entry points. Both new files are at 100% line/branch coverage; full suite passes (129 tests, 0 fail).Issues
Relation to #61 / #73 / #74
Supersedes no part of them: all three leave these
TODO-marked bare throws untouched (#61 keeps thethrow new Error // TODO: Describelines as-is in its rewrite of the same functions). Merge-order conflicts with #61 in these five files would be textual and small.