feat(error-handling): error notification for network failures (#94)

Signed-off-by: hoivikaj <github@hoivik.co>
This commit is contained in:
Anthony Hoivik authored and GitHub committed 2026-03-17 15:23:28 -03:00
1 parent 4959f8f18c
commit b572e07b01
7 files changed
+335 -52

No files matched your search

+22 -10
View File
@@ -22,6 +22,7 @@ import {
import { downloadTool, extractZip, find, cacheDir } from '@actions/tool-cache';
import { mv, cp, mkdirP } from '@actions/io';
import { getRelease } from './releases.js';
import { getErrorMessage } from './error-utils.js';
// __dirname is not available in ES modules, so we need to construct it ourselves
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -47,7 +48,13 @@ function mapOS (os) {
async function downloadAndExtractCLI (url) {
debug(`Downloading OpenTofu CLI from ${url}`);
const pathToCLIZip = await downloadTool(url);
let pathToCLIZip;
try {
pathToCLIZip = await downloadTool(url);
} catch (error) {
const cause = getErrorMessage(error);
throw new Error(`Failed to download OpenTofu from ${url}: ${cause}`);
}
if (!pathToCLIZip) {
throw new Error(`Unable to download OpenTofu from ${url}`);
@@ -56,14 +63,19 @@ async function downloadAndExtractCLI (url) {
let pathToCLI;
debug('Extracting OpenTofu CLI zip file');
if (platform().startsWith('win')) {
debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
await mv(pathToCLIZip, fixedPathToCLIZip);
debug(`Moved download to ${fixedPathToCLIZip}`);
pathToCLI = await extractZip(fixedPathToCLIZip);
} else {
pathToCLI = await extractZip(pathToCLIZip);
try {
if (platform().startsWith('win')) {
debug(`OpenTofu CLI Download Path is ${pathToCLIZip}`);
const fixedPathToCLIZip = `${pathToCLIZip}.zip`;
await mv(pathToCLIZip, fixedPathToCLIZip);
debug(`Moved download to ${fixedPathToCLIZip}`);
pathToCLI = await extractZip(fixedPathToCLIZip);
} else {
pathToCLI = await extractZip(pathToCLIZip);
}
} catch (error) {
const cause = getErrorMessage(error);
throw new Error(`Failed to extract OpenTofu archive: ${cause}`);
}
debug(`OpenTofu CLI path is ${pathToCLI}.`);
@@ -227,7 +239,7 @@ async function run () {
}
return release;
} catch (error) {
logError(error);
logError(getErrorMessage(error));
throw error;
}
}