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

[BUGFIX] cli: Improve error message for 'k3d get-kubeconfig' #22

Merged
merged 1 commit into from
May 3, 2019

Conversation

andyz-dev
Copy link
Contributor

Before this change, command:
$ k3d create -name test
$ k3d get-kubeconfig

Produces the following error message:

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/rancher/k3d/cli.GetKubeConfig(0xc00031a160, 0x0, 0x0)
	/Users/azhou/projs/k3d/cli/commands.go:335 +0x105d
github.com/urfave/cli.HandleAction(0x13e7ca0, 0x148f0b0, 0xc00031a160, 0xc000304000, 0x0)
	/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/app.go:490 +0xc8
github.com/urfave/cli.Command.Run(0x1477cb5, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1480cd8, 0x23, 0x0, ...)
	/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/command.go:210 +0x996
github.com/urfave/cli.(*App).Run(0xc0000bc1a0, 0xc00000e060, 0x2, 0x2, 0x0, 0x0)
	/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/app.go:255 +0x6af
main.main()
	/Users/azhou/projs/k3d/main.go:185 +0x11e0

This patch improve the error message by avoid the panic. Now the output
becomes:

019/05/02 12:05:30 No server container for cluster k3s_default

Before this change, command:
 $ k3d create -name test
 $ k3d get-kubeconfig

Produces the following error message:

	panic: runtime error: index out of range

	goroutine 1 [running]:
	github.com/rancher/k3d/cli.GetKubeConfig(0xc00031a160, 0x0, 0x0)
		/Users/azhou/projs/k3d/cli/commands.go:335 +0x105d
	github.com/urfave/cli.HandleAction(0x13e7ca0, 0x148f0b0, 0xc00031a160, 0xc000304000, 0x0)
		/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/app.go:490 +0xc8
	github.com/urfave/cli.Command.Run(0x1477cb5, 0xe, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1480cd8, 0x23, 0x0, ...)
		/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/command.go:210 +0x996
	github.com/urfave/cli.(*App).Run(0xc0000bc1a0, 0xc00000e060, 0x2, 0x2, 0x0, 0x0)
		/Users/azhou/projs/rcloud/pkg/mod/github.com/urfave/cli@v1.20.0/app.go:255 +0x6af
	main.main()
		/Users/azhou/projs/k3d/main.go:185 +0x11e0

This patch improve the error message by avoid the panic. Now the output
becomes:

	019/05/02 12:05:30 No server container for cluster k3s_default
@cloudnautique
Copy link

Same fix as #21

@andyz-dev
Copy link
Contributor Author

Same fix as #21

Well, it is the same bug, but slightly different fix. IMHO, #22 produces cleaner error message.

For the same test cases mentioned in the commit message, #21 would have produced:

2019/05/02 15:16:26 Couldn't get server container for cluster: k3s_default

Notice the extra added to the output.

In case k3d maintainer choose to merge this pull request, I'd like to request that we acknowledge the effort of #21 that identified the same underlining issue, and roll it into the commit message.

@iwilltry42 iwilltry42 changed the title cli: Improve error message for 'k3d get-kubeconfig' [BUGFIX] cli: Improve error message for 'k3d get-kubeconfig' May 3, 2019
@iwilltry42 iwilltry42 merged commit 2267924 into k3d-io:master May 3, 2019
@iwilltry42
Copy link
Member

Thank you for this :) Seems like I missed that one

@andyz-dev andyz-dev deleted the imporve-error-message branch May 3, 2019 06:49
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.

3 participants