mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 16:09:06 +00:00
## What
Moves the `ResponseError` class (`types/base.ts`) and the classified
error classes (`types/api-errors.ts`) into
`lib/errors/studio-errors.ts`, and renames `ResponseError` to
`StudioError`.
## Why
Studio's error classification is being expanded to cover errors that
don't come from API responses (thrown network failures, aborted
requests, unexpected client errors). The API-specific name and location
no longer fit. Landing the rename on its own keeps the follow-up PR,
which introduces the classified error model, small and reviewable.
## Notes for reviewers
- Mechanical change, no behavior change. Most of the diff is a one-line
import change per file plus import re-sorting by Prettier.
- Files that only use the type now use `import type { StudioError }`.
- `ResponseError` is no longer re-exported from `@/types`; there are no
compatibility shims at the old paths.
- Unrelated identifiers like `QueryResponseError` and
`parseResponseErrors` are unchanged.
125 lines
4.3 KiB
TypeScript
125 lines
4.3 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import { ErrorMatcher } from './ErrorMatcher'
|
|
import { ConnectionTimeoutError, StudioError } from '@/lib/errors/studio-errors'
|
|
|
|
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', () => {
|
|
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 StudioError (not a classified subclass)', () => {
|
|
render(
|
|
<ErrorMatcher
|
|
title="Failed to load tables"
|
|
error={new StudioError('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'
|
|
)
|
|
})
|
|
})
|