Skip to content

Commit

Permalink
fix(ios): do not falsely link to Android Wiki for iOS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Sep 10, 2020
1 parent bbf55cb commit 18371f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/android/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Debug from 'debug';

import { AVDException, CLIException, ERR_BAD_INPUT, ERR_NO_DEVICE, ERR_NO_TARGET, ERR_TARGET_NOT_FOUND, ERR_UNSUITABLE_API_INSTALLATION, RunException } from '../errors';
import { AVDException, AndroidRunException, CLIException, ERR_BAD_INPUT, ERR_NO_DEVICE, ERR_NO_TARGET, ERR_TARGET_NOT_FOUND, ERR_UNSUITABLE_API_INSTALLATION } from '../errors';
import { getOptionValue, getOptionValues } from '../utils/cli';
import { log } from '../utils/log';
import { onBeforeExit } from '../utils/process';
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function selectDevice(sdk: SDK, args: readonly string[]): Promise<D
if (targetDevice) {
return targetDevice;
} else {
throw new RunException(`Target not found: ${target}`, ERR_TARGET_NOT_FOUND);
throw new AndroidRunException(`Target not found: ${target}`, ERR_TARGET_NOT_FOUND);
}
}

Expand All @@ -100,7 +100,7 @@ export async function selectDevice(sdk: SDK, args: readonly string[]): Promise<D
if (selectedDevice) {
return selectedDevice;
} else if (args.includes('--device')) {
throw new RunException(`No hardware devices found. Not attempting emulator because --device was specified.`, ERR_NO_DEVICE);
throw new AndroidRunException(`No hardware devices found. Not attempting emulator because --device was specified.`, ERR_NO_DEVICE);
} else {
log('No hardware devices found, attempting emulator...\n');
}
Expand All @@ -116,9 +116,9 @@ export async function selectDevice(sdk: SDK, args: readonly string[]): Promise<D
debug('Issue with AVDs: %s', e.message);

if (e.code === ERR_UNSUITABLE_API_INSTALLATION) {
throw new RunException('No targets devices/emulators available. Cannot create AVD because there is no suitable API installation. Use --sdk-info to reveal missing packages and other issues.', ERR_NO_TARGET);
throw new AndroidRunException('No targets devices/emulators available. Cannot create AVD because there is no suitable API installation. Use --sdk-info to reveal missing packages and other issues.', ERR_NO_TARGET);
}
}

throw new RunException('No target devices/emulators available.', ERR_NO_TARGET);
throw new AndroidRunException('No target devices/emulators available.', ERR_NO_TARGET);
}
12 changes: 10 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ export type EmulatorExceptionCode = (

export class EmulatorException extends AndroidException<EmulatorExceptionCode> {}

export type RunExceptionCode = (
export type AndroidRunExceptionCode = (
typeof ERR_NO_AVDS_FOUND |
typeof ERR_TARGET_NOT_FOUND |
typeof ERR_NO_DEVICE |
typeof ERR_NO_TARGET
);

export class RunException extends AndroidException<RunExceptionCode> {}
export class AndroidRunException extends AndroidException<AndroidRunExceptionCode> {}

export type SDKExceptionCode = (
typeof ERR_AVD_HOME_NOT_FOUND |
Expand All @@ -113,6 +113,14 @@ export type SDKExceptionCode = (

export class SDKException extends AndroidException<SDKExceptionCode> {}

export type IOSRunExceptionCode = (
typeof ERR_TARGET_NOT_FOUND |
typeof ERR_NO_DEVICE |
typeof ERR_NO_TARGET
);

export class IOSRunException extends Exception<IOSRunExceptionCode> {}

export function serializeError(e = new Error()): string {
const stack = String(e.stack ? e.stack : e);

Expand Down
6 changes: 3 additions & 3 deletions src/ios/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Debug from 'debug';
import { existsSync, mkdtempSync } from 'fs';
import * as path from 'path';

import { CLIException, ERR_BAD_INPUT, ERR_TARGET_NOT_FOUND, RunException } from '../errors';
import { CLIException, ERR_BAD_INPUT, ERR_TARGET_NOT_FOUND, IOSRunException } from '../errors';
import { getOptionValue } from '../utils/cli';

import { getBundleId, unzipIPA } from './utils/app';
Expand All @@ -23,7 +23,7 @@ export async function run(args: readonly string[]): Promise<void> {
const isIPA = appPath.endsWith('.ipa');

if (!existsSync(appPath)) {
throw new RunException(`Path '${appPath}' not found`);
throw new IOSRunException(`Path '${appPath}' not found`);
}

try {
Expand All @@ -48,7 +48,7 @@ export async function run(args: readonly string[]): Promise<void> {
} else if (simulators.find(s => s.udid === udid)) {
await runOnSimulator(udid, appPath, bundleId, waitForApp);
} else {
throw new RunException(`No device or simulator with UDID "${udid}" found`, ERR_TARGET_NOT_FOUND);
throw new IOSRunException(`No device or simulator with UDID "${udid}" found`, ERR_TARGET_NOT_FOUND);
}
} else if (devices.length && !preferSimulator) {
// no udid, use first connected device
Expand Down

0 comments on commit 18371f2

Please sign in to comment.