Error handling for JSON parsing

This commit is contained in:
Angela P Wen 2022-08-01 12:12:49 +02:00
parent 6630cbeccb
commit 8a4a573d59
3 changed files with 17 additions and 6 deletions

11
lib/actions-util.js generated
View file

@ -688,9 +688,14 @@ async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
}
let suffix = "";
const matrix = getRequiredInput("matrix");
if (matrix !== undefined && matrix !== "null") {
for (const entry of Object.entries(JSON.parse(matrix)).sort())
suffix += `-${entry[1]}`;
if (matrix) {
try {
for (const [, matrixVal] of Object.entries(JSON.parse(matrix)).sort())
suffix += `-${matrixVal}`;
}
catch (e) {
core.info("Could not parse user-specified `matrix` input into JSON. The debug artifact will not be named with the user's `matrix` input.");
}
}
await artifact.create().uploadArtifact(sanitizeArifactName(`${artifactName}${suffix}`), toUpload.map((file) => path.normalize(file)), path.normalize(rootDir));
}

File diff suppressed because one or more lines are too long

View file

@ -888,8 +888,14 @@ export async function uploadDebugArtifacts(
let suffix = "";
const matrix = getRequiredInput("matrix");
if (matrix) {
for (const [, matrixVal] of Object.entries(JSON.parse(matrix)).sort())
suffix += `-${matrixVal}`;
try {
for (const [, matrixVal] of Object.entries(JSON.parse(matrix)).sort())
suffix += `-${matrixVal}`;
} catch (e) {
core.info(
"Could not parse user-specified `matrix` input into JSON. The debug artifact will not be named with the user's `matrix` input."
);
}
}
await artifact.create().uploadArtifact(
sanitizeArifactName(`${artifactName}${suffix}`),