Skip to content

Commit c76f86c

Browse files
authored
refactor: fail fast on invalid pipeline steps (#237)
1 parent 4cd0409 commit c76f86c

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

src/execution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import { type CliCommand, type InternalCliCommand, type Arg, Strategy, getRegistry, fullName } from './registry.js';
1313
import type { IPage } from './types.js';
14-
import { executePipeline } from './pipeline.js';
14+
import { executePipeline } from './pipeline/index.js';
1515
import { AdapterLoadError } from './errors.js';
1616
import { shouldUseBrowserSession } from './capabilityRouting.js';
1717
import { getBrowserFactory, browserSession, runWithTimeout, DEFAULT_BROWSER_COMMAND_TIMEOUT } from './runtime.js';

src/pipeline.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/pipeline/executor.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import { describe, it, expect, vi } from 'vitest';
66
import { executePipeline } from './index.js';
7+
import { ConfigError } from '../errors.js';
78
import type { IPage } from '../types.js';
89

910
/** Create a minimal mock page for testing */
@@ -148,13 +149,13 @@ describe('executePipeline', () => {
148149
expect(page.wait).toHaveBeenCalledWith(2);
149150
});
150151

151-
it('handles unknown steps gracefully in debug mode', async () => {
152-
const stderr = vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
153-
await executePipeline(null, [
152+
it('fails fast on unknown steps', async () => {
153+
await expect(executePipeline(null, [
154154
{ unknownStep: 'test' },
155-
], { debug: true });
156-
expect(stderr).toHaveBeenCalledWith(expect.stringContaining('Unknown step'));
157-
stderr.mockRestore();
155+
], { debug: true })).rejects.toBeInstanceOf(ConfigError);
156+
await expect(executePipeline(null, [
157+
{ unknownStep: 'test' },
158+
], { debug: true })).rejects.toThrow('Unknown pipeline step "unknownStep"');
158159
});
159160

160161
it('passes args through template rendering', async () => {

src/pipeline/executor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import chalk from 'chalk';
66
import type { IPage } from '../types.js';
77
import { getStep, type StepHandler } from './registry.js';
88
import { log } from '../logger.js';
9+
import { ConfigError } from '../errors.js';
910

1011
export interface PipelineContext {
1112
args?: Record<string, unknown>;
@@ -32,7 +33,10 @@ export async function executePipeline(
3233
if (handler) {
3334
data = await handler(page, params, data, args);
3435
} else {
35-
if (debug) log.warn(`Unknown step: ${op}`);
36+
throw new ConfigError(
37+
`Unknown pipeline step "${op}" at index ${i}.`,
38+
'Check the YAML pipeline step name or register the custom step before execution.',
39+
);
3640
}
3741

3842
if (debug) debugStepResult(op, data);

0 commit comments

Comments
 (0)