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

Detect when interface cast fails and return an error instead of panic. #4220

Merged
merged 3 commits into from
Feb 14, 2025

Conversation

timflyio
Copy link
Contributor

@timflyio timflyio commented Feb 13, 2025

Change Summary

What and Why: Fix a panic

% flyctl ext k8s save-kubeconfig fks-tim-newsham-fks-sake
Oops, something went wrong! Could you try that again?

interface conversion: interface {} is nil, not string
goroutine 1 [running]:
runtime/debug.Stack()
    runtime/debug/stack.go:26 +0x64
github.com/superfly/flyctl/internal/sentry.printError({0x104f91b20, 0x140006646f0})
    github.com/superfly/flyctl/internal/sentry/sentry.go:190 +0x168
github.com/superfly/flyctl/internal/sentry.Recover({0x104f91b20, 0x140006646f0})
    github.com/superfly/flyctl/internal/sentry/sentry.go:180 +0xb8
main.run.func1()
    github.com/superfly/flyctl/main.go:40 +0x34
panic({0x104f91b20?, 0x140006646f0?})
    runtime/panic.go:785 +0x124
github.com/superfly/flyctl/internal/command/extensions/kubernetes.runSaveKubeconfig({0x105322348, 0x1400054d410})
    github.com/superfly/flyctl/internal/command/extensions/kubernetes/kubeconfig.go:45 +0x2d8
github.com/superfly/flyctl/internal/command/extensions/kubernetes.saveKubeconfig.New.newRunE.func2(0x140006c8008, {0x1400005aa00?, 0x4?, 0x1047e1859?})
    github.com/superfly/flyctl/internal/command/command.go:140 +0x188

probably related to a failure provisioning the cluster:

% flyctl ext k8s create -o personal -n fks-sake
Fly Kubernetes is in beta, it is not recommended for critical production use cases. For help or feedback, email us at [email protected]
Some regions require a Launch plan or higher (bom).
See https://fly.io/plans to set up a plan.

? Choose the primary region (can't be changed later) [staff] Ashburn, Virginia (US) (qmx)
Error: failed to create etcd cluster - Failed to create volume: Status 500, Trace ID: b273d47d095c8504f7f14e76c573850d, Body: {"error"=>"internal: failed to get app: sql: no rows in result set"}

How: by detecting when an interface cast fails and returning an error instead of crashing.

Related to:


Documentation

  • Fresh Produce
  • In superfly/docs, or asked for help from docs team
  • n/a

@timflyio timflyio marked this pull request as ready for review February 13, 2025 01:57
kubeconfig := metadata["kubeconfig"].(string)
kubeconfig, ok := metadata["kubeconfig"].(string)
if !ok {
return fmt.Errorf("failed to fetch kubeconfig")
Copy link
Member

Choose a reason for hiding this comment

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

maybe we should add "provisioning your cluster may have failed" to it? only because the only way this would fail is if something got borked on our end and there's no real way to fix it by running it again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the error message and included a potential tip for fixing the situation (delete and reprovision).

Copy link
Member

@senyosimpson senyosimpson left a comment

Choose a reason for hiding this comment

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

one comment but not important, lgtm

@timflyio timflyio merged commit c1fc78b into master Feb 14, 2025
10 checks passed
@timflyio timflyio deleted the fix-kubeconfig-panic branch February 14, 2025 01:04
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