feat: introduce MagicStringError with concise, consistent messages - #324
Merged
Conversation
antfubot
force-pushed
the
tame-baths-win
branch
from
August 13, 2026 05:57
35e6f6d to
45e8c37
Compare
antfubot
force-pushed
the
tame-baths-win
branch
from
August 13, 2026 06:03
45e8c37 to
9ad9472
Compare
Replace ad hoc `new Error`/`new TypeError` throws with a single MagicStringError type. Every message is prefixed with `[MagicString]` and kept short, lower-case, and consistent in tone, folding any how-to-fix hint into the one message. The concrete error type (previously a mix of `Error` and `TypeError`) was never documented, so consolidating on MagicStringError — which still extends `Error` — is not a breaking change.
antfubot
force-pushed
the
tame-baths-win
branch
from
August 13, 2026 06:05
9ad9472 to
783ee8d
Compare
antfu
approved these changes
Aug 13, 2026
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 & why
Error messages thrown by
magic-stringwere ad hocnew Error/new TypeErrorstrings with inconsistent casing and tone. This normalizes every throw site behind a single, consistent error type in the spirit of "errors worth reading".Changes
MagicStringError(exported from the package entry) — the single error type thrown everywhere, extendingError.[MagicString]so its source is obvious at a glance.insert() is deprecated, use appendLeft() or prependRight()).MagicString,Bundle, andSourceMaptoMagicStringError, and unify the duplicated "content must be a string" checks.Examples:
Backward compatibility
MagicStringErrorextendsError, soinstanceof Errorandtry/catchkeep working. A few throw sites previously producedTypeError, but that concrete type was never documented, so consolidating onMagicStringErroris not considered a breaking change. Only the human-readable message wording changes.This PR was created with the help of an agent.