mirror of
https://github.com/obi1kenobi/cargo-semver-checks-action.git
synced 2024-11-21 23:49:33 +01:00
Proper error handling
This commit is contained in:
parent
733726affb
commit
9c72228a41
2 changed files with 15 additions and 7 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
20
src/main.ts
20
src/main.ts
|
@ -7,6 +7,14 @@ import * as io from "@actions/io";
|
||||||
import * as toolCache from "@actions/tool-cache";
|
import * as toolCache from "@actions/tool-cache";
|
||||||
import * as rustCore from "@actions-rs/core";
|
import * as rustCore from "@actions-rs/core";
|
||||||
|
|
||||||
|
function getErrorMessage(error: unknown): string {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return error.message;
|
||||||
|
} else {
|
||||||
|
return String(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getPlatformMatchingTarget(): string {
|
function getPlatformMatchingTarget(): string {
|
||||||
const platform = os.platform() as string;
|
const platform = os.platform() as string;
|
||||||
switch (platform) {
|
switch (platform) {
|
||||||
|
@ -70,8 +78,8 @@ async function installRustUp(): Promise<void> {
|
||||||
if (os.platform() == "win32") {
|
if (os.platform() == "win32") {
|
||||||
try {
|
try {
|
||||||
await exec.exec("mkdir C:\\Users\\runneradmin\\.cargo\\registry\\index");
|
await exec.exec("mkdir C:\\Users\\runneradmin\\.cargo\\registry\\index");
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
core.info(`Failed to create registry index directory: ${error.message}`);
|
core.info(`Failed to create registry index directory: ${getErrorMessage(error)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,9 +114,9 @@ async function installCargoSemverChecks(cargo: rustCore.Cargo): Promise<void> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await installCargoSemverChecksFromPrecompiledBinary();
|
await installCargoSemverChecksFromPrecompiledBinary();
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
core.info("Failed to download precompiled binary of cargo-semver-checks.");
|
core.info("Failed to download precompiled binary of cargo-semver-checks.");
|
||||||
core.info(`Error: ${error.message}`);
|
core.info(`Error: ${getErrorMessage(error)}`);
|
||||||
core.info("Installing using cargo install...");
|
core.info("Installing using cargo install...");
|
||||||
|
|
||||||
await installCargoSemverChecksUsingCargo(cargo);
|
await installCargoSemverChecksUsingCargo(cargo);
|
||||||
|
@ -127,8 +135,8 @@ async function run(): Promise<void> {
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
await run();
|
await run();
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(getErrorMessage(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue