mirror of
https://github.com/supabase/supabase.git
synced 2026-09-08 19:08:44 +08:00
## Problem When the table editor showed a "Failed to load tables" or "Failed to load schemas" error (for example, when the underlying database or API gateway is unhealthy), there was no working way to restart the project from that error state. Restarting only worked by navigating to Project Settings. ## Fix "Failed to load tables" goes through the existing `ErrorMatcher` classification system, which only showed troubleshooting steps (including a restart action) for connection-timeout errors. Added an `ERROR_MAPPINGS` entry for the unclassified/generic API error case, reusing the existing `RestartDatabaseTroubleshootingSection` and `RestartProjectDialog` components already used for connection timeouts. "Failed to load schemas" (in the shared `SchemaSelector`, used across the table editor and several Database pages) only offered a retry. Added a "Restart database" button next to it, wired to the same `RestartProjectDialog`. ## How to test - In the table editor, trigger a table-load failure that isn't a connection timeout (any generic API error). The error card should now show a "Try restarting your project" step with a working restart action. - Open the schema selector while schemas fail to load (e.g. mock a 503 from the schemas query). A "Restart database" button should appear next to "Reload schemas" and open the restart confirmation dialog. - `apps/studio/components/interfaces/ErrorHandling/ErrorMatcher.test.tsx` and `apps/studio/components/ui/SchemaSelector.test.tsx` cover both cases. FE-4054 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added database restart guidance when schema loading fails. * Added options to reload schemas or restart the database, including a confirmation prompt. * Added troubleshooting guidance for unclassified table-loading errors. * **Bug Fixes** * Improved error handling by displaying relevant fallback guidance for unknown errors while preserving classified troubleshooting instructions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
128 lines
4.4 KiB
TypeScript
128 lines
4.4 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { ErrorMatcher } from './ErrorMatcher'
|
|
import { ConnectionTimeoutError } from '@/types/api-errors'
|
|
import { ResponseError } from '@/types/base'
|
|
|
|
vi.mock('@/lib/telemetry/track', () => ({ useTrack: () => vi.fn() }))
|
|
vi.mock('@/state/ai-assistant-state', () => ({
|
|
useAiAssistantStateSnapshot: () => ({ newChat: vi.fn() }),
|
|
}))
|
|
vi.mock('@/state/sidebar-manager-state', () => ({
|
|
useSidebarManagerSnapshot: () => ({ openSidebar: vi.fn() }),
|
|
}))
|
|
vi.mock('@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider', () => ({
|
|
SIDEBAR_KEYS: { AI_ASSISTANT: 'ai-assistant' },
|
|
}))
|
|
vi.mock('./RestartProjectDialog', () => ({
|
|
RestartProjectDialog: () => null,
|
|
}))
|
|
|
|
describe('ErrorMatcher', () => {
|
|
beforeEach(() => vi.clearAllMocks())
|
|
|
|
it('renders the provided title and error message', () => {
|
|
render(
|
|
<ErrorMatcher
|
|
title="Failed to load tables"
|
|
error="ERROR: FAILED TO RUN SQL QUERY: CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT."
|
|
supportFormParams={{}}
|
|
/>
|
|
)
|
|
expect(screen.getByText('Failed to load tables')).toBeInTheDocument()
|
|
expect(
|
|
screen.getByText(
|
|
'ERROR: FAILED TO RUN SQL QUERY: CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT.'
|
|
)
|
|
).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders troubleshooting steps for classified errors', () => {
|
|
const error = new ConnectionTimeoutError('CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT')
|
|
render(<ErrorMatcher title="Failed to load tables" error={error} supportFormParams={{}} />)
|
|
expect(screen.getByText('Try restarting your project')).toBeInTheDocument()
|
|
expect(screen.getByText('Try our troubleshooting guide')).toBeInTheDocument()
|
|
expect(screen.getByText('Debug with AI')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders fallback for plain ResponseError (not a classified subclass)', () => {
|
|
render(
|
|
<ErrorMatcher
|
|
title="Failed to load tables"
|
|
error={new ResponseError('CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT')}
|
|
supportFormParams={{}}
|
|
/>
|
|
)
|
|
expect(screen.getByText('Failed to load tables')).toBeInTheDocument()
|
|
expect(screen.queryByText('Try restarting your project')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('renders fallback with provided title for unmatched errors', () => {
|
|
render(
|
|
<ErrorMatcher title="Failed to load tables" error="UNKNOWN ERROR" supportFormParams={{}} />
|
|
)
|
|
expect(screen.getByText('Failed to load tables')).toBeInTheDocument()
|
|
expect(screen.getByText('UNKNOWN ERROR')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders the caller-provided fallback when the error is unclassified', () => {
|
|
render(
|
|
<ErrorMatcher
|
|
title="Failed to load tables"
|
|
error="UNKNOWN ERROR"
|
|
supportFormParams={{}}
|
|
fallback={<div>Custom fallback</div>}
|
|
/>
|
|
)
|
|
expect(screen.getByText('Custom fallback')).toBeInTheDocument()
|
|
})
|
|
|
|
it('ignores the caller-provided fallback when the error is classified', () => {
|
|
const error = new ConnectionTimeoutError('CONNECTION TERMINATED DUE TO CONNECTION TIMEOUT')
|
|
render(
|
|
<ErrorMatcher
|
|
title="Failed to load tables"
|
|
error={error}
|
|
supportFormParams={{}}
|
|
fallback={<div>Custom fallback</div>}
|
|
/>
|
|
)
|
|
expect(screen.queryByText('Custom fallback')).not.toBeInTheDocument()
|
|
expect(screen.getByText('Try restarting your project')).toBeInTheDocument()
|
|
})
|
|
|
|
it('accepts error as object with message property', () => {
|
|
render(
|
|
<ErrorMatcher
|
|
title="Failed to load tables"
|
|
error={{ message: 'UNKNOWN ERROR' }}
|
|
supportFormParams={{}}
|
|
/>
|
|
)
|
|
expect(screen.getByText('UNKNOWN ERROR')).toBeInTheDocument()
|
|
})
|
|
|
|
it('builds support link with projectRef param', () => {
|
|
render(
|
|
<ErrorMatcher
|
|
title="Failed to load tables"
|
|
error="UNKNOWN ERROR"
|
|
supportFormParams={{ projectRef: 'my-project' }}
|
|
/>
|
|
)
|
|
expect(screen.getByRole('link', { name: /contact support/i })).toHaveAttribute(
|
|
'href',
|
|
'/support/new?projectRef=my-project'
|
|
)
|
|
})
|
|
|
|
it('builds support link with no params when supportFormParams is omitted', () => {
|
|
render(<ErrorMatcher title="Failed to load tables" error="UNKNOWN ERROR" />)
|
|
expect(screen.getByRole('link', { name: /contact support/i })).toHaveAttribute(
|
|
'href',
|
|
'/support/new'
|
|
)
|
|
})
|
|
})
|