Repository navigation
List excess arguments in error message - #2384
Conversation
|
For listing the arguments, I wonder whether they should be quoted. Given the arguments could contain spaces and commas, I think quoting might be appropriate? (Note: we can't match exactly how they appear on the command-line as any original quotes have been stripped during processing by the shell.) I looked at how choices are handled, and we have done it both ways! In the help we are fairly consistent and use Given: program.addOption(new Option('-d, --drink <size>', 'drink size').choices(['small', 'medium', 'large']).default('medium'));See quoted in the help: But unquoted in the error: $ node index.mjs --drink huge
error: option '-d, --drink <size>' argument 'huge' is invalid. Allowed choices are small, medium, large. |
|
I think my original reasoning was that the command-line was likely visible just above the error, so relisting arguments not needed. But good point this is less clear with options, especially if mixed order. $ node index.mjs -d small file1 -d medium file2 -d large file3
error: too many arguments. Expected 2 arguments but got 3: file1, file2, file3. |
|
No, the original message contained zero hints about where to look for the problem. I guess there’s no need for quoting, since the arguments are separated by commas. And in the rare case where an argument contains a comma, it's not an exact explanation — but it should still be pretty obvious where to look, at least. |
shadowspawn
left a comment
There was a problem hiding this comment.
I think this is a useful improvement. I would like the changes to CHANGELOG removed.
|
It is an interesting question whether change to error messages are technically a semver breaking change, but I know some projects test messages in unit tests or scrape the error message for custom handling. Unless/until we have a stated policy that messages may change I prefer to keep the changes in a semver major release. |
|
I don't think it's very urgent and big enough for major release on its own, but I think you are right it should be included in next major release. |
|
(Note: waiting for revert on accidental changes to CHANGELOG.) |
shadowspawn
left a comment
There was a problem hiding this comment.
LGTM, thanks @stiff
|
Released in v15: https://github.com/tj/commander.js/releases/tag/v15.0.0 |
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [commander](https://github.com/tj/commander.js) | [`14.0.3` → `15.0.0`](https://renovatebot.com/diffs/npm/commander/14.0.3/15.0.0) |  |  | --- ### Release Notes <details> <summary>tj/commander.js (commander)</summary> ### [`v15.0.0`](https://github.com/tj/commander.js/blob/HEAD/CHANGELOG.md#1500-2026-05-29) [Compare Source](tj/commander.js@v14.0.3...v15.0.0) Commander 15 is ESM only. This is expected to be seamless for ESM consumers, but some CommonJS consumers may hit issues with tooling requiring configuration for ESM-only dependencies. See Migration Tips below. The release of Commander 15 moves Commander 14 into maintenance. Commander 14 will get security updates for 12 months (to May 2027). For more info see [Release Policy](./docs/release-policy.md). ##### Added - show excess command-arguments in error message (\[[#​2384](tj/commander.js#2384)]) ##### Fixed - *Breaking:* only lone `--no-*` option sets default option value to `true`, default not implicitly set when define both positive and negative option in either order (\[[#​2405](tj/commander.js#2405)]) - update example to use compatible character for MINGW64 (\[[#​2475](tj/commander.js#2475)]) ##### Changed - *Breaking:* migrated Commander implementation from CommonJS to ESM (\[[#​2464](tj/commander.js#2464)]) - *Breaking:* Commander 15 requires Node.js v22.12.0 or higher (for `require(esm)`). - dev: switch tests from Jest to `node:test` test runner (\[[#​2463](tj/commander.js#2463)]) ##### Deleted - *Breaking:* removed deprecated export of `commander/esm.mjs` (\[[#​2464](tj/commander.js#2464)]) ##### Migration Tips Commander 15 is ESM only, but this does not mean you need to migrate to ESM to use it. Importing ESM from CommonJS is supported by Node.js, and Bun, and Deno. Hopefully it Just Works for you! However, you may be using a different runtime or some other part of your setup that may not yet natively support importing ESM from CommonJS, such as your testing framework or bundler. If you have problems using Commander 15 in your environment, one option is stay on Commander 14 for now. Commander 14 will get security updates until May 2027 and things will hopefully improve for your setup in the meantime. </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTUuMCIsInVwZGF0ZWRJblZlciI6IjQzLjE5NS4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119--> Reviewed-on: https://codeberg.org/huskas-2189/Bookmark/pulls/85
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [commander](https://github.com/tj/commander.js) | [`14.0.3` → `15.0.0`](https://renovatebot.com/diffs/npm/commander/14.0.3/15.0.0) |  |  | --- ### Release Notes <details> <summary>tj/commander.js (commander)</summary> ### [`v15.0.0`](https://github.com/tj/commander.js/blob/HEAD/CHANGELOG.md#1500-2026-05-29) [Compare Source](tj/commander.js@v14.0.3...v15.0.0) Commander 15 is ESM only. This is expected to be seamless for ESM consumers, but some CommonJS consumers may hit issues with tooling requiring configuration for ESM-only dependencies. See Migration Tips below. The release of Commander 15 moves Commander 14 into maintenance. Commander 14 will get security updates for 12 months (to May 2027). For more info see [Release Policy](./docs/release-policy.md). ##### Added - show excess command-arguments in error message (\[[#​2384](tj/commander.js#2384)]) ##### Fixed - *Breaking:* only lone `--no-*` option sets default option value to `true`, default not implicitly set when define both positive and negative option in either order (\[[#​2405](tj/commander.js#2405)]) - update example to use compatible character for MINGW64 (\[[#​2475](tj/commander.js#2475)]) ##### Changed - *Breaking:* migrated Commander implementation from CommonJS to ESM (\[[#​2464](tj/commander.js#2464)]) - *Breaking:* Commander 15 requires Node.js v22.12.0 or higher (for `require(esm)`). - dev: switch tests from Jest to `node:test` test runner (\[[#​2463](tj/commander.js#2463)]) ##### Deleted - *Breaking:* removed deprecated export of `commander/esm.mjs` (\[[#​2464](tj/commander.js#2464)]) ##### Migration Tips Commander 15 is ESM only, but this does not mean you need to migrate to ESM to use it. Importing ESM from CommonJS is supported by Node.js, and Bun, and Deno. Hopefully it Just Works for you! However, you may be using a different runtime or some other part of your setup that may not yet natively support importing ESM from CommonJS, such as your testing framework or bundler. If you have problems using Commander 15 in your environment, one option is stay on Commander 14 for now. Commander 14 will get security updates until May 2027 and things will hopefully improve for your setup in the meantime. </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTUuMCIsInVwZGF0ZWRJblZlciI6IjQzLjE5NS4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119--> Reviewed-on: https://codeberg.org/huskas-2189/Bookmark/pulls/85
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [commander](https://github.com/tj/commander.js) | [`14.0.3` → `15.0.0`](https://renovatebot.com/diffs/npm/commander/14.0.3/15.0.0) |  |  | --- ### Release Notes <details> <summary>tj/commander.js (commander)</summary> ### [`v15.0.0`](https://github.com/tj/commander.js/blob/HEAD/CHANGELOG.md#1500-2026-05-29) [Compare Source](tj/commander.js@v14.0.3...v15.0.0) Commander 15 is ESM only. This is expected to be seamless for ESM consumers, but some CommonJS consumers may hit issues with tooling requiring configuration for ESM-only dependencies. See Migration Tips below. The release of Commander 15 moves Commander 14 into maintenance. Commander 14 will get security updates for 12 months (to May 2027). For more info see [Release Policy](./docs/release-policy.md). ##### Added - show excess command-arguments in error message (\[[#​2384](tj/commander.js#2384)]) ##### Fixed - *Breaking:* only lone `--no-*` option sets default option value to `true`, default not implicitly set when define both positive and negative option in either order (\[[#​2405](tj/commander.js#2405)]) - update example to use compatible character for MINGW64 (\[[#​2475](tj/commander.js#2475)]) ##### Changed - *Breaking:* migrated Commander implementation from CommonJS to ESM (\[[#​2464](tj/commander.js#2464)]) - *Breaking:* Commander 15 requires Node.js v22.12.0 or higher (for `require(esm)`). - dev: switch tests from Jest to `node:test` test runner (\[[#​2463](tj/commander.js#2463)]) ##### Deleted - *Breaking:* removed deprecated export of `commander/esm.mjs` (\[[#​2464](tj/commander.js#2464)]) ##### Migration Tips Commander 15 is ESM only, but this does not mean you need to migrate to ESM to use it. Importing ESM from CommonJS is supported by Node.js, and Bun, and Deno. Hopefully it Just Works for you! However, you may be using a different runtime or some other part of your setup that may not yet natively support importing ESM from CommonJS, such as your testing framework or bundler. If you have problems using Commander 15 in your environment, one option is stay on Commander 14 for now. Commander 14 will get security updates until May 2027 and things will hopefully improve for your setup in the meantime. </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTUuMCIsInVwZGF0ZWRJblZlciI6IjQzLjE5NS4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119--> Reviewed-on: https://codeberg.org/huskas-2189/Bookmark/pulls/85
Sometimes a typo in arguments list can be parsed as an excess argument rather than option. When the options list is long, finding it can be tricky, so it would be helpful to see exactly what arguments are treated as excess.
Solution
Real life example by mistakenly adding spaces before # in systemd service file:
ChangeLog
List excess arguments in error message