Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a panic when generating help while the subcommand and all option groups are hidden #354

Merged

Conversation

bboozzoo
Copy link
Contributor

@bboozzoo bboozzoo commented Jan 5, 2021

The panic is caused by calling strings.Repeat() with negative repeat count. This
is triggered by incorrectly computed alignment info.

Since the positional arguments are always shown (even when the subcommand is
hidden), the arguments need to be accounted for when calculating alignment.

The panic backtrace is the following:

--- FAIL: TestHiddenCommandNoBuiltinHelp (0.00s)
panic: strings: negative Repeat count [recovered]
        panic: strings: negative Repeat count

goroutine 91 [running]:
testing.tRunner.func1.1(0x57f160, 0x5f3f20)
        /home/maciek/code/go/go/src/testing/testing.go:1072 +0x30d
testing.tRunner.func1(0xc000252a80)
        /home/maciek/code/go/go/src/testing/testing.go:1075 +0x41a
panic(0x57f160, 0x5f3f20)
        /home/maciek/code/go/go/src/runtime/panic.go:969 +0x1b9
strings.Repeat(0x5bc3b0, 0x1, 0xfffffffffffffff1, 0x13, 0x0)
        /home/maciek/code/go/go/src/strings/strings.go:529 +0x5e5
github.com/jessevdk/go-flags.(*Parser).WriteHelp(0xc000387340, 0x5f6d40, 0xc0002772f0)
        /home/maciek/work/canonical/workspace/src/github.com/jessevdk/go-flags/help.go:449 +0x510
github.com/jessevdk/go-flags.TestHiddenCommandNoBuiltinHelp(0xc000252a80)
        /home/maciek/work/canonical/workspace/src/github.com/jessevdk/go-flags/help_test.go:469 +0x4d4
testing.tRunner(0xc000252a80, 0x5cd9a0)
        /home/maciek/code/go/go/src/testing/testing.go:1123 +0xef
created by testing.(*T).Run
        /home/maciek/code/go/go/src/testing/testing.go:1168 +0x2b3
exit status 2
FAIL    github.com/jessevdk/go-flags    0.016s

There's also an open question whether positional arguments should be listed in the help output.

…groups are hidden

The panic is caused by calling strings.Repeat() with negative repeat count. This
is triggered by incorrectly computed alignment info.

Since the positional arguments are always shown (even when the subcommand is
hidden), the arguments need to be accounted for when calculating alignment.

The panic backtrace is the following:

--- FAIL: TestHiddenCommandNoBuiltinHelp (0.00s)
panic: strings: negative Repeat count [recovered]
        panic: strings: negative Repeat count

goroutine 91 [running]:
testing.tRunner.func1.1(0x57f160, 0x5f3f20)
        /home/maciek/code/go/go/src/testing/testing.go:1072 +0x30d
testing.tRunner.func1(0xc000252a80)
        /home/maciek/code/go/go/src/testing/testing.go:1075 +0x41a
panic(0x57f160, 0x5f3f20)
        /home/maciek/code/go/go/src/runtime/panic.go:969 +0x1b9
strings.Repeat(0x5bc3b0, 0x1, 0xfffffffffffffff1, 0x13, 0x0)
        /home/maciek/code/go/go/src/strings/strings.go:529 +0x5e5
github.com/jessevdk/go-flags.(*Parser).WriteHelp(0xc000387340, 0x5f6d40, 0xc0002772f0)
        /home/maciek/work/canonical/workspace/src/github.com/jessevdk/go-flags/help.go:449 +0x510
github.com/jessevdk/go-flags.TestHiddenCommandNoBuiltinHelp(0xc000252a80)
        /home/maciek/work/canonical/workspace/src/github.com/jessevdk/go-flags/help_test.go:469 +0x4d4
testing.tRunner(0xc000252a80, 0x5cd9a0)
        /home/maciek/code/go/go/src/testing/testing.go:1123 +0xef
created by testing.(*T).Run
        /home/maciek/code/go/go/src/testing/testing.go:1168 +0x2b3
exit status 2
FAIL    github.com/jessevdk/go-flags    0.016s

Signed-off-by: Maciek Borzecki <maciek.borzecki@gmail.com>
@bboozzoo
Copy link
Contributor Author

bboozzoo commented Jan 7, 2021

Uhh, looks like some of the dependencies won't build on 1.9/1.10 at this point:

hub.com/onsi/ginkgo/ginkgo/outline

../../onsi/ginkgo/ginkgo/outline/outline.go:89:8: undefined: strings.Builder

and 1.10:

# github.com/onsi/ginkgo/ginkgo

../../onsi/ginkgo/ginkgo/generate_command.go:259:9: undefined: strings.ReplaceAll

