Skip to content

Commit

Permalink
Merge pull request #133 from rmoff/97-catch-runtime-errors
Browse files Browse the repository at this point in the history
#97: Catch Vale runtime errors properly
  • Loading branch information
jdkato authored Oct 9, 2024
2 parents 91ac403 + 301ad93 commit f49b46c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function run(actionInput) {
const workdir = core.getInput('workdir') || '.';
const cwd = path.relative(process.env['GITHUB_WORKSPACE'] || process.cwd(), workdir);
try {
const code = yield core.group('Running vale with reviewdog 🐶 ...', () => __awaiter(this, void 0, void 0, function* () {
const code = yield core.group('Running vale...', () => __awaiter(this, void 0, void 0, function* () {
// Vale output ...
const output = yield exec.getExecOutput(actionInput.exePath, actionInput.args, {
cwd,
Expand All @@ -58,8 +58,17 @@ function run(actionInput) {
}
});
const vale_code = output.exitCode;
'Vale return code: ${vale_code}';
// Check for fatal runtime errors only (exit code 2)
// These aren't linting errors, but ones that will come
// about from missing or bad configuration files, etc.
if (vale_code === 2) {
core.setFailed(`Vale encountered a fatal error with status code: ${vale_code}`);
return 2; // Exit the function early
}
const should_fail = core.getInput('fail_on_error');
// Pipe to reviewdog ...
core.info('Calling reviewdog 🐶');
process.env['REVIEWDOG_GITHUB_API_TOKEN'] = core.getInput('token');
return yield exec.exec(actionInput.reviewdogPath, [
'-f=rdjsonl',
Expand All @@ -75,7 +84,7 @@ function run(actionInput) {
});
}));
if (code !== 0) {
core.setFailed(`reviewdog exited with status code: ${code}`);
core.setFailed(`Vale and reviewdog exited with status code: ${code}`);
}
}
catch (error) {
Expand Down
14 changes: 12 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function run(actionInput: input.Input): Promise<void> {

try {
const code = await core.group(
'Running vale with reviewdog 🐶 ...',
'Running vale...',
async (): Promise<number> => {
// Vale output ...
const output = await exec.getExecOutput(
Expand All @@ -37,9 +37,19 @@ export async function run(actionInput: input.Input): Promise<void> {
);

const vale_code = output.exitCode;
'Vale return code: ${vale_code}'
// Check for fatal runtime errors only (exit code 2)
// These aren't linting errors, but ones that will come
// about from missing or bad configuration files, etc.
if (vale_code === 2) {
core.setFailed(`Vale encountered a fatal error with status code: ${vale_code}`);
return 2; // Exit the function early
}

const should_fail = core.getInput('fail_on_error');

// Pipe to reviewdog ...
core.info('Calling reviewdog 🐶');
process.env['REVIEWDOG_GITHUB_API_TOKEN'] = core.getInput('token');
return await exec.exec(
actionInput.reviewdogPath,
Expand All @@ -62,7 +72,7 @@ export async function run(actionInput: input.Input): Promise<void> {
);

if (code !== 0) {
core.setFailed(`reviewdog exited with status code: ${code}`);
core.setFailed(`Vale and reviewdog exited with status code: ${code}`);
}
} catch (error) {
if (error instanceof Error) {
Expand Down

0 comments on commit f49b46c

Please sign in to comment.