feat: add an error handling shortcut to a flow step's run settings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-11-17 21:45:54 +01:00
co-authored by Claude Opus 5.5
parent a2c04c2aa8
commit c1cf7f97cf
2 changed files with 58 additions and 1 deletions
@@ -33,8 +33,11 @@
import SettingGroup from '$lib/components/itemSettings/SettingGroup.svelte'
import WorkspaceScriptSettingInfo from './WorkspaceScriptSettingInfo.svelte'
import { slideDynamic } from '$lib/transitions'
import { GitBranch } from 'lucide-svelte'
import { addErrorBranch, canAddErrorBranch } from '../stepErrorBranch'
const { pathStore } = getContext<FlowEditorContext>('FlowEditorContext')
const flowEditorContext = getContext<FlowEditorContext>('FlowEditorContext')
const { pathStore } = flowEditorContext
interface Props {
flowModule: FlowModule
@@ -110,6 +113,10 @@
const s3Snippet = $derived(s3Language ? s3Scripts[s3Language][s3Kind] : undefined)
const concurrencyOn = $derived(hasInlineConcurrency(flowModule))
const concurrencyOff = $derived(!$enterpriseLicense || !concurrencyOn)
// Agent tools are not flow steps, and the preprocessor and error handler have no step after them.
const showAddErrorBranch = $derived(
!isAgentTool && !isFailure && canAddErrorBranch(flowEditorContext, flowModule.id)
)
// A resolved approval is recorded against the step the gate holds back, not this one, so
// `continue_on_error` never sees it — the suspend option is the only way to continue past it.
const suspendNeedsItsOwnContinueToggle = $derived(
@@ -164,6 +171,18 @@
"The flow continues to the next step even if this step fails (after exhausting retries, if any). The step's error becomes its return, so a following branch can handle it."
}}
/>
{#if showAddErrorBranch}
<Button
variant="default"
unifiedSize="sm"
wrapperClasses="self-start"
startIcon={{ icon: GitBranch }}
title="Turn on Continue on error and add a Branch to one after this step, with an On error branch"
onClick={() => addErrorBranch(flowEditorContext, flowModule.id)}
>
Add error handling
</Button>
{/if}
{#if suspendNeedsItsOwnContinueToggle}
<Alert type="info" title="Does not cover the approval" size="xs">
This only applies when the step's own code fails. A disapproval or an approval timeout
@@ -0,0 +1,38 @@
import type { FlowModule } from '$lib/gen'
import { push } from '$lib/history.svelte'
import { refreshStateStore } from '$lib/svelte5Utils.svelte'
import type { FlowEditorContext } from './types'
import { getModuleArrayContainer } from './flowTree'
import { insertNewModuleAtIndex } from './flowStateUtils.svelte'
/** Whether `stepId` sits in a step list a Branch to one can be inserted into after it. */
export function canAddErrorBranch(ctx: FlowEditorContext, stepId: string): boolean {
return getModuleArrayContainer(ctx.flowStore.val.value, stepId) != null
}
/** Turn on continue on error for `stepId` and insert a Branch to one right after it, whose one
* branch runs when the step failed and whose default runs otherwise. One undo entry. */
export async function addErrorBranch(
{ flowStore, flowStateStore, history, selectionManager }: FlowEditorContext,
stepId: string
): Promise<void> {
const container = getModuleArrayContainer(flowStore.val.value, stepId)
if (!container) return
push(history, flowStore.val)
container.modules[container.index].continue_on_error = true
const modules = (await insertNewModuleAtIndex(
flowStore,
flowStateStore,
container.modules,
container.index + 1,
'branchone'
)) as FlowModule[]
const inserted = modules[container.index + 1]
if (inserted.value.type === 'branchone') {
inserted.value.branches = [
{ summary: 'On error', expr: `!!results.${stepId}?.error`, modules: [] }
]
}
refreshStateStore(flowStore)
selectionManager.selectId(inserted.id)
}