@jessevdk jessevdk merged commit 4d0b7bb into jessevdk:master Mar 21, 2021
@jessevdk
Copy link
Owner

Nice catch! Looks good, I've updated travis on master but didn't manage to trigger a rebuild for your PR. I've merged.

@bboozzoo
Copy link
Contributor Author

Thank you for merging it!

nabeken added a commit to nabeken/psadm that referenced this pull request Jun 17, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/jessevdk/go-flags](https://github.com/jessevdk/go-flags)
| require | minor | `v1.5.0` -> `v1.6.1` |

---

### Release Notes

<details>
<summary>jessevdk/go-flags (github.com/jessevdk/go-flags)</summary>

###
[`v1.6.1`](https://github.com/jessevdk/go-flags/releases/tag/v1.6.1)

[Compare
Source](https://github.com/jessevdk/go-flags/compare/v1.6.0...v1.6.1)

**Full Changelog**:
jessevdk/go-flags@v1.6.0...v1.6.1

###
[`v1.6.0`](https://github.com/jessevdk/go-flags/releases/tag/v1.6.0)

[Compare
Source](https://github.com/jessevdk/go-flags/compare/v1.5.0...v1.6.0)

#### What's Changed

- ini: fix IniParser.write() for zero values by
[@&#8203;sean-](https://github.com/sean-) in
[jessevdk/go-flags#332
- fix a panic when generating help while the subcommand and all option
groups are hidden by [@&#8203;bboozzoo](https://github.com/bboozzoo)
in
[jessevdk/go-flags#354
- Help for positional args without allcmd.ArgsRequired dependent from
arg.Required by [@&#8203;sv99](https://github.com/sv99) in
[jessevdk/go-flags#342
- Bump golang.org/x/sys from 0.0.0-20210320140829-1e4c9ba3b0c4 to 0.1.0
by [@&#8203;dependabot](https://github.com/dependabot) in
[jessevdk/go-flags#396
- Option to allow passing value to bool flag by
[@&#8203;alexcb](https://github.com/alexcb) in
[jessevdk/go-flags#367
- Add support for SOURCE_DATE_EPOCH for TestMan by
[@&#8203;anthonyfok](https://github.com/anthonyfok) in
[jessevdk/go-flags#376
- Update to run go-flags on AIX by
[@&#8203;llrocha](https://github.com/llrocha) in
[jessevdk/go-flags#390
- Add option for key value delimiter by
[@&#8203;anaprimawaty](https://github.com/anaprimawaty) in
[jessevdk/go-flags#392
- Undersocre support for numbers (set default base for strconv.Parse\*
to 0) by [@&#8203;GRbit](https://github.com/GRbit) in
[jessevdk/go-flags#404
- docs: add ENV variable usage example by
[@&#8203;cemremengu](https://github.com/cemremengu) in
[jessevdk/go-flags#371
- Support per-command PassAfterNonOption by
[@&#8203;woky](https://github.com/woky) in
[jessevdk/go-flags#393
- Upgrade by [@&#8203;jessevdk](https://github.com/jessevdk) in
[jessevdk/go-flags#406

#### New Contributors

- [@&#8203;sean-](https://github.com/sean-) made their first
contribution in
[jessevdk/go-flags#332
- [@&#8203;sv99](https://github.com/sv99) made their first
contribution in
[jessevdk/go-flags#342
- [@&#8203;dependabot](https://github.com/dependabot) made their first
contribution in
[jessevdk/go-flags#396
- [@&#8203;alexcb](https://github.com/alexcb) made their first
contribution in
[jessevdk/go-flags#367
- [@&#8203;anthonyfok](https://github.com/anthonyfok) made their first
contribution in
[jessevdk/go-flags#376
- [@&#8203;llrocha](https://github.com/llrocha) made their first
contribution in
[jessevdk/go-flags#390
- [@&#8203;anaprimawaty](https://github.com/anaprimawaty) made their
first contribution in
[jessevdk/go-flags#392
- [@&#8203;GRbit](https://github.com/GRbit) made their first
contribution in
[jessevdk/go-flags#404
- [@&#8203;cemremengu](https://github.com/cemremengu) made their first
contribution in
[jessevdk/go-flags#371
- [@&#8203;woky](https://github.com/woky) made their first
contribution in
[jessevdk/go-flags#393

**Full Changelog**:
jessevdk/go-flags@v1.5.0...v1.6.0

</details>

---

### Configuration

📅 **Schedule**: 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 becomes conflicted, 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 [Renovate
Bot](https://github.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MDIuMCIsInVwZGF0ZWRJblZlciI6IjM3LjQwMi4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->
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.

2 participants