Skip to content

List excess arguments in error message - #2384

Merged
abetomo merged 4 commits into
tj:release/15.xfrom
stiff:master
Jul 19, 2025
Merged

abetomo merged 4 commits into
tj:release/15.xfrom
stiff:master

Conversation

@stiff

@stiff stiff commented Jun 27, 2025

Copy link
Copy Markdown
Contributor

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:

error: too many arguments. Expected 0 arguments but got 2: #, #--address=0x72.

ChangeLog

List excess arguments in error message

Comment thread CHANGELOG.md Resolved
Comment thread lib/command.js Resolved
@shadowspawn

Copy link
Copy Markdown
Collaborator

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 JSON.stringify. Although that is partly because some values, like default, not being plain strings. And use same pattern so consistent in display.

Given:

program.addOption(new Option('-d, --drink <size>', 'drink size').choices(['small', 'medium', 'large']).default('medium'));

See quoted in the help:

Options:
  -d, --drink <size>  drink size (choices: "small", "medium", "large", default: "medium")

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.

@shadowspawn

shadowspawn commented Jun 27, 2025 •

Copy link
Copy Markdown
Collaborator

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.

@stiff

stiff commented Jun 28, 2025

Copy link
Copy Markdown
Contributor Author

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.

Comment thread lib/command.js Resolved
@shadowspawn
shadowspawn changed the base branch from develop to release/15.x July 3, 2025 22:14

@shadowspawn shadowspawn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is a useful improvement. I would like the changes to CHANGELOG removed.

@shadowspawn

Copy link
Copy Markdown
Collaborator

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.

@shadowspawn shadowspawn added the semver: major Releasing requires a major version bump, not backwards compatible label Jul 3, 2025
@stiff

stiff commented Jul 5, 2025

Copy link
Copy Markdown
Contributor Author

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.

@shadowspawn

Copy link
Copy Markdown
Collaborator

(Note: waiting for revert on accidental changes to CHANGELOG.)

@shadowspawn shadowspawn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks @stiff

@abetomo abetomo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@abetomo
abetomo merged commit 2e96cd3 into tj:release/15.x Jul 19, 2025
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Jul 19, 2025
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label May 29, 2026
@shadowspawn

Copy link
Copy Markdown
Collaborator

huskas-2189 pushed a commit to huskas-2189/Bookmark that referenced this pull request Jun 14, 2026
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) | ![age](https://developer.mend.io/api/mc/badges/age/npm/commander/15.0.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/commander/14.0.3/15.0.0?slim=true) |

---

### 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 (\[[#&#8203;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 (\[[#&#8203;2405](tj/commander.js#2405)])
- update example to use compatible character for MINGW64 (\[[#&#8203;2475](tj/commander.js#2475)])

##### Changed

- *Breaking:* migrated Commander implementation from CommonJS to ESM (\[[#&#8203;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 (\[[#&#8203;2463](tj/commander.js#2463)])

##### Deleted

- *Breaking:* removed deprecated export of `commander/esm.mjs` (\[[#&#8203;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
huskas-2189 pushed a commit to huskas-2189/Bookmark that referenced this pull request Jun 19, 2026
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) | ![age](https://developer.mend.io/api/mc/badges/age/npm/commander/15.0.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/commander/14.0.3/15.0.0?slim=true) |

---

### 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 (\[[#&#8203;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 (\[[#&#8203;2405](tj/commander.js#2405)])
- update example to use compatible character for MINGW64 (\[[#&#8203;2475](tj/commander.js#2475)])

##### Changed

- *Breaking:* migrated Commander implementation from CommonJS to ESM (\[[#&#8203;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 (\[[#&#8203;2463](tj/commander.js#2463)])

##### Deleted

- *Breaking:* removed deprecated export of `commander/esm.mjs` (\[[#&#8203;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
huskas-2189 pushed a commit to huskas-2189/Bookmark that referenced this pull request Jun 19, 2026
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) | ![age](https://developer.mend.io/api/mc/badges/age/npm/commander/15.0.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/commander/14.0.3/15.0.0?slim=true) |

---

### 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 (\[[#&#8203;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 (\[[#&#8203;2405](tj/commander.js#2405)])
- update example to use compatible character for MINGW64 (\[[#&#8203;2475](tj/commander.js#2475)])

##### Changed

- *Breaking:* migrated Commander implementation from CommonJS to ESM (\[[#&#8203;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 (\[[#&#8203;2463](tj/commander.js#2463)])

##### Deleted

- *Breaking:* removed deprecated export of `commander/esm.mjs` (\[[#&#8203;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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver: major Releasing requires a major version bump, not backwards compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants