refactor: update error handling to node 20 standards (#243)

* refactor: update error handling to node 20 standards

* chore: rebuild files
This commit is contained in:
Cedric van Putten authored and GitHub committed 2023-11-24 18:03:01 +01:00
1 parent b3e53555d9
commit 65ee05557f
14 files changed
+5544 -5358

No files matched your search

+644 -629
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+793 -761
View File
File diff suppressed because it is too large. Load diff
+1395 -1318
View File
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+585 -582
View File
File diff suppressed because it is too large. Load diff
+693 -692
View File
File diff suppressed because it is too large. Load diff
+2 -4
View File
@@ -4,8 +4,6 @@ import type { Platform } from '@expo/config';
import semver from 'semver';
import { URL } from 'url';
import { errorMessage } from './utils';
export interface EasUpdate {
/** The unique ID of the platform specific update */
id: string;
@@ -60,8 +58,8 @@ export async function createUpdate(cwd: string, command: string): Promise<EasUpd
({ stdout } = await getExecOutput((await which('eas', true)) + ` ${command}`, undefined, {
cwd,
}));
} catch (error) {
throw new Error(`Could not create a new EAS Update, reason:\n${errorMessage(error)}`);
} catch (error: unknown) {
throw new Error(`Could not create a new EAS Update`, { cause: error });
}
return JSON.parse(stdout);
+14 -16
View File
@@ -4,8 +4,6 @@ import { which } from '@actions/io';
import { ok as assert } from 'assert';
import { URL } from 'url';
import { errorMessage } from './utils';
export type CliName = 'expo' | 'eas';
export type Command = {
@@ -97,8 +95,8 @@ export async function projectOwner(cli: CliName = 'expo'): Promise<string> {
try {
({ stdout } = await getExecOutput(await which(cli), ['whoami'], { silent: true }));
} catch (error) {
throw new Error(`Could not fetch the project owner, reason:\n${errorMessage(error)}`);
} catch (error: unknown) {
throw new Error(`Could not fetch the project owner`, { cause: error });
}
if (!stdout) {
@@ -118,8 +116,8 @@ export async function runCommand(cmd: Command) {
({ stderr, stdout } = await getExecOutput(await which(cmd.cli), cmd.args.concat('--non-interactive'), {
silent: false,
}));
} catch (error) {
throw new Error(`Could not run command ${cmd.args.join(' ')}, reason:\n${errorMessage(error)}`);
} catch (error: unknown) {
throw new Error(`Could not run command ${cmd.args.join(' ')}`, { cause: error });
}
return [stdout.trim(), stderr.trim()];
@@ -133,8 +131,8 @@ export async function easBuild(cmd: Command): Promise<BuildInfo[]> {
({ stdout } = await getExecOutput(await which('eas', true), args, {
silent: false,
}));
} catch (error) {
throw new Error(`Could not run command eas build, reason:\n${errorMessage(error)}`);
} catch (error: unknown) {
throw new Error(`Could not run command eas build`, { cause: error });
}
return JSON.parse(stdout);
@@ -165,8 +163,8 @@ export async function createEasBuildFromRawCommandAsync(
({ stdout } = await getExecOutput((await which('eas', true)) + ` ${cmd}`, extraArgs, {
cwd,
}));
} catch (error) {
throw new Error(`Could not run command eas build, reason:\n${errorMessage(error)}`);
} catch (error: unknown) {
throw new Error(`Could not run command eas build`, { cause: error });
}
return JSON.parse(stdout);
@@ -178,8 +176,8 @@ export async function createEasBuildFromRawCommandAsync(
export async function cancelEasBuildAsync(cwd: string, buildId: string): Promise<void> {
try {
await getExecOutput(await which('eas', true), ['build:cancel', buildId], { cwd });
} catch (e) {
info(`Failed to cancel build ${buildId}: ${errorMessage(e)}`);
} catch (error: unknown) {
info(`Failed to cancel build ${buildId}: ${String(error)}`);
}
}
@@ -193,8 +191,8 @@ export async function queryEasBuildInfoAsync(cwd: string, buildId: string): Prom
silent: true,
});
return JSON.parse(stdout);
} catch (e) {
info(`Failed to query eas build ${buildId}: ${errorMessage(e)}`);
} catch (error: unknown) {
info(`Failed to query eas build ${buildId}: ${String(error)}`);
}
return null;
}
@@ -210,8 +208,8 @@ export async function projectInfo(dir: string): Promise<ProjectInfo> {
cwd: dir,
silent: true,
}));
} catch (error) {
throw new Error(`Could not fetch the project info from ${dir}, reason:\n${errorMessage(error)}`);
} catch (error: unknown) {
throw new Error(`Could not fetch the project info from ${dir}`, { cause: error });
}
const { name, slug, owner } = JSON.parse(stdout);
+2 -3
View File
@@ -1,7 +1,6 @@
import { exec, getExecOutput } from '@actions/exec';
import { mkdirP } from '@actions/io';
import { errorMessage } from './utils';
import { cacheTool, tempPath } from './worker';
/**
@@ -14,8 +13,8 @@ export async function resolvePackage(name: string, range: string): Promise<strin
try {
({ stdout } = await getExecOutput('npm', ['info', `${name}@${range}`, 'version', '--json'], { silent: true }));
} catch (error) {
throw new Error(`Could not resolve ${name}@${range}, reason:\n${errorMessage(error)}`);
} catch (error: unknown) {
throw new Error(`Could not resolve ${name}@${range}`, { cause: error });
}
// thanks npm, for returning a "" json string value for invalid versions
+2 -4
View File
@@ -1,8 +1,6 @@
import { getExecOutput } from '@actions/exec';
import { ExpoConfig } from '@expo/config';
import { errorMessage } from './utils';
/**
* Load the Expo app project config in the given directory.
* This runs `expo config` command instead of using `@expo/config` directly,
@@ -16,8 +14,8 @@ export async function loadProjectConfig(cwd: string): Promise<ExpoConfig> {
cwd,
silent: true,
}));
} catch (error) {
throw new Error(`Could not fetch the project info from ${cwd}, reason:\n${errorMessage(error)}`);
} catch (error: unknown) {
throw new Error(`Could not fetch the project info from ${cwd}`, { cause: error });
}
return JSON.parse(stdout);
-12
View File
@@ -9,15 +9,3 @@ export function template(template: string, replacements: Record<string, string>)
}
return result;
}
export function errorMessage(error: Error | unknown): string {
if (error instanceof Error) {
return error.message;
}
if (typeof error === 'string') {
return error;
}
return 'Unknown error';
}
+1 -3
View File
@@ -4,8 +4,6 @@ import { ok as assert } from 'assert';
import os from 'os';
import path from 'path';
import { errorMessage } from './utils';
export { find as findTool, cacheDir as cacheTool } from '@actions/tool-cache';
/**
@@ -56,7 +54,7 @@ export async function patchWatchers(): Promise<void> {
} catch (error) {
warning(`Looks like we can't patch watchers/inotify limits, you might encouter the 'ENOSPC' error.`);
warning('For more info: https://github.com/expo/expo-github-action/issues/20, encountered error:');
warning(errorMessage(error));
warning(String(error));
}
}
+1
View File
@@ -3,6 +3,7 @@
"compilerOptions": {
"outDir": "./build",
"rootDir": "./src",
"module": "CommonJS",
"moduleResolution": "node"
},
"exclude": [