Repository navigation
fix(markdown-toolkit): state the rule in errors for wrong input, and throw TypeError - #199
Merged
Merged
Conversation
…rror Seven checks reject a value that breaks a condition, such as a heading depth outside 1 to 6. Each had its own `if` and `throw`, and which error class it threw depended only on when it was written: four threw `Error`, three threw `TypeError`. They now call one assert, `assertCondition`, which states the condition that must hold and always throws a `TypeError`. The messages are unchanged. The four that change class are the heading depth, the column alignment, the placeholder name and the one-paragraph inline template.
An error for a wrong argument now states the rule, type and range, and stops. It no longer reports what was given: no `, got 7`, no `, got a string`, and no quoted copy of the value. Twelve messages change. Nine lose their `, got …` tail, and the heading one also names the type: "heading depth must be a number from 1 to 6". Three that only said "invalid" or "unknown" and quoted the value now state their rule: the column alignment, the placeholder name and the HTML entity. With nothing left to describe, `describe` is removed, along with the line in `list` that chose between a number's value and its kind.
Jason3S
marked this pull request as draft
November 11, 2026 08:47
Five functions accept their input case by case and reject the rest with a `throw` on the last line. That line is now `assertUnhandledCase`, which never returns, so each case line stays as it is and a new case is still one added line. `htmlEntity` was the last place to throw a plain `Error`; it now throws a `TypeError` like every other rejected argument. The check that turns away a list item inside a line is a condition with its own message, so it uses `assertCondition`.
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.
Summary
An error for a wrong argument now states the rule and stops: it no longer says what was given. Seven functions that threw a plain
Errorfor a wrong value now throw aTypeError, so every rejected argument reports the same error class., got …or quotes the value any more.Errorby name, needs updating.Messages
Each line is a whole message.
heading depth must be a number from 1 to 6a list start must be a whole number from 0 to 999999999column alignment must be 'left', 'center', 'right' or a delimiter such as ':---'a placeholder name must be parts joined by '.', each of ASCII letters, digits, '_' and '-', and not starting with '-'an HTML entity must be a character, a name HTML defines, or a reference such as ' 'table header must be an array, and the same for table rows, a table row, list entries and definition list entriesheading content must be inline, and the same wherever only text, links, formatting or code can godocument content must be blocks, and the same wherever only blocks can godefinition list entry must be a [term, definition] pairexpected a string or a Markdown element{@ name @} is inside code and takes only a string, text, a placeholder or an HTML entity{@ name @} is inside a URL and takes only a string, text or a placeholderError class
These threw
Errorand now throwTypeError:heading, for a wrong depthtableandhtmlTable, for a wrong column alignmentplaceholderandblockPlaceholder, for a wrong nameinlineTemplate, for text of more than one paragraphhtmlEntity, for an unknown nameUsage