Skip to content

Commit

Permalink
Add experimental_ to onTaskError
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Sep 6, 2023
1 parent fd6f283 commit 7ac94c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions node-src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,17 @@ it('fails on missing project token', async () => {
});

// Note this tests options errors, but not fatal task or runtime errors.
it('passes options error to onTaskError', async () => {
it('passes options error to experimental_onTaskError', async () => {
const ctx = getContext([]);
ctx.options = {
onTaskError: jest.fn(),
experimental_onTaskError: jest.fn(),
} as any;

ctx.options.onTaskError = jest.fn();
ctx.options.experimental_onTaskError = jest.fn();
ctx.env.CHROMATIC_PROJECT_TOKEN = '';
await runBuild(ctx);

await expect(ctx.options.onTaskError).toHaveBeenCalledWith(
await expect(ctx.options.experimental_onTaskError).toHaveBeenCalledWith(
expect.anything(), // Context
expect.objectContaining({
formattedError: expect.stringContaining('Missing project token'), // Long formatted error fatalError https://github.com/chromaui/chromatic-cli/blob/217e77671179748eb4ddb8becde78444db93d067/node-src/ui/messages/errors/fatalError.ts#L11
Expand Down
7 changes: 5 additions & 2 deletions node-src/runBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export async function runBuild(ctx: Context, extraOptions?: Partial<Options>) {
} catch (e) {
ctx.log.info('');
ctx.log.error(fatalError(ctx, [e]));
ctx.options.onTaskError?.(ctx, { formattedError: fatalError(ctx, [e]), originalError: e });
ctx.options.experimental_onTaskError?.(ctx, {
formattedError: fatalError(ctx, [e]),
originalError: e,
});
setExitCode(ctx, exitCodes.INVALID_OPTIONS, true);
return;
}
Expand Down Expand Up @@ -72,7 +75,7 @@ export async function runBuild(ctx: Context, extraOptions?: Partial<Options>) {
}
} catch (error) {
const errors = [].concat(error); // GraphQLClient might throw an array of errors
ctx.options.onTaskError?.(ctx, {
ctx.options.experimental_onTaskError?.(ctx, {
formattedError: fatalError(ctx, errors),
originalError: error,
});
Expand Down
2 changes: 1 addition & 1 deletion node-src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface Options {
experimental_onTaskStart?: (ctx: Context) => void;

/** A callback that is called if a task fails */
onTaskError?: (
experimental_onTaskError?: (
ctx: Context,
{ formattedError, originalError }: { formattedError: string; originalError: Error | Error[] }
) => void;
Expand Down

0 comments on commit 7ac94c2

Please sign in to comment.