Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/worker/client/routes/connect-secret-errors.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect, test } from 'vitest'
import { formatConnectorConfigFailureMessage } from './connect-secret-errors.ts'

test('reports rollback when secret rollback completed', () => {
const message = formatConnectorConfigFailureMessage(
new Error('Config update exploded.'),
{ secretRolledBack: true },
)

expect(message).toBe(
'Connector configuration failed and the secret was rolled back. Config update exploded.',
)
})

test('does not claim rollback when no connector rollback ran', () => {
const message = formatConnectorConfigFailureMessage(
new Error('Config update exploded.'),
{ secretRolledBack: false },
)

expect(message).toBe(
'Connector configuration failed after the secret was saved. Config update exploded.',
)
})

test('reports updated secret retained when connector config fails on existing secret', () => {
const message = formatConnectorConfigFailureMessage(
new Error('Config update exploded.'),
{ secretRolledBack: false, updatedSecretRetained: true },
)

expect(message).toBe(
'Connector configuration failed after the secret was updated. Config update exploded.',
)
})
18 changes: 18 additions & 0 deletions packages/worker/client/routes/connect-secret-errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function formatConnectorConfigFailureMessage(
error: unknown,
options: {
secretRolledBack: boolean
updatedSecretRetained?: boolean
},
) {
const message =
error instanceof Error
? error.message
: 'Unable to update connector config.'
if (options.updatedSecretRetained) {
return `Connector configuration failed after the secret was updated. ${message}`
}
return options.secretRolledBack
? `Connector configuration failed and the secret was rolled back. ${message}`
: `Connector configuration failed after the secret was saved. ${message}`
}
Loading
Loading