Skip to content

refactor: normalize dimension-check error construction across ndarray/iter#12985

Closed
Planeshifter wants to merge 6 commits into
developfrom
philipp/drift-ndarray-iter-2026-06-20
Closed

refactor: normalize dimension-check error construction across ndarray/iter#12985
Planeshifter wants to merge 6 commits into
developfrom
philipp/drift-ndarray-iter-2026-06-20

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

Six packages in @stdlib/ndarray/iter have a single residual plain-string throw new TypeError( '...' ) at the dimension-count check that was missed during the migration to the canonical format() error-construction style. Every other throw in each of these same files — including a no-argument throw new Error( format( 'invalid option. Cannot write to read-only array.' ) ); for the read-only check — already wraps the message in format(). This pull request wraps the dimension-count throws in format() to match. Error message text and TypeError class are unchanged.

Namespace summary

  • Members analyzed: 14 (no autogenerated members in this namespace)
  • Features analyzed: file tree, package.json shape, README section order, top-level manifest.json shape, test/ / benchmark/ / examples/ filenames, JSDoc shape, return kind, validation prologue, error construction, dependency set
  • Features with a clear majority (≥75%) and zero outliers: file tree, top-level package.json keys, directories keys, README section sequence (## Usage## Notes## Examples## See Also), JSDoc @example present, returnKind: iterator
  • Drift surfaced: error construction. 8 of 14 packages (entries, indices, interleave-subarrays, select-dimension, stacks, subarrays, to-array-each, values) use format() for every throw; the 6 outliers below each have one residual plain-string throw. At the throw-site level, 50 of 56 throws across the namespace (89%) already use format().
  • Features excluded for absence of a clear majority: public signature shape, validation prologue sequence, JSDoc @param count, @throws count — each varies with the underlying function (some packages take (x), others (x, dim), (x, dims), (arrays, ndims), etc.), so cross-package vote does not apply.

@stdlib/ndarray/iter/columns

The ndims < 2 check throws a plain-string TypeError. Every other throw in lib/main.js — including the no-argument format() call guarding the read-only Error — already uses format(). Wrap the dimension-check message in format() so the file is internally consistent.

@stdlib/ndarray/iter/column-entries

Same drift as columns: a single plain-string TypeError at the ndims < 2 check, surrounded by format()-wrapped throws. Wrap the message in format().

@stdlib/ndarray/iter/rows

Twin of columns and carries the same drift at the ndims < 2 check. Wrap the message in format().

@stdlib/ndarray/iter/row-entries

Twin of column-entries and carries the same drift at the ndims < 2 check. Wrap the message in format().

@stdlib/ndarray/iter/matrices

Same drift, three-dimension variant: the ndims < 3 check throws a plain-string TypeError while every other throw uses format(). Wrap the message in format().

@stdlib/ndarray/iter/matrix-entries

Same drift as matrices at the ndims < 3 check. Wrap the message in format().

Related Issues

None.

Questions

No.

Other

Validation

  • Structural extraction. File trees, top-level package.json keys, scripts / stdlib / directories shapes, README heading sequences, and test/ / benchmark/ / examples/ filenames compared across all 14 members. No structural drift.
  • Semantic extraction. One per-package agent read each package's lib/main.js and lib/index.js and returned a strict-schema JSON bundle covering public signature, return kind, validation prologue, error-construction style, JSDoc shape, and the @stdlib/* dependency set.
  • Three-agent validation (one opus semantic-review, one opus cross-reference, one sonnet structural-review) confirmed confirmed-drift for all 6 outliers. Tests rely on the TypeError class only — no assertions on message text. No @throws annotation, REPL doc, README example, or TypeScript declaration depends on the construction call.
  • Cross-run dedup. Open and recently-merged PRs touching @stdlib/ndarray/iter searched; no collision (PR docs: improve examples of ndarray/iter namespace #1686 touches namespace examples only; PR docs: update ndarray/iter TypeScript declarations #12661 updates TypeScript declarations only; PR docs: propagate recent develop fixes to sibling packages #12642 touches interleave-subarrays/docs/repl.txt only).

Deliberately excluded

  • Public-signature, validation-prologue, JSDoc-param-count, and @throws-count features: vary with the underlying function and have no cross-namespace majority. Per-package corrections to these would require human judgement and are out of scope for an automated drift pass.
  • The nditerColumns S0/nditerRows S1 variable-naming difference: the two functions iterate over the trailing and second-to-last dimensions respectively, so the two-letter suffix encodes a deliberate dimension index — not drift.

Checklist

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)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding
  • Review and debugging

Disclosure

This PR was authored by Claude Code on behalf of @Planeshifter as an automated cross-package API-drift audit of @stdlib/ndarray/iter. Candidate corrections were located via per-package semantic-feature extraction (one sonnet agent per package), validated by three parallel reviewer agents (opus semantic-review, opus cross-reference, sonnet structural-review), then applied as one mechanical patch per package in the primary worktree. A human will audit and promote the PR out of draft.


@stdlib-js/reviewers


Generated by Claude Code

claude added 6 commits June 20, 2026 08:14
…er/columns`

Wrap the existing plain-string `TypeError` for the `ndims < 2` check in
`format()`, matching the construction style already used by every other
throw in `lib/main.js` (including the `format()`-with-no-arguments call
for the read-only `Error`). All 14 packages in `@stdlib/ndarray/iter`
use `format()` for the bulk of their throws (89% of throws across the
namespace); this normalizes the one residual plain-string throw in this
package to the canonical convention.

The error message text and `TypeError` class are unchanged, so the
change is invisible to consumers.
…er/column-entries`

Wrap the existing plain-string `TypeError` for the `ndims < 2` check in
`format()`, matching the construction style already used by every other
throw in `lib/main.js` (including the `format()`-with-no-arguments call
for the read-only `Error`). All 14 packages in `@stdlib/ndarray/iter`
use `format()` for the bulk of their throws (89% of throws across the
namespace); this normalizes the one residual plain-string throw in this
package to the canonical convention.

The error message text and `TypeError` class are unchanged, so the
change is invisible to consumers.
…er/rows`

Wrap the existing plain-string `TypeError` for the `ndims < 2` check in
`format()`, matching the construction style already used by every other
throw in `lib/main.js` (including the `format()`-with-no-arguments call
for the read-only `Error`). All 14 packages in `@stdlib/ndarray/iter`
use `format()` for the bulk of their throws (89% of throws across the
namespace); this normalizes the one residual plain-string throw in this
package to the canonical convention.

The error message text and `TypeError` class are unchanged, so the
change is invisible to consumers.
…er/row-entries`

Wrap the existing plain-string `TypeError` for the `ndims < 2` check in
`format()`, matching the construction style already used by every other
throw in `lib/main.js` (including the `format()`-with-no-arguments call
for the read-only `Error`). All 14 packages in `@stdlib/ndarray/iter`
use `format()` for the bulk of their throws (89% of throws across the
namespace); this normalizes the one residual plain-string throw in this
package to the canonical convention.

The error message text and `TypeError` class are unchanged, so the
change is invisible to consumers.
…er/matrices`

Wrap the existing plain-string `TypeError` for the `ndims < 3` check in
`format()`, matching the construction style already used by every other
throw in `lib/main.js` (including the `format()`-with-no-arguments call
for the read-only `Error`). All 14 packages in `@stdlib/ndarray/iter`
use `format()` for the bulk of their throws (89% of throws across the
namespace); this normalizes the one residual plain-string throw in this
package to the canonical convention.

The error message text and `TypeError` class are unchanged, so the
change is invisible to consumers.
…er/matrix-entries`

Wrap the existing plain-string `TypeError` for the `ndims < 3` check in
`format()`, matching the construction style already used by every other
throw in `lib/main.js` (including the `format()`-with-no-arguments call
for the read-only `Error`). All 14 packages in `@stdlib/ndarray/iter`
use `format()` for the bulk of their throws (89% of throws across the
namespace); this normalizes the one residual plain-string throw in this
package to the canonical convention.

The error message text and `TypeError` class are unchanged, so the
change is invisible to consumers.
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
ndarray/iter/column-entries $\\color{green}290/290$
$\\color{green}+100.00\\%$
$\\color{green}27/27$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}290/290$
$\\color{green}+100.00\\%$
ndarray/iter/columns $\\color{green}285/285$
$\\color{green}+100.00\\%$
$\\color{green}27/27$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}285/285$
$\\color{green}+100.00\\%$
ndarray/iter/matrices $\\color{green}274/274$
$\\color{green}+100.00\\%$
$\\color{green}27/27$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}274/274$
$\\color{green}+100.00\\%$
ndarray/iter/matrix-entries $\\color{green}291/291$
$\\color{green}+100.00\\%$
$\\color{green}27/27$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}291/291$
$\\color{green}+100.00\\%$
ndarray/iter/row-entries $\\color{green}290/290$
$\\color{green}+100.00\\%$
$\\color{green}27/27$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}290/290$
$\\color{green}+100.00\\%$
ndarray/iter/rows $\\color{green}285/285$
$\\color{green}+100.00\\%$
$\\color{green}27/27$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}285/285$
$\\color{green}+100.00\\%$

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

@kgryte kgryte left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the changes in this PR are necessary, as format is not needed. There are no placeholders in the error messages to interpolate.

@kgryte kgryte closed this Jun 20, 2026
@kgryte kgryte deleted the philipp/drift-ndarray-iter-2026-06-20 branch June 20, 2026 22:52
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.

4 participants