Skip to content

fix: show full parent command path in subcommand usage errors#9404

Open
shaanmajid wants to merge 2 commits into
npm:latestfrom
shaanmajid:fix/subcommand-usage-path
Open

fix: show full parent command path in subcommand usage errors#9404
shaanmajid wants to merge 2 commits into
npm:latestfrom
shaanmajid:fix/subcommand-usage-path

Conversation

@shaanmajid
Copy link
Copy Markdown

Summary

  • Subcommand runtime usage errors (e.g., npm stage approve without a <stage-id>) rendered the bare subcommand name (e.g., npm approve <stage-id>) and Run "npm help approve" for more info -- pointing at a command and help page that don't exist.
  • The subcommand instance now carries its parent command name, so usage output and usageError render the full path (npm stage approve <stage-id>) and point to the real help page (npm help stage)

This fix applies to npm stage and npm trust.

Implementation

  • lib/npm.js: set parentName on the subcommand instance during dispatch (and use the full joined path on the --help branch for parity).
  • lib/base-cmd.js: the instance usage getter threads parentName into getUsage, and the help footer resolves to the top-level documented command.

References

Fixes #9403

@shaanmajid shaanmajid requested review from a team as code owners May 25, 2026 20:48
@swarnim-dev
Copy link
Copy Markdown

Tested this locally and can confirm it works. Ran the test suite and everything passes:

  • stage/approve tests: 5/5 ✅
  • trust command tests: 71 assertions across 5 files ✅

The fix does what it's supposed to - error messages now show the full command path like "npm stage approve " instead of the broken "npm approve ". Verified it works for both stage and trust subcommands.

Code looks solid, no edge cases I can find, and there's good test coverage.

Ready to ship acc. to me!

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.

[BUG] Subcommand usage errors show the wrong command path (e.g. "npm approve" instead of "npm stage approve")

2 participants