Skip to content

refactor: use format to construct errors in utils/library-manifest#13650

Closed
Planeshifter wants to merge 1 commit into
developfrom
philipp/drift-utils-2026-07-25
Closed

refactor: use format to construct errors in utils/library-manifest#13650
Planeshifter wants to merge 1 commit into
developfrom
philipp/drift-utils-2026-07-25

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request refactors error construction in @stdlib/utils/library-manifest to use @stdlib/string/format.

Refactors library-manifest's two TypeError messages in lib/main.js to build via @stdlib/string/format and %s instead of string concatenation, matching the pattern used by 141 of the 142 other utils packages that construct value-interpolating error messages (99.3%). Message text is preserved byte-for-byte, and existing tests assert only the error type, so behavior is unchanged. @stdlib/string/format carries no dependencies, so this introduces no circular dependency.

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Identified by a namespace-wide error-construction scan of utils: library-manifest was the sole package still assembling interpolated error messages via string concatenation. The line-39 note about avoiding stdlib packages concerns the hasOwnProp/objectKeys hot-path built-ins only; @stdlib/string/format is dependency-free and the package already requires @stdlib/fs/resolve-parent-path and @stdlib/utils/convert-path. package.json is deliberately left untouched (in-source dependencies are empty namespace-wide and populated at publish time).

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Research and understanding

Disclosure

This PR was authored by Claude Code running an automated cross-package drift-detection routine over the utils namespace. The routine extracted the error-construction feature across all 198 members, identified library-manifest as the sole value-interpolating concatenation outlier against a 99.3% format majority, and validated the fix as behavior-preserving (byte-for-byte identical messages; tests assert error type only) before applying it.


@stdlib-js/reviewers


Generated by Claude Code

Rewrite the two value-interpolating `TypeError` messages in the main
implementation to build their message via `@stdlib/string/format`
instead of string concatenation. `format` is the canonical error
construction utility across the `utils` namespace: every other
value-interpolating throw (~140 sibling packages) uses it, leaving this
package as the sole outlier constructing error messages by
concatenation.

The message text is preserved byte-for-byte (`%s` coerces values
identically to concatenation), so no observable behavior or test
expectation changes; the package tests assert only the error type.
`@stdlib/string/format` has no dependencies and thus introduces no
circular dependency, consistent with the existing note in `main.js`
regarding avoiding stdlib packages for the hot-path built-ins.

Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
utils/library-manifest $\\color{green}503/503$
$\\color{green}+100.00\\%$
$\\color{green}64/64$
$\\color{green}+100.00\\%$
$\\color{green}5/5$
$\\color{green}+100.00\\%$
$\\color{green}503/503$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

Copy link
Copy Markdown
Member Author

Closing this draft. The underlying finding is sound but cannot be landed within the scope of the automated drift correction that produced it.

Finding. Across @stdlib/utils, 141 of the 142 packages that interpolate a value into an error message use @stdlib/string/format; library-manifest was the sole package still building those two TypeError messages via string concatenation. The proposed change was a behavior-preserving normalization (message text byte-for-byte identical; tests assert error type only).

Blocker. Lint Changed Files lints the entire changed file, not the diff. Any edit to lib/main.js re-lints the whole file and surfaces three pre-existing no-restricted-syntax errors unrelated to this change:

 98:8   error  Use `@stdlib/utils/dirname` instead of path.dirname  no-restricted-syntax
178:11  error  Use `@stdlib/utils/dirname` instead of path.dirname  no-restricted-syntax
180:11  error  Use `@stdlib/utils/dirname` instead of path.dirname  no-restricted-syntax

These path.dirname calls predate the change. Turning CI green would require also rewriting them to @stdlib/utils/dirname — out of scope for an error-construction normalization, and non-trivial here: the package carries a deliberate note (line 39) about minimizing stdlib dependencies to avoid circular dependencies, so swapping the built-in path API warrants its own behavioral review rather than being folded in as an incidental fix.

Rather than expand scope, the correction is dropped. The format normalization is worth doing deliberately alongside a path.dirname@stdlib/utils/dirname lint-debt cleanup for this package, as a scoped change of its own.


Generated by Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants