Skip to content

Commit

Permalink
Fix unhandled promise rejections (#528)
Browse files Browse the repository at this point in the history
Co-authored-by: Gábor Csárdi <csardi.gabor@gmail.com>
  • Loading branch information
nikeee and gaborcsardi authored Mar 14, 2022
1 parent 80377d9 commit eae0c34
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 44 deletions.
68 changes: 41 additions & 27 deletions setup-pandoc/lib/setup-pandoc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -8,14 +27,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPandoc = void 0;
let tempDirectory = process.env["RUNNER_TEMP"] || "";
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
Expand Down Expand Up @@ -43,41 +56,41 @@ if (!tempDirectory) {
tempDirectory = path.join(baseLocation, "actions", "temp");
}
function run() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
let pandocVersion = core.getInput("pandoc-version");
core.debug(`got pandoc-version ${pandocVersion}`);
yield getPandoc(pandocVersion);
}
catch (error) {
core.setFailed(error.message);
core.setFailed((_b = (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error) !== null && _b !== void 0 ? _b : "Unknown error");
}
});
}
function getPandoc(version) {
return __awaiter(this, void 0, void 0, function* () {
if (IS_WINDOWS) {
installPandocWindows(version);
}
else if (IS_MAC) {
installPandocMac(version);
}
else {
installPandocLinux(version);
}
});
if (IS_WINDOWS) {
return installPandocWindows(version);
}
else if (IS_MAC) {
return installPandocMac(version);
}
else {
return installPandocLinux(version);
}
}
exports.getPandoc = getPandoc;
function installPandocMac(version) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const fileName = util.format("pandoc-%s-macOS.pkg", version);
const downloadUrl = util.format("https://github.com/jgm/pandoc/releases/download/%s/%s", version, fileName);
let downloadPath = null;
let downloadPath;
try {
downloadPath = yield tc.downloadTool(downloadUrl);
}
catch (error) {
throw `Failed to download Pandoc ${version}: ${error}`;
throw new Error(`Failed to download Pandoc ${version}: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
}
yield io.mv(downloadPath, path.join(tempDirectory, fileName));
exec.exec("sudo installer", [
Expand All @@ -91,15 +104,16 @@ function installPandocMac(version) {
});
}
function installPandocWindows(version) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const fileName = util.format("pandoc-%s-windows-x86_64.zip", version);
const downloadUrl = util.format("https://github.com/jgm/pandoc/releases/download/%s/%s", version, fileName);
let downloadPath = null;
let downloadPath;
try {
downloadPath = yield tc.downloadTool(downloadUrl);
}
catch (error) {
throw `Failed to download Pandoc ${version}: ${error}`;
throw new Error(`Failed to download Pandoc ${version}: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
}
//
// Extract
Expand All @@ -125,16 +139,17 @@ function pandocSubdir(version) {
return util.format("pandoc-%s-windows-x86_64", version);
}
function installPandocLinux(version) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const fileName = util.format("pandoc-%s-1-amd64.deb", version);
const downloadUrl = util.format("https://github.com/jgm/pandoc/releases/download/%s/%s", version, fileName);
let downloadPath = null;
let downloadPath;
try {
console.log("::group::Download pandoc");
downloadPath = yield tc.downloadTool(downloadUrl);
}
catch (error) {
throw `Failed to download Pandoc ${version}: ${error}`;
throw new Error(`Failed to download Pandoc ${version}: ${error}`);
}
yield io.mv(downloadPath, path.join(tempDirectory, fileName));
try {
Expand All @@ -147,8 +162,7 @@ function installPandocLinux(version) {
]);
}
catch (error) {
core.debug(error);
throw `Failed to install pandoc: ${error}`;
throw new Error(`Failed to install pandoc: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
}
console.log("::endgroup::");
});
Expand Down
32 changes: 15 additions & 17 deletions setup-pandoc/src/setup-pandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@ async function run() {
core.debug(`got pandoc-version ${pandocVersion}`);
await getPandoc(pandocVersion);
} catch (error) {
core.setFailed(error.message);
core.setFailed(error?.message ?? error ?? "Unknown error");
}
}

export async function getPandoc(version: string) {
export function getPandoc(version: string): Promise<void> {
if (IS_WINDOWS) {
installPandocWindows(version);
return installPandocWindows(version);
} else if (IS_MAC) {
installPandocMac(version);
return installPandocMac(version);
} else {
installPandocLinux(version);
return installPandocLinux(version);
}
}

async function installPandocMac(version: string) {
async function installPandocMac(version: string): Promise<void> {
const fileName = util.format("pandoc-%s-macOS.pkg", version);
const downloadUrl = util.format(
"https://github.com/jgm/pandoc/releases/download/%s/%s",
version,
fileName
);
let downloadPath: string | null = null;

let downloadPath: string;
try {
downloadPath = await tc.downloadTool(downloadUrl);
} catch (error) {
throw `Failed to download Pandoc ${version}: ${error}`;
throw new Error(`Failed to download Pandoc ${version}: ${error?.message ?? error}`);
}

await io.mv(downloadPath, path.join(tempDirectory, fileName));
Expand All @@ -74,19 +74,19 @@ async function installPandocMac(version: string) {
]);
}

async function installPandocWindows(version: string) {
async function installPandocWindows(version: string): Promise<void> {
const fileName = util.format("pandoc-%s-windows-x86_64.zip", version);
const downloadUrl = util.format(
"https://github.com/jgm/pandoc/releases/download/%s/%s",
version,
fileName
);
let downloadPath: string | null = null;

let downloadPath: string;
try {
downloadPath = await tc.downloadTool(downloadUrl);
} catch (error) {
throw `Failed to download Pandoc ${version}: ${error}`;
throw new Error(`Failed to download Pandoc ${version}: ${error?.message ?? error}`);
}

//
Expand Down Expand Up @@ -119,20 +119,20 @@ function pandocSubdir(version: string) {
return util.format("pandoc-%s-windows-x86_64", version);
}

async function installPandocLinux(version: string) {
async function installPandocLinux(version: string): Promise<void> {
const fileName = util.format("pandoc-%s-1-amd64.deb", version);
const downloadUrl = util.format(
"https://github.com/jgm/pandoc/releases/download/%s/%s",
version,
fileName
);
let downloadPath: string | null = null;

let downloadPath: string;
try {
console.log("::group::Download pandoc");
downloadPath = await tc.downloadTool(downloadUrl);
} catch (error) {
throw `Failed to download Pandoc ${version}: ${error}`;
throw new Error(`Failed to download Pandoc ${version}: ${error}`);
}

await io.mv(downloadPath, path.join(tempDirectory, fileName));
Expand All @@ -146,9 +146,7 @@ async function installPandocLinux(version: string) {
path.join(tempDirectory, fileName)
]);
} catch (error) {
core.debug(error);

throw `Failed to install pandoc: ${error}`;
throw new Error(`Failed to install pandoc: ${error?.message ?? error}`);
}
console.log("::endgroup::");
}
Expand Down

0 comments on commit eae0c34

Please sign in to comment.