Skip to content

Commit

Permalink
fix(cli): Throw error if native-run didn't find targets (#4681)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jun 7, 2021
1 parent 39eebd0 commit bfbf2b5
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions cli/src/util/native-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,37 @@ export async function runNativeRun(
export async function getPlatformTargets(
platformName: string,
): Promise<PlatformTarget[]> {
const errors = [];
try {
const output = await runNativeRun([platformName, '--list', '--json']);
const parsedOutput = JSON.parse(output);

return [
...parsedOutput.devices.map((t: any) => ({ ...t, virtual: false })),
...parsedOutput.virtualDevices.map((t: any) => ({ ...t, virtual: true })),
];
if (parsedOutput.devices.length || parsedOutput.virtualDevices.length) {
return [
...parsedOutput.devices.map((t: any) => ({ ...t, virtual: false })),
...parsedOutput.virtualDevices.map((t: any) => ({
...t,
virtual: true,
})),
];
} else {
parsedOutput.errors.map((e: any) => {
errors.push(e);
});
}
} catch (e) {
const err = JSON.parse(e);
const errMsg = `${c.strong('native-run')} failed with error ${c.strong(
err.code,
)}: ${err.error}
\tMore details for this error may be available online: ${c.strong(
'https://github.com/ionic-team/native-run/wiki/Android-Errors',
)}
`;
throw errMsg;
errors.push(err);
}
const plural = errors.length > 1 ? 's' : '';
const errMsg = `${c.strong('native-run')} failed with error${plural}\n
${errors
.map((e: any) => {
return `\t${c.strong(e.code)}: ${e.error}`;
})
.join('\n')}
\n\tMore details for this error${plural} may be available online: ${c.strong(
'https://github.com/ionic-team/native-run/wiki/Android-Errors',
)}
`;
throw errMsg;
}

0 comments on commit bfbf2b5

Please sign in to comment.