Skip to content

fix(cli): align utils/update/ + utils/command/ error messages with 4-ingredient strategy#1257

Open
John-David Dalton (jdalton) wants to merge 2 commits intomainfrom
jdd/error-msg-update-command
Open

fix(cli): align utils/update/ + utils/command/ error messages with 4-ingredient strategy#1257
John-David Dalton (jdalton) wants to merge 2 commits intomainfrom
jdd/error-msg-update-command

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton John-David Dalton (jdalton) commented Apr 22, 2026

Summary

PR 4 in the error-message cleanup series. Covers packages/cli/src/utils/update/ (the update-checking stack) and packages/cli/src/utils/command/registry-core.mts (the custom command-registry layer). ~17 messages across 3 source files + 3 test files.

What's fixed

utils/update/checker.mts (8 throws)

Registry / network / input validation errors. Before, most said "Package name must be a non-empty string" or "Invalid registry URL: foo". After, each message names:

  • the function that was called
  • the received value (with its type when it matters)
  • the valid shape

Example:

Before: Invalid version data in registry response
After: https://registry.npmjs.org/foo/latest responded without a .version string (got: {"name":"foo"}); the registry may be misconfigured or foo may not exist — verify the URL in a browser

utils/update/manager.mts (3 warn guards)

Mirror validation on the manager layer — same options, checked again before the checker call. Previously shared wording with checker.mts which was confusing when both fired. Now each message explicitly prefixes checkForUpdates options.X so you can tell which layer complained.

These are loggerLocal.warn + return false, not throws, so the tone stays soft ("skipping update check" rather than "throw").

utils/command/registry-core.mts (6 throws)

The custom CLI command-registry layer. Conflict errors now name both commands involved; middleware errors name the index; flag errors name the flag and the expected type. Examples:

Before: Alias "test" conflicts with existing command "test"
After: cannot register command "other" alias "test": conflicts with command "test"; rename the alias or unregister the conflicting command first

Before: Missing value for flag --name
After: flag --name requires a string value but none was provided; pass it as --name=<value> or --name <value>

Tests updated

  • test/unit/utils/update/checker.test.mts — 6 assertions switched to regex
  • test/unit/utils/update/manager.test.mts — 3 assertions switched to expect.stringContaining
  • test/unit/utils/command/registry-core.test.mts — 5 assertions

153/153 tests in the affected suites pass.

Test plan

  • CI green
  • Sanity: pass --page foo or similar invalid flag into the custom registry's built-in parser (it's not wired to most commands, but the tests exercise it)

Note

Low Risk
Low risk: changes are limited to error/warn message wording and corresponding test assertion updates, with no functional logic changes to command execution or update checking paths.

Overview
Improves CLI diagnostics by rewriting command registry and update-checking validation errors to include the calling function/context, the received value, and clear remediation guidance (e.g., duplicate command/alias conflicts, middleware next() double-invocation, missing/invalid flag values, invalid registry inputs/registry responses).

Updates unit tests to match the new, more descriptive messages (switching several assertions to regex/stringContaining).

Reviewed by Cursor Bugbot for commit 952b914. Configure here.

…ingredient strategy

Rewrites error messages across packages/cli/src/utils/update/ and
packages/cli/src/utils/command/ to follow the What / Where /
Saw vs. wanted / Fix strategy from CLAUDE.md.

Sources:
- utils/update/checker.mts: 8 messages (URL validation, package name
  / registry URL validation, version-response validation). Each now
  names the function, the received type, and what a valid value
  looks like.
- utils/update/manager.mts: 3 messages (mirror guards for name /
  version / ttl). Still warn-and-return-false, but the text now
  tells the caller exactly which option was wrong.
- utils/command/registry-core.mts: 6 messages (command / alias
  registration conflicts, middleware next() misuse, flag parsing
  failures). Each now names the offending command, flag name, or
  index so debuggers don't need to read source.

Tests updated:
- test/unit/utils/update/checker.test.mts: 6 assertions (switched
  to regex)
- test/unit/utils/update/manager.test.mts: 3 assertions (switched
  to expect.stringContaining)
- test/unit/utils/command/registry-core.test.mts: 5 assertions

All 153 tests in the affected suites pass.

Follows strategy from #1254. Part of the multi-PR series started
by #1255 (commands/) and continued in #1256 (utils/dlx/).
Comment thread packages/cli/src/utils/command/registry-core.mts
Comment thread packages/cli/src/utils/update/checker.mts
Two issues flagged by Cursor bugbot on #1257:

1. (Medium) registry-core.mts middleware error reported the wrong
   offending middleware index. `index` tracks the highest dispatched
   position, not the caller; when dispatch(i) is re-entered after a
   double-next(), the offender held middleware[i - 1]'s next closure.
   Fixed to use `i - 1` with a comment explaining why.

2. (Low) checker.mts error referenced a non-existent
   `UpdateChecker.fetch()` — the object is actually exported as
   `NetworkUtils`. Renamed in both the error and its test regex.

Caught by #1257 bugbot review.
@jdalton
Copy link
Copy Markdown
Contributor Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 952b914. Configure here.

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.

1 participant