Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tevanoff committed Mar 6, 2024
1 parent f2d04f7 commit 9f0d8b2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions node-src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ export const setBuildCommand = async (ctx: Context) => {
const timeoutAfter = (ms) =>
new Promise((resolve, reject) => setTimeout(reject, ms, new Error(`Operation timed out`)));

function isE2EBuildCommandNotFoundError(err) {
function isE2EBuildCommandNotFoundError(errorMessage: string) {
// It's hard to know if this is the case as each package manager has a different type of
// error for this, but we'll try to figure it out.
const msg = err.message as string;
const errorRegexes = ['command not found', `[\\W]?${e2eBuildBinName}[\\W]? not found`, 'code E404', 'exit code 127', `command failed.*${e2eBuildBinName}.*$`];
return errorRegexes.some((regex) => msg.match(new RegExp(regex, 'gi')));
return errorRegexes.some((regex) => errorMessage.match(new RegExp(regex, 'gi')));

Check warning on line 68 in node-src/tasks/build.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

node-src/tasks/build.ts#L68

RegExp() called with a `regex` function argument, this might allow an attacker to cause a Regular Expression Denial-of-Service (ReDoS) within your application as RegExP blocks the main thread.

Check warning on line 68 in node-src/tasks/build.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

node-src/tasks/build.ts#L68

The `RegExp` constructor was called with a non-literal value.
}

function e2eBuildErrorMessage(err, workingDir, ctx: Context): { exitCode: number, message: string } {
function e2eBuildErrorMessage(err, workingDir: string, ctx: Context): { exitCode: number, message: string } {
const flag = ctx.options.playwright ? 'playwright' : 'cypress';
const errorMessage = err.message;

// If we tried to run the E2E package's bin directly (due to being in the action)
// 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 (isE2EBuildCommandNotFoundError(err)) {
if (isE2EBuildCommandNotFoundError(errorMessage)) {
const dependencyName = `@chromatic-com/${flag}`;
return {
exitCode: exitCodes.MISSING_DEPENDENCY,
Expand All @@ -85,7 +85,7 @@ function e2eBuildErrorMessage(err, workingDir, ctx: Context): { exitCode: number

return {
exitCode: exitCodes.E2E_BUILD_FAILED,
message: e2eBuildFailed({ flag, errorMessage: err.message }),
message: e2eBuildFailed({ flag, errorMessage }),
};
}

Expand Down

0 comments on commit 9f0d8b2

Please sign in to comment.