Skip to content

Commit

Permalink
Handdled errors close to the functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhoski committed Jul 2, 2024
1 parent 2c6b789 commit 9412d59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
33 changes: 19 additions & 14 deletions src/buildSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,29 @@ export function getBuildSummaryTable(tasks: Task[]): string[][] {
}

export function writeSummary(taskSummaryTableRows: string[][]) {
core.summary
.addTable(taskSummaryTableRows)
.write();
try {
core.summary
.addTable(taskSummaryTableRows)
.write();
} catch (e) {
console.error('An error occurred while adding the build results table to the summary:', e);
}

}

export function processAndDisplayBuildSummary() {
const runId = process.env.GITHUB_RUN_ID;
const runnerTemp = process.env.RUNNER_TEMP;
let filePath: string;

if (!runId) {
filePath = join(runnerTemp as string, `buildSummary.json`);
} else {
filePath = join(runnerTemp as string, `buildSummary${runId as string}.json`);
}
const runId = process.env.GITHUB_RUN_ID || '';
const runnerTemp = process.env.RUNNER_TEMP || '';

const data = JSON.parse(readFileSync(filePath, { encoding: 'utf8' }));
const taskSummaryTableRows = getBuildSummaryTable(data);
let taskSummaryTableRows;
try {
const filePath: string = join(runnerTemp, `buildSummary${runId}.json`);
const data = JSON.parse(readFileSync(filePath, { encoding: 'utf8' }));
taskSummaryTableRows = getBuildSummaryTable(data);
} catch (e) {
console.error('An error occurred while reading the build summary file:', e);
return;
}
writeSummary(taskSummaryTableRows);
}

8 changes: 2 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,14 @@ async function run() {
}
};

await matlab.runCommand(
matlab.runCommand(
helperScript,
platform,
architecture,
(cmd, args) => exec.exec(cmd, args, execOptions),
startupOptions
).finally(() => {
try {
buildSummary.processAndDisplayBuildSummary();
} catch (ex) {
console.error('An error occurred while reading the build summary file or adding the build summary table:', ex);
}
buildSummary.processAndDisplayBuildSummary();
});

}
Expand Down

0 comments on commit 9412d59

Please sign in to comment.