Skip to content

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

Merged
owlstronaut merged 3 commits into
npm:latestfrom
shaanmajid:fix/subcommand-usage-path
Jun 2, 2026
Merged

fix: show full parent command path in subcommand usage errors#9404
owlstronaut merged 3 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!

@shaanmajid
Copy link
Copy Markdown
Author

CI failures were from stale snapshot; should be fixed with 40655c0

@owlstronaut owlstronaut merged commit fe41ae7 into npm:latest Jun 2, 2026
22 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

⚠️ Backport to release/v11 failed.

This usually means the cherry-pick had conflicts. Please create a manual backport:

git fetch origin release/v11
git checkout -b backport/v11/9404 origin/release/v11
git cherry-pick -x fe41ae7c6b38e7e9957b646bf379e2b5daae03f9
# resolve any conflicts, then:
git push origin backport/v11/9404
Error details
Command failed: git cherry-pick -x fe41ae7c6b38e7e9957b646bf379e2b5daae03f9
error: could not apply fe41ae7c6... fix: show full parent command path in subcommand usage errors (#9404)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"

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

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")

3 participants