-
Notifications
You must be signed in to change notification settings - Fork 502
fix(start): suggest recovery for exec format and backup migration failures #5936
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package start | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "runtime" | ||
| "strings" | ||
|
|
||
| "github.com/supabase/cli/internal/utils" | ||
| ) | ||
|
|
||
| // SuggestFromUnhealthyLogs returns a CmdSuggestion for common local-stack | ||
| // startup failures seen after image upgrades or wrong-arch pulls | ||
| // (see https://github.com/supabase/supabase/issues/48224). | ||
| func SuggestFromUnhealthyLogs(logs string) string { | ||
| lower := strings.ToLower(logs) | ||
| var parts []string | ||
|
|
||
| if strings.Contains(lower, "exec format error") { | ||
| arch := runtime.GOARCH | ||
| parts = append(parts, fmt.Sprintf( | ||
| "A container failed with \"exec format error\" (wrong CPU architecture image).\n"+ | ||
| "Try removing the mismatched images and restarting for linux/%s:\n"+ | ||
| " %s\n"+ | ||
| " docker image prune -f\n"+ | ||
| " %s", | ||
| arch, | ||
| utils.Aqua("supabase stop --no-backup"), | ||
| utils.Aqua("supabase start"), | ||
| )) | ||
| } | ||
|
|
||
| if strings.Contains(lower, "migrations_name_key") || | ||
| (strings.Contains(lower, "migration failed") && strings.Contains(lower, "duplicate key")) { | ||
| parts = append(parts, fmt.Sprintf( | ||
| "Storage migrations failed against an existing database volume (often after upgrading images while restoring a backup).\n"+ | ||
| "Reset local data and start fresh:\n"+ | ||
| " %s\n"+ | ||
| " %s", | ||
| utils.Aqua("supabase stop --no-backup"), | ||
| utils.Aqua("supabase start"), | ||
| )) | ||
| } | ||
|
|
||
| if strings.Contains(lower, "err_invalid_package_config") || | ||
| strings.Contains(lower, "invalid package config") { | ||
| parts = append(parts, fmt.Sprintf( | ||
| "Studio image looks corrupted or incomplete. Remove it and re-pull:\n"+ | ||
| " %s\n"+ | ||
| " docker image rm -f $(docker images -q supabase/studio) 2>/dev/null\n"+ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Studio was pulled through the normal registry resolution path, the cached repository is usually Useful? React with 👍 / 👎. |
||
| " %s", | ||
| utils.Aqua("supabase stop --no-backup"), | ||
| utils.Aqua("supabase start"), | ||
| )) | ||
| } | ||
|
|
||
| return strings.Join(parts, "\n\n") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package start | ||
|
|
||
| import ( | ||
| "runtime" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSuggestFromUnhealthyLogs(t *testing.T) { | ||
| t.Run("suggests recovery for exec format error", func(t *testing.T) { | ||
| suggestion := SuggestFromUnhealthyLogs("exec /mailpit: exec format error\n") | ||
| require.NotEmpty(t, suggestion) | ||
| assert.Contains(t, suggestion, "exec format error") | ||
| assert.Contains(t, suggestion, "supabase stop --no-backup") | ||
| assert.Contains(t, suggestion, "supabase start") | ||
| assert.Contains(t, suggestion, "linux/"+runtime.GOARCH) | ||
| }) | ||
|
|
||
| t.Run("suggests recovery for storage migrations_name_key", func(t *testing.T) { | ||
| logs := `Migration failed. Reason: duplicate key value violates unique constraint "migrations_name_key"` | ||
| suggestion := SuggestFromUnhealthyLogs(logs) | ||
| require.NotEmpty(t, suggestion) | ||
| assert.Contains(t, suggestion, "Storage migrations failed") | ||
| assert.Contains(t, suggestion, "supabase stop --no-backup") | ||
| assert.Contains(t, suggestion, "supabase start") | ||
| }) | ||
|
|
||
| t.Run("suggests recovery for studio invalid package config", func(t *testing.T) { | ||
| logs := "Error: Invalid package config /app/apps/studio/node_modules/next/package.json.\n code: 'ERR_INVALID_PACKAGE_CONFIG'" | ||
| suggestion := SuggestFromUnhealthyLogs(logs) | ||
| require.NotEmpty(t, suggestion) | ||
| assert.Contains(t, suggestion, "Studio") | ||
| assert.Contains(t, suggestion, "supabase stop --no-backup") | ||
| assert.Contains(t, suggestion, "supabase start") | ||
| }) | ||
|
|
||
| t.Run("combines multiple failure suggestions", func(t *testing.T) { | ||
| logs := "exec /mailpit: exec format error\nmigrations_name_key\nERR_INVALID_PACKAGE_CONFIG" | ||
| suggestion := SuggestFromUnhealthyLogs(logs) | ||
| require.NotEmpty(t, suggestion) | ||
| assert.Contains(t, suggestion, "exec format error") | ||
| assert.Contains(t, suggestion, "Storage migrations failed") | ||
| assert.Contains(t, suggestion, "Studio") | ||
| }) | ||
|
|
||
| t.Run("returns empty for unrelated logs", func(t *testing.T) { | ||
| assert.Empty(t, SuggestFromUnhealthyLogs("listening on :5432\nready\n")) | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "log" | ||
| "os" | ||
| "regexp" | ||
| "runtime" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
@@ -289,6 +290,9 @@ func registryFromImage(imageTag string) string { | |
| func DockerImagePull(ctx context.Context, imageTag string, w io.Writer) error { | ||
| out, err := Docker.ImagePull(ctx, imageTag, image.PullOptions{ | ||
| RegistryAuth: GetRegistryAuthForImage(imageTag), | ||
| // Prefer the host architecture so services like mailpit do not start | ||
| // with a wrong-arch binary (exec format error). See supabase/supabase#48224. | ||
| Platform: "linux/" + runtime.GOARCH, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This platform pin only applies to Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the CLI talks to a Docker daemon with a different architecture from the CLI binary, such as a remote Useful? React with 👍 / 👎. |
||
| }) | ||
| if err != nil { | ||
| return errors.Errorf("failed to pull docker image: %w", err) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the cached wrong-architecture image case that produces
exec format error, this recovery command does not actually remove the bad image: Docker'simage prunedocs (https://docs.docker.com/reference/cli/docker/image/prune/) define the default as removing only dangling images unless-ais used, while the image Supabase just started is still tagged and will be reused byDockerResolveImageIfNotCachedon the nextsupabase start. Users who follow the suggestion can therefore hit the same health-check failure again; the hint needs to remove the relevant cached image tag(s) or force a repull.Useful? React with 👍 / 👎.