Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#97: Catch Vale runtime errors properly #133

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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