Skip to content

fix(cli): fix potential panic in traceError if unwrapped err is nil #15166

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

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Oct 21, 2024

Seen while investigating #12721:

Root cause was a developer error, but this definitely shouldn't panic.

Before:

/ # coder stat
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x1f12eb0]

goroutine 1 [running]:
github.com/coder/coder/v2/cli.traceError({0x90e89a0?, 0x40007a8210})
        /home/runner/work/coder/coder/cli/root.go:1119 +0x70
github.com/coder/coder/v2/cli.cliHumanFormatError({0x40003065a0, 0x1c8}, {0x90e89a0, 0x40007a8210}, 0x40007a81e0?)
        /home/runner/work/coder/coder/cli/root.go:985 +0x190
github.com/coder/coder/v2/cli.cliHumanFormatError({0x40000d0f00, 0x139}, {0x90e89a0, 0x40007a81e0}, 0x40001c4480?)
        /home/runner/work/coder/coder/cli/root.go:985 +0x1d8
github.com/coder/coder/v2/cli.cliHumanFormatError({0x40000d0b40, 0xf}, {0x90e5f00, 0x40006a3a80}, 0x90e5d40?)
        /home/runner/work/coder/coder/cli/root.go:985 +0x1d8
github.com/coder/coder/v2/cli.cliHumanFormatError({0x0, 0x0}, {0x90e5ce0, 0x40003b14c0}, 0x2?)
        /home/runner/work/coder/coder/cli/root.go:985 +0x1d8
github.com/coder/coder/v2/cli.formatRunCommandError(0x40007a8108, 0x400079fce7)
        /home/runner/work/coder/coder/cli/root.go:1057 +0x30c
github.com/coder/coder/v2/cli.cliHumanFormatError({0x0, 0x0}, {0x90e5ec0, 0x40007a8108}, 0xaa0aed0?)
        /home/runner/work/coder/coder/cli/root.go:980 +0xe0
github.com/coder/coder/v2/cli.cliHumanFormatError({0x0, 0x0}, {0x90e5160, 0x40007a8120}, 0x90e50e0?)
        /home/runner/work/coder/coder/cli/root.go:966 +0x144
github.com/coder/coder/v2/cli.(*PrettyErrorFormatter).Format(0x400079fda0, {0x90e5160?, 0x40007a8120?})
        /home/runner/work/coder/coder/cli/root.go:927 +0x48
github.com/coder/coder/v2/cli.(*RootCmd).RunWithSubcommands(0x400068ed80, {0x400053a2c8, 0x30, 0x57})
        /home/runner/work/coder/coder/cli/root.go:175 +0x278
main.main()
        /home/runner/work/coder/coder/enterprise/cmd/coder/main.go:11 +0x40

After:

Encountered an error running "coder stat", see "coder stat --help" for more information
error: <nil>

@johnstcn johnstcn self-assigned this Oct 21, 2024
@johnstcn johnstcn marked this pull request as ready for review October 21, 2024 14:49
@johnstcn johnstcn requested a review from Emyrk October 21, 2024 14:49
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

Passing a (*Error)(nil) feels like a bug on the caller, but agreed this should not panic.

Playground example: https://go.dev/play/p/3jqgXvOcv2L

@johnstcn johnstcn merged commit 212aeff into main Oct 21, 2024
36 checks passed
@johnstcn johnstcn deleted the cj/panic-traceerror branch October 21, 2024 16:12
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants