Skip to content

Commit

Permalink
doctor: add error messages for failures (#672)
Browse files Browse the repository at this point in the history
* add error messages for failures

* Fix Flow errors
  • Loading branch information
jmeistrich authored and thymikee committed Sep 10, 2019
1 parent 5e7652d commit 154f1ca
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
13 changes: 7 additions & 6 deletions packages/cli/src/commands/doctor/checkInstallation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const PACKAGE_MANAGERS = {
NPM: 'NPM',
};

const isSoftwareInstalled = async (command: string) => {
const checkSoftwareInstalled = async (command: string) => {
try {
await commandExists(command);

return true;
} catch (_ignored) {
return false;
} catch (_ignored) {
return 'should be installed';
}
};

Expand All @@ -24,7 +24,8 @@ const doesSoftwareNeedToBeFixed = ({
version: string,
versionRange: string,
}) =>
version === 'Not Found' ||
!semver.satisfies(semver.coerce(version), versionRange);
(version === 'Not Found' ||
!semver.satisfies(semver.coerce(version), versionRange)) &&
`version ${versionRange} is required`;

export {PACKAGE_MANAGERS, isSoftwareInstalled, doesSoftwareNeedToBeFixed};
export {PACKAGE_MANAGERS, checkSoftwareInstalled, doesSoftwareNeedToBeFixed};
5 changes: 4 additions & 1 deletion packages/cli/src/commands/doctor/doctor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ const printIssue = ({
label,
needsToBeFixed,
isRequired,
description,
}: {
label: string,
needsToBeFixed: boolean,
isRequired: boolean,
description: string,
}) => {
const symbol = needsToBeFixed
? isRequired
? chalk.red('✖')
: chalk.yellow('●')
: chalk.green('✓');

logger.log(` ${symbol} ${label}`);
logger.log(` ${symbol} ${label}${needsToBeFixed ? ': ' + description : ''}`);
};

const printOverallStats = ({errors, warnings}) => {
Expand Down Expand Up @@ -94,6 +96,7 @@ export default (async function runDoctor(
return {
label: healthcheck.label,
needsToBeFixed: Boolean(needsToBeFixed),
description: String(needsToBeFixed),
runAutomaticFix: healthcheck.runAutomaticFix,
isRequired,
type: needsToBeFixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ const URLS = {

const label = 'ANDROID_HOME';

const message = `Read more about how to set the ${label} at ${chalk.dim(
URLS[process.platform],
)}.`;

export default ({
label,
getDiagnostics: async () => ({
needsToBeFixed: !process.env.ANDROID_HOME,
needsToBeFixed: !process.env.ANDROID_HOME && message,
}),
runAutomaticFix: async ({loader}: {loader: typeof Ora}) => {
loader.info();

logManualInstallation({
message: `Read more about how to set the ${label} at ${chalk.dim(
URLS[process.platform],
)}.`,
message,
});
},
}: HealthCheckInterface);
4 changes: 2 additions & 2 deletions packages/cli/src/commands/doctor/healthchecks/cocoaPods.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @flow
import {isSoftwareInstalled} from '../checkInstallation';
import {checkSoftwareInstalled} from '../checkInstallation';
// $FlowFixMe - converted to TS
import {installCocoaPods} from '../../../tools/installPods';
import {type HealthCheckInterface} from '../types';

export default ({
label: 'CocoaPods',
getDiagnostics: async () => ({
needsToBeFixed: !(await isSoftwareInstalled('pod')),
needsToBeFixed: await checkSoftwareInstalled('pod'),
}),
runAutomaticFix: async ({loader}) => await installCocoaPods(loader),
}: HealthCheckInterface);
4 changes: 2 additions & 2 deletions packages/cli/src/commands/doctor/healthchecks/iosDeploy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import execa from 'execa';
import Ora from 'ora';
import {isSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation';
import {checkSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation';
import {packageManager} from './packageManagers';
import {logManualInstallation} from './common';
import type {HealthCheckInterface} from '../types';
Expand All @@ -22,7 +22,7 @@ export default ({
label: 'ios-deploy',
isRequired: false,
getDiagnostics: async () => ({
needsToBeFixed: !(await isSoftwareInstalled('ios-deploy')),
needsToBeFixed: await checkSoftwareInstalled('ios-deploy'),
}),
runAutomaticFix: async ({loader}: {loader: typeof Ora}) => {
const installationCommand = getInstallationCommand();
Expand Down

0 comments on commit 154f1ca

Please sign in to comment.