Skip to content

Commit

Permalink
handle all E2E build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tevanoff committed Mar 6, 2024
1 parent 957579e commit acd31f4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion node-src/lib/setExitCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export const exitCodes = {
STORYBOOK_START_FAILED: 22,
STORYBOOK_BROKEN: 23,

// E2E errors
E2E_BUILD_FAILED: 51,

// Subprocess errors
GIT_NOT_CLEAN: 101,
GIT_OUT_OF_DATE: 102,
GIT_NO_MERGE_BASE: 103,
NPM_INSTALL_FAILED: 104,
NPM_BUILD_STORYBOOK_FAILED: 105,
COMMAND_NOT_FOUND: 127,

// I/O errors
FETCH_ERROR: 201,
Expand Down
13 changes: 5 additions & 8 deletions node-src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import buildFailed from '../ui/messages/errors/buildFailed';
import { failed, initial, pending, skipped, success } from '../ui/tasks/build';
import { getPackageManagerRunCommand } from '../lib/getPackageManager';
import { buildBinName as e2EbuildBinName, getE2eBuildCommand } from '../lib/getE2eBuildCommand';
import missingDependency from '../ui/messages/errors/missingDependency';
import e2eBuildFailed from '../ui/messages/errors/e2eBuildFailed';

export const setSourceDir = async (ctx: Context) => {
if (ctx.options.outputDir) {
Expand Down Expand Up @@ -87,15 +87,12 @@ export const buildStorybook = async (ctx: Context) => {
// and it failed, that means we couldn't find it. This probably means they haven't
// installed the right dependency or run from the right directory
if (
ctx.options.inAction &&
(ctx.options.playwright || ctx.options.cypress) &&
e.message.match(e2EbuildBinName)
e.message.match(e2EbuildBinName) &&
(ctx.options.playwright || ctx.options.cypress)
) {
const flag = ctx.options.playwright ? 'playwright' : 'cypress';
const dependencyName = `@chromatic-com/${flag}`;
ctx.log.error(missingDependency({ dependencyName, flag, workingDir: process.cwd() }));
ctx.log.debug(e);
setExitCode(ctx, exitCodes.MISSING_DEPENDENCY, true);
ctx.log.error(e2eBuildFailed({ flag, errorMessage: e.message }));
setExitCode(ctx, exitCodes.E2E_BUILD_FAILED, true);
throw new Error(failed(ctx).output);
}

Expand Down
17 changes: 17 additions & 0 deletions node-src/ui/messages/errors/e2eBuildFailed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import chalk from 'chalk';
import { dedent } from 'ts-dedent';
import { error } from '../../components/icons';

export default ({
flag,
errorMessage,
}: {
flag: string;
errorMessage: string;
}) => {
return dedent(chalk`
${error} Failed to run \`chromatic --${flag}\`:
${errorMessage}
`);
};

0 comments on commit acd31f4

Please sign in to comment.