Skip to content

Commit

Permalink
Ensure pipeline matcher regexp is not undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed Jun 20, 2024
1 parent bd79dee commit cc5e27b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions apps/interpreter/src/run-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import process from 'node:process';

import { type Logger } from '@jvalue/jayvee-execution';
import {
DefaultJayveeInterpreter,
ExitCode,
Expand All @@ -28,15 +29,9 @@ export async function runAction(
return process.exit(ExitCode.FAILURE);
}

let pipelineRegExp: RegExp | undefined;
try {
pipelineRegExp = new RegExp(options.pipeline);
} catch (e: unknown) {
logger.logErr(
`Invalid value "${options.pipeline}" for pipeline selection option: -p --pipeline.\n` +
'Must be a valid regular expression.',
);
return undefined;
const pipelineRegExp = parsePipelineMatcherRegExp(options.pipeline, logger);
if (pipelineRegExp === undefined) {
return process.exit(ExitCode.FAILURE);
}

const interpreter = new DefaultJayveeInterpreter({
Expand Down Expand Up @@ -71,3 +66,18 @@ async function runParseOnly(
const exitCode = model === undefined ? ExitCode.FAILURE : ExitCode.SUCCESS;
process.exit(exitCode);
}

function parsePipelineMatcherRegExp(
matcher: string,
logger: Logger,
): RegExp | undefined {
try {
return new RegExp(matcher);
} catch (e: unknown) {
logger.logErr(
`Invalid value "${matcher}" for pipeline selection option: -p --pipeline.\n` +
'Must be a valid regular expression.',
);
return undefined;
}
}

0 comments on commit cc5e27b

Please sign in to comment.