一键导入
flow-error-try-catch-removal
// Remove try-catch antipattern from step calls during Flow to Output SDK migration. Use when converting workflow code that wraps step calls in try-catch blocks.
// Remove try-catch antipattern from step calls during Flow to Output SDK migration. Use when converting workflow code that wraps step calls in try-catch blocks.
Validate and fix folder structure for Output SDK workflows. Use to ensure migrated workflows follow the correct structure conventions.
Convert Flow SDK activities.ts to Output SDK steps.ts. Use when migrating activity functions to step definitions with typed parameters.
Convert inline prompts and prompt arrays to .prompt files with YAML frontmatter. Use when migrating prompts from Flow SDK format to Output SDK prompt files.
Convert Flow SDK workflow class to Output SDK workflow() function. Use when migrating workflow.ts files from class-based to functional definitions.
Create scenario files for testing migrated Output SDK workflows. Use to set up test inputs in the scenarios/ subfolder.
Fix ESLint issues in migrated Output SDK code. Use when seeing lint errors after migration, or when writing new Output SDK code that needs to follow project conventions.
| name | flow-error-try-catch-removal |
| description | Remove try-catch antipattern from step calls during Flow to Output SDK migration. Use when converting workflow code that wraps step calls in try-catch blocks. |
| allowed-tools | ["Bash","Read","Write","Grep","Edit"] |
This skill helps identify and remove the try-catch antipattern that's common in Flow SDK code but incorrect in Output SDK. In Output SDK, step calls should NOT be wrapped in try-catch blocks - errors should propagate up the chain.
During Migration:
Code Patterns to Fix:
In Output SDK, the workflow execution engine handles errors automatically:
// WRONG: Wrapping step calls in try-catch
export default workflow( {
name: 'someWorkflow',
description: 'a workflow description',
inputSchema: WorkflowInputSchema,
outputSchema: WorkflowOutputSchema,
fn: async input => {
try {
// Step 1: Get User data
const userData = await getUserData( { userId: input.userId } );
// Step 2: Get role configuration
const roleConfig = await getRoleConfig( { role: userData.role } );
// Step 3: Ensure something
await ensureSomething( { config: roleConfig } );
return { success: true };
} catch ( error ) {
throw new FatalError( error instanceof Error ? error.message : 'Unknown workflow error' );
}
}
} );
// CORRECT: Let errors propagate naturally
export default workflow( {
name: 'someWorkflow',
description: 'a workflow description',
inputSchema: WorkflowInputSchema,
outputSchema: WorkflowOutputSchema,
fn: async input => {
// Step 1: Get User data
const userData = await getUserData( { userId: input.userId } );
// Step 2: Get role configuration
const roleConfig = await getRoleConfig( { role: userData.role } );
// Step 3: Ensure something
await ensureSomething( { config: roleConfig } );
return { success: true };
}
} );
Search for try-catch patterns in workflow files:
grep -r "try {" src/workflows/*/workflow.ts
grep -r "} catch" src/workflows/*/workflow.ts
Before removing, understand what the try-catch was doing:
Remove the try-catch wrapper but keep the step calls:
// Before
fn: async input => {
try {
const result = await someStep( input );
return result;
} catch ( error ) {
throw new FatalError( error.message );
}
}
// After
fn: async input => {
const result = await someStep( input );
return result;
}
Try-catch is still appropriate in specific cases:
Steps can use try-catch for internal logic:
export const fetchExternalData = step( {
name: 'fetchExternalData',
inputSchema: z.object( { url: z.string() } ),
fn: async ( input ) => {
try {
const response = await fetch( input.url );
return response.json();
} catch ( error ) {
// Transform to ValidationError for expected failures
throw new ValidationError( `Failed to fetch: ${input.url}` );
}
}
} );
When you need to handle a specific error type differently:
fn: async input => {
const userData = await getUserData( { userId: input.userId } );
try {
await sendNotification( { userId: userData.id } );
} catch ( error ) {
// Only catch specific expected errors
if ( error instanceof NotificationDisabledError ) {
// User has notifications disabled - continue without notification
console.log( 'Notifications disabled for user' );
} else {
throw error; // Re-throw unexpected errors
}
}
return { success: true };
}
When a failure shouldn't stop the workflow:
fn: async input => {
const result = await processData( input );
// Optional: try to cache result, but don't fail if caching fails
try {
await cacheResult( { key: input.id, value: result } );
} catch {
// Caching failed - log but continue
console.warn( 'Failed to cache result' );
}
return result;
}
import { FatalError } from '@flow/sdk';
import { getUserData, processUser, saveResults } from './activities';
export default class UserProcessingWorkflow {
async execute(input: WorkflowInput): Promise<WorkflowOutput> {
try {
const user = await getUserData(input.userId);
const processed = await processUser(user);
await saveResults(processed);
return { success: true, userId: user.id };
} catch (error) {
throw new FatalError(`Workflow failed: ${error.message}`);
}
}
}
import { workflow, z } from '@outputai/core';
import { getUserData, processUser, saveResults } from './steps.js';
import { WorkflowInputSchema, WorkflowOutputSchema } from './types.js';
export default workflow( {
name: 'userProcessing',
description: 'Process user data',
inputSchema: WorkflowInputSchema,
outputSchema: WorkflowOutputSchema,
fn: async input => {
const user = await getUserData( { userId: input.userId } );
const processed = await processUser( { user } );
await saveResults( { data: processed } );
return { success: true, userId: user.id };
}
} );
# Should return minimal results (only appropriate uses)
grep -A5 "try {" src/workflows/*/workflow.ts
npx output workflow run <workflowName> --input '{}'
Intentionally trigger an error to verify it propagates correctly.
flow-convert-workflow-definition - Full workflow conversionflow-convert-activities-to-steps - Step conversion patternsflow-validation-checklist - Complete migration validation