Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

ref(etl): Improve error message handling (#45713)

Riccardo Busetti8255a63a868c
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.tsx
index d23e5cec4a6..6f8f5c05891 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/NewPublicationPanel.tsx
@@ -33,12 +33,18 @@ interface NewPublicationPanelProps {
export const NewPublicationPanel = ({ visible, sourceId, onClose }: NewPublicationPanelProps) => {
const { ref: projectRef } = useParams()
const { data: project } = useSelectedProjectQuery()
- const { mutateAsync: createPublication, isPending: creatingPublication } =
- useCreatePublicationMutation()
- const { data: tables } = useReplicationTablesQuery({
- projectRef,
- sourceId,
- })
+
+ const { data: tables } = useReplicationTablesQuery({ projectRef, sourceId })
+
+ const { mutate: createPublication, isPending: creatingPublication } =
+ useCreatePublicationMutation({
+ onSuccess: () => {
+ toast.success('Successfully created publication')
+ form.reset(defaultValues)
+ onClose()
+ },
+ })
+
const formId = 'publication-editor'
const FormSchema = z.object({
name: z.string().min(1, 'Name is required'),
@@ -59,23 +65,19 @@ export const NewPublicationPanel = ({ visible, sourceId, onClose }: NewPublicati
if (!projectRef) return console.error('Project ref is required')
if (!project) return console.error('Project is required')
if (!sourceId) return console.error('Source id is required')
- try {
- await createPublication({
- projectRef,
- sourceId,
- name: data.name,
- tables: data.tables.map((table) => {
- const [schema, name] = table.split('.')
- return { schema, name }
- }),
- connectionString: project.connectionString,
- })
- toast.success('Successfully created publication')
- onClose()
- } catch (error) {
- toast.error('Failed to create publication')
- }
- form.reset(defaultValues)
+
+ const tables = data.tables.map((table) => {
+ const [schema, name] = table.split('.')
+ return { schema, name }
+ })
+
+ createPublication({
+ projectRef,
+ sourceId,
+ name: data.name,
+ tables,
+ connectionString: project.connectionString,
+ })
}
return (
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/index.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/index.tsx
index 63bae60250a..e9997898784 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/index.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationPanel/DestinationForm/index.tsx
@@ -56,6 +56,7 @@ import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
} from '@/state/replication-pipeline-request-status'
+import { type ResponseError } from '@/types'
const formId = 'destination-editor'
@@ -368,8 +369,11 @@ export const DestinationForm = ({
const hasRequestError = results.some((r) => r.status === 'rejected')
if (hasRequestError) {
- // If any request failed, show a generic error and stop
- toast.error('Failed to validate configuration. Please try again.')
+ // If any request failed, surface the upstream message so users see why
+ const rejected = results.find((r): r is PromiseRejectedResult => r.status === 'rejected')
+ const reason =
+ rejected?.reason instanceof Error ? rejected.reason.message : 'Please try again.'
+ toast.error(`Failed to validate configuration: ${reason}`)
setHasRunValidation(false)
return false
}
@@ -481,7 +485,7 @@ export const DestinationForm = ({
}
} catch (error) {
const action = editMode ? 'apply and run' : 'create and start'
- toast.error(`Failed to ${action} destination`)
+ toast.error(`Failed to ${action} destination: ${(error as ResponseError).message}`)
}
}
diff --git a/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx b/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
index 7862020cac6..59ca3701744 100644
--- a/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/DestinationRow.tsx
@@ -16,7 +16,6 @@ import {
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { DeleteDestination } from './DeleteDestination'
-import { PIPELINE_ERROR_MESSAGES } from './Pipeline.utils'
import { PipelineStatus } from './PipelineStatus'
import { PipelineStatusName, STATUS_REFRESH_FREQUENCY_MS } from './Replication.constants'
import { RowMenu } from './RowMenu'
@@ -32,6 +31,7 @@ import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
} from '@/state/replication-pipeline-request-status'
+import { type ResponseError } from '@/types'
interface DestinationRowProps {
destinationId: number
@@ -99,7 +99,7 @@ export const DestinationRow = ({ destinationId }: DestinationRowProps) => {
return console.error('Project ref is required')
}
if (!pipeline) {
- return toast.error(PIPELINE_ERROR_MESSAGES.NO_PIPELINE_FOUND)
+ return toast.error('No pipeline found')
}
try {
@@ -114,7 +114,7 @@ export const DestinationRow = ({ destinationId }: DestinationRowProps) => {
setShowDeleteDestinationForm(false)
toast.success(`Deleted destination "${destinationName}"`)
} catch (error) {
- toast.error(PIPELINE_ERROR_MESSAGES.DELETE_DESTINATION)
+ toast.error(`Failed to delete destination: ${(error as ResponseError).message}`)
} finally {
setIsDeleting(false)
}
@@ -129,7 +129,7 @@ export const DestinationRow = ({ destinationId }: DestinationRowProps) => {
return (
<>
{isPipelineError && (
- <AlertError error={pipelineError} subject={PIPELINE_ERROR_MESSAGES.RETRIEVE_PIPELINE} />
+ <AlertError error={pipelineError} subject="Failed to retrieve pipeline information" />
)}
{isPipelineSuccess && (
<TableRow>
diff --git a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
index 449a36c43ee..d588b953537 100644
--- a/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/Destinations.tsx
@@ -27,7 +27,6 @@ import { DestinationPanel } from './DestinationPanel/DestinationPanel'
import { DestinationType } from './DestinationPanel/DestinationPanel.types'
import { DestinationRow } from './DestinationRow'
import { DisableExternalReplicationDialog } from './DisableExternalReplicationDialog'
-import { PIPELINE_ERROR_MESSAGES } from './Pipeline.utils'
import { ReadReplicaRow } from './ReadReplicas/ReadReplicaRow'
import {
useIsETLBigQueryPrivateAlpha,
@@ -262,7 +261,7 @@ export const Destinations = () => {
{hasErrorsFetchingData && (
<AlertError
error={destinationsError || databasesError}
- subject={PIPELINE_ERROR_MESSAGES.RETRIEVE_DESTINATIONS}
+ subject="Failed to retrieve destinations"
/>
)}
diff --git a/apps/studio/components/interfaces/Database/Replication/Pipeline.utils.ts b/apps/studio/components/interfaces/Database/Replication/Pipeline.utils.ts
index 387e6a88509..9064e4fd2f1 100644
--- a/apps/studio/components/interfaces/Database/Replication/Pipeline.utils.ts
+++ b/apps/studio/components/interfaces/Database/Replication/Pipeline.utils.ts
@@ -2,18 +2,6 @@ import { PipelineStatusName } from './Replication.constants'
import { ReplicationPipelineStatusData } from '@/data/replication/pipeline-status-query'
import { PipelineStatusRequestStatus } from '@/state/replication-pipeline-request-status'
-export const PIPELINE_ERROR_MESSAGES = {
- RETRIEVE_PIPELINE: 'Failed to retrieve pipeline information',
- RETRIEVE_PIPELINE_STATUS: 'Failed to retrieve pipeline status',
- RETRIEVE_REPLICATION_STATUS: 'Failed to retrieve table replication status',
- RETRIEVE_DESTINATIONS: 'Failed to retrieve destinations',
- ENABLE_DESTINATION: 'Failed to enable destination',
- DISABLE_DESTINATION: 'Failed to disable destination',
- DELETE_DESTINATION: 'Failed to delete destination',
- NO_PIPELINE_FOUND: 'No pipeline found',
- COPY_TABLE_STATUS: 'Failed to copy table status',
-} as const
-
export const getStatusName = (
status: ReplicationPipelineStatusData['status'] | undefined
): PipelineStatusName | undefined => {
diff --git a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
index caa5c9777bf..915389d6033 100644
--- a/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/ReplicationPipelineStatus/ReplicationPipelineStatus.tsx
@@ -39,7 +39,6 @@ import {
getPipelineDisplayState,
getStatusName,
PIPELINE_ACTIONABLE_STATES,
- PIPELINE_ERROR_MESSAGES,
} from '../Pipeline.utils'
import { PipelineStatus } from '../PipelineStatus'
import { PipelineStatusName, STATUS_REFRESH_FREQUENCY_MS } from '../Replication.constants'
@@ -62,6 +61,7 @@ import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
} from '@/state/replication-pipeline-request-status'
+import { type ResponseError } from '@/types'
/**
* Component for displaying replication pipeline status and table replication details.
@@ -232,8 +232,14 @@ export const ReplicationPipelineStatus = () => {
const onPrimaryAction = async () => {
if (!projectRef) return console.error('Project ref is required')
- if (!pipeline) return toast.error(PIPELINE_ERROR_MESSAGES.NO_PIPELINE_FOUND)
-
+ if (!pipeline) return toast.error('No pipeline found')
+
+ const action =
+ statusName === PipelineStatusName.STOPPED
+ ? 'start'
+ : statusName === PipelineStatusName.STARTED
+ ? 'stop'
+ : 'restart'
try {
if (statusName === PipelineStatusName.STOPPED) {
setRequestStatus(pipeline.id, PipelineStatusRequestStatus.StartRequested, statusName)
@@ -247,7 +253,7 @@ export const ReplicationPipelineStatus = () => {
}
} catch (error) {
setRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
- toast.error(PIPELINE_ERROR_MESSAGES.ENABLE_DESTINATION)
+ toast.error(`Failed to ${action} pipeline: ${(error as ResponseError).message}`)
}
}
@@ -315,7 +321,7 @@ export const ReplicationPipelineStatus = () => {
</div>
</div>
{isPipelineError && (
- <AlertError error={pipelineError} subject={PIPELINE_ERROR_MESSAGES.RETRIEVE_PIPELINE} />
+ <AlertError error={pipelineError} subject="Failed to retrieve pipeline information" />
)}
{isStatusError && (
diff --git a/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx b/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
index f2a9115e6f8..6360b277b79 100644
--- a/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/RowMenu.tsx
@@ -16,7 +16,6 @@ import {
getStatusName,
PIPELINE_DISABLE_ALLOWED_FROM,
PIPELINE_ENABLE_ALLOWED_FROM,
- PIPELINE_ERROR_MESSAGES,
} from './Pipeline.utils'
import { PipelineStatusName } from './Replication.constants'
import AlertError from '@/components/ui/AlertError'
@@ -88,46 +87,46 @@ export const RowMenu = ({
const onEnablePipeline = async () => {
if (!projectRef) return console.error('Project ref is required')
- if (!pipeline) return toast.error(PIPELINE_ERROR_MESSAGES.NO_PIPELINE_FOUND)
+ if (!pipeline) return toast.error('No pipeline found')
try {
// Only show 'enabling' when transitioning from allowed states
- if (PIPELINE_ENABLE_ALLOWED_FROM.includes(statusName as any)) {
+ if (PIPELINE_ENABLE_ALLOWED_FROM.includes(statusName as PipelineStatusName)) {
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.StartRequested, statusName)
}
await startPipeline({ projectRef, pipelineId: pipeline.id })
} catch (error) {
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
- toast.error(PIPELINE_ERROR_MESSAGES.ENABLE_DESTINATION)
+ toast.error(`Failed to start pipeline: ${(error as ResponseError).message}`)
}
}
const onDisablePipeline = async () => {
if (!projectRef) return console.error('Project ref is required')
- if (!pipeline) return toast.error(PIPELINE_ERROR_MESSAGES.NO_PIPELINE_FOUND)
+ if (!pipeline) return toast.error('No pipeline found')
try {
// Only show 'disabling' when transitioning from allowed states
- if (PIPELINE_DISABLE_ALLOWED_FROM.includes(statusName as any)) {
+ if (PIPELINE_DISABLE_ALLOWED_FROM.includes(statusName as PipelineStatusName)) {
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.StopRequested, statusName)
}
await stopPipeline({ projectRef, pipelineId: pipeline.id })
} catch (error) {
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
- toast.error(PIPELINE_ERROR_MESSAGES.DISABLE_DESTINATION)
+ toast.error(`Failed to stop pipeline: ${(error as ResponseError).message}`)
}
}
const onRestartPipeline = async () => {
if (!projectRef) return console.error('Project ref is required')
- if (!pipeline) return toast.error(PIPELINE_ERROR_MESSAGES.NO_PIPELINE_FOUND)
+ if (!pipeline) return toast.error('No pipeline found')
try {
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.RestartRequested, statusName)
await restartPipeline({ projectRef, pipelineId: pipeline.id })
} catch (error) {
setGlobalRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
- toast.error(PIPELINE_ERROR_MESSAGES.ENABLE_DESTINATION)
+ toast.error(`Failed to restart pipeline: ${(error as ResponseError).message}`)
}
}
@@ -135,9 +134,7 @@ export const RowMenu = ({
<div className="flex justify-end items-center space-x-2">
{isLoading && <ShimmeringLoader />}
- {isError && (
- <AlertError error={error} subject={PIPELINE_ERROR_MESSAGES.RETRIEVE_PIPELINE_STATUS} />
- )}
+ {isError && <AlertError error={error} subject="Failed to retrieve pipeline status" />}
<DropdownMenu>
<DropdownMenuTrigger asChild>
diff --git a/apps/studio/components/interfaces/Database/Replication/UpdateVersionModal.tsx b/apps/studio/components/interfaces/Database/Replication/UpdateVersionModal.tsx
index 62fccf8478a..7f45fd1c002 100644
--- a/apps/studio/components/interfaces/Database/Replication/UpdateVersionModal.tsx
+++ b/apps/studio/components/interfaces/Database/Replication/UpdateVersionModal.tsx
@@ -20,6 +20,7 @@ import {
PipelineStatusRequestStatus,
usePipelineRequestStatus,
} from '@/state/replication-pipeline-request-status'
+import { type ResponseError } from '@/types'
interface UpdateVersionModalProps {
visible: boolean
@@ -65,9 +66,9 @@ export const UpdateVersionModal = ({
// Step 1: Update to the new version
try {
await updatePipelineVersion({ projectRef, pipelineId: pipeline.id, versionId })
- } catch (e: any) {
+ } catch (e) {
// 404: default changed; version cache will refresh via mutation onError. Keep dialog open.
- if (e?.code === 404) return
+ if ((e as ResponseError)?.code === 404) return
// Other errors are already toasted by the mutation; do not double-toast here.
return
}
@@ -80,10 +81,10 @@ export const UpdateVersionModal = ({
try {
await restartPipeline({ projectRef, pipelineId: pipeline.id })
toast.success('Pipeline successfully updated and is currently restarting')
- } catch (e: any) {
+ } catch (e) {
// Clear optimistic state and surface a single concise error
setRequestStatus(pipeline.id, PipelineStatusRequestStatus.None)
- toast.error('Failed to restart pipeline')
+ toast.error(`Failed to restart pipeline: ${(e as ResponseError).message}`)
}
} else {
toast.success('Pipeline successfully updated')