Skip to content

Commit

Permalink
refactor: update error handling to node 20 standards (#243)
Browse files Browse the repository at this point in the history
* refactor: update error handling to node 20 standards

* chore: rebuild files
  • Loading branch information
byCedric authored Nov 24, 2023
1 parent b3e5355 commit 65ee055
Show file tree
Hide file tree
Showing 14 changed files with 11,274 additions and 11,088 deletions.
4,491 changes: 2,253 additions & 2,238 deletions build/command/index.js

Large diffs are not rendered by default.

2,158 changes: 1,111 additions & 1,047 deletions build/fingerprint-post/index.js

Large diffs are not rendered by default.

2,220 changes: 1,126 additions & 1,094 deletions build/fingerprint/index.js

Large diffs are not rendered by default.

5,907 changes: 2,992 additions & 2,915 deletions build/preview-build/index.js

Large diffs are not rendered by default.

1,562 changes: 788 additions & 774 deletions build/preview-comment/index.js

Large diffs are not rendered by default.

1,327 changes: 665 additions & 662 deletions build/preview/index.js

Large diffs are not rendered by default.

4,633 changes: 2,317 additions & 2,316 deletions build/setup/index.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/eas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
30 changes: 14 additions & 16 deletions src/expo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand All @@ -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()];
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)}`);
}
}

Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/packager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { exec, getExecOutput } from '@actions/exec';
import { mkdirP } from '@actions/io';

import { errorMessage } from './utils';
import { cacheTool, tempPath } from './worker';

/**
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/project.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
4 changes: 1 addition & 3 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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));
}
}

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"outDir": "./build",
"rootDir": "./src",
"module": "CommonJS",
"moduleResolution": "node"
},
"exclude": [
Expand Down

0 comments on commit 65ee055

Please sign in to comment.