Skip to content

Commit

Permalink
[eas-cli] Fix display of errors when expo-updates CLI command fails (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman authored Apr 12, 2024
1 parent 8e26c7c commit d05142f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🐛 Bug fixes

- Fix display of errors when expo-updates CLI command fails. ([#2324](https://github.com/expo/eas-cli/pull/2324) by [@wschurman](https://github.com/wschurman))

### 🧹 Chores

## [7.8.1](https://github.com/expo/eas-cli/releases/tag/v7.8.1) - 2024-04-11
Expand Down
13 changes: 9 additions & 4 deletions packages/eas-cli/src/project/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,16 +723,21 @@ async function getRuntimeVersionForPlatformAsync({

if (await isModernExpoUpdatesCLIWithRuntimeVersionCommandSupportedAsync(projectDir)) {
try {
Log.debug('Using expo-updates runtimeversion:resolve CLI for runtime version resolution');

const extraArgs = Log.isDebug ? ['--debug'] : [];

const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(projectDir, [
'runtimeversion:resolve',
'--platform',
platform,
...extraArgs,
]);
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult);
if (runtimeVersionResult.fingerprintSources) {
Log.debug(`Resolved fingeprint runtime version for platform "${platform}". Sources:`);
Log.debug(runtimeVersionResult.fingerprintSources);
}

Log.debug('runtimeversion:resolve output:');
Log.debug(resolvedRuntimeVersionJSONResult);

return nullthrows(
runtimeVersionResult.runtimeVersion,
`Unable to determine runtime version for ${
Expand Down
13 changes: 9 additions & 4 deletions packages/eas-cli/src/project/resolveRuntimeVersionAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,21 @@ export async function resolveRuntimeVersionAsync({
}

try {
Log.debug('Using expo-updates runtimeversion:resolve CLI for runtime version resolution');

const extraArgs = Log.isDebug ? ['--debug'] : [];

const resolvedRuntimeVersionJSONResult = await expoUpdatesCommandAsync(projectDir, [
'runtimeversion:resolve',
'--platform',
platform,
...extraArgs,
]);
const runtimeVersionResult = JSON.parse(resolvedRuntimeVersionJSONResult);
if (runtimeVersionResult.fingerprintSources) {
Log.debug(`Resolved fingeprint runtime version for platform "${platform}". Sources:`);
Log.debug(runtimeVersionResult.fingerprintSources);
}

Log.debug('runtimeversion:resolve output:');
Log.debug(resolvedRuntimeVersionJSONResult);

return runtimeVersionResult.runtimeVersion ?? null;
} catch (e: any) {
// if expo-updates is not installed, there's no need for a runtime version in the build
Expand Down
16 changes: 11 additions & 5 deletions packages/eas-cli/src/utils/expoUpdatesCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { link } from '../log';

export class ExpoUpdatesCLIModuleNotFoundError extends Error {}
export class ExpoUpdatesCLIInvalidCommandError extends Error {}
export class ExpoUpdatesCLICommandFailedError extends Error {}

export async function expoUpdatesCommandAsync(projectDir: string, args: string[]): Promise<string> {
let expoUpdatesCli;
Expand All @@ -24,13 +25,18 @@ export async function expoUpdatesCommandAsync(projectDir: string, args: string[]
}

try {
return (await spawnAsync(expoUpdatesCli, args)).stdout;
return (await spawnAsync(expoUpdatesCli, args, { stdio: 'pipe' })).stdout;
} catch (e: any) {
if (e.stderr && typeof e.stderr === 'string' && e.stderr.includes('Invalid command')) {
throw new ExpoUpdatesCLIInvalidCommandError(
`The command specified by ${args} was not valid in the \`expo-updates\` CLI.`
);
if (e.stderr && typeof e.stderr === 'string') {
if (e.stderr.includes('Invalid command')) {
throw new ExpoUpdatesCLIInvalidCommandError(
`The command specified by ${args} was not valid in the \`expo-updates\` CLI.`
);
} else {
throw new ExpoUpdatesCLICommandFailedError(e.stderr);
}
}

throw e;
}
}

0 comments on commit d05142f

Please sign in to comment.