Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): stop showing a success toast when a source save fails (#113787)

Daniel RC6cfc98b208f7
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/dataWarehouseSourceSettingsLogic.test.ts b/products/data_warehouse/frontend/scenes/SourceScene/tabs/dataWarehouseSourceSettingsLogic.test.ts
index 9d2433cd309c..84a52e082b21 100644
--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/dataWarehouseSourceSettingsLogic.test.ts
+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/dataWarehouseSourceSettingsLogic.test.ts
@@ -287,6 +287,36 @@ describe('sourceSettingsLogic', () => {
])
})
+ it.each([
+ { outcome: 'accepted', rejected: false, successToasts: 1, formAction: 'submitSourceConfigSuccess' },
+ { outcome: 'rejected', rejected: true, successToasts: 0, formAction: 'submitSourceConfigFailure' },
+ ])('reports a save as $outcome', async ({ rejected, successToasts, formAction }) => {
+ silenceKeaLoadersErrors()
+ const source = makeSource([makeSchema()])
+ const updateSpy = jest.spyOn(api.externalDataSources, 'update')
+ if (rejected) {
+ updateSpy.mockRejectedValue(Object.assign(new Error('Connection timed out'), { status: 400 }))
+ } else {
+ updateSpy.mockResolvedValue(source)
+ }
+ const successToastSpy = jest.spyOn(lemonToast, 'success')
+
+ logic = sourceSettingsLogic({ id: 'source-1' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ logic.actions.setSourceConfigValue('description', 'edited description')
+
+ await expectLogic(logic, () => {
+ logic.actions.submitSourceConfig()
+ }).toDispatchActions([formAction])
+
+ expect(updateSpy).toHaveBeenCalledTimes(1)
+ expect(successToastSpy).toHaveBeenCalledTimes(successToasts)
+ // A rejected save must keep the edits so that the person can retry.
+ expect(logic.values.sourceConfig.description).toEqual('edited description')
+ })
+
it.each([
{ case: 'a warning toast', connection_warning: 'Source saved, but the connection check failed.', warnings: 1 },
{ case: 'the success toast', connection_warning: null, warnings: 0 },
diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts
index 0ab23f219207..c7787b78cb21 100644
--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts
+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/sourceSettingsLogic.ts
@@ -420,6 +420,7 @@ export interface sourceSettingsLogicValues {
sourceFieldConfig: SourceConfigResponseApi | null
sourceId: string
sourceLoading: boolean
+ sourceUpdateFailed: boolean
statusFilter: string | null
syncMethodFilter: string | null
syncingNow: boolean
@@ -428,6 +429,13 @@ export interface sourceSettingsLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface sourceSettingsLogicActions {
updateSource: (source: ExternalDataSource) => ExternalDataSource // sourcesDataLogic
+ updateSourceFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ } // sourcesDataLogic
bulkDeleteData: (schemas: ExternalDataSourceSchema[]) => {
schemas: ExternalDataSourceSchema[]
}
@@ -695,13 +703,15 @@ export type sourceSettingsLogicType = MakeLogicType<
sourceSettingsLogicMeta
>
+class SourceSaveRejectedError extends Error {}
+
export const sourceSettingsLogic = kea<sourceSettingsLogicType>([
path(['products', 'dataWarehouse', 'sourceSettingsLogic']),
props({} as SourceSettingsLogicProps),
key(({ id }) => id),
connect(() => ({
values: [availableSourcesLogic, ['availableSources']],
- actions: [sourcesDataLogic, ['updateSource']],
+ actions: [sourcesDataLogic, ['updateSource', 'updateSourceFailure']],
})),
actions({
setSourceId: (id: string) => ({ id }),
@@ -845,6 +855,13 @@ export const sourceSettingsLogic = kea<sourceSettingsLogicType>([
setSourceId: (_, { id }) => id,
},
],
+ sourceUpdateFailed: [
+ false as boolean,
+ {
+ updateSource: () => false,
+ updateSourceFailure: () => true,
+ },
+ ],
canLoadMoreJobs: [
true as boolean,
{
@@ -1144,6 +1161,11 @@ export const sourceSettingsLogic = kea<sourceSettingsLogicType>([
: values.source?.auto_sync_schema_patterns,
description: description !== '' ? description : (values.source?.description ?? null),
})
+ // The loader catches a rejected save and resolves anyway. Throw so that the
+ // form records a failed submit.
+ if (values.sourceUpdateFailed) {
+ throw new SourceSaveRejectedError()
+ }
actions.loadSource()
captureSaveOutcome('success')
const connectionWarning = sourcesDataLogic.values.lastUpdateConnectionWarning
@@ -1172,6 +1194,10 @@ export const sourceSettingsLogic = kea<sourceSettingsLogicType>([
})
} catch (e: any) {
captureSaveOutcome('rejected')
+ // The global loader failure handler has already shown the error.
+ if (e instanceof SourceSaveRejectedError) {
+ throw e
+ }
if (e.message) {
lemonToast.error(e.message)
} else {