Skip to content

Commit 3b30a1e

Browse files
islandryuszymonrybczak
authored andcommitted
fix: Correctly display errors in react-native init (#2394)
* fix: Display correct error when config file does not exist * fix: move cocoaPods Error * fix: prettify output * fix: pass an error * fix: do cleanup before exiting process --------- Co-authored-by: szymonrybczak <[email protected]>
1 parent 9eb448f commit 3b30a1e

File tree

1 file changed

+33
-23
lines changed
  • packages/cli/src/commands/init

1 file changed

+33
-23
lines changed

packages/cli/src/commands/init/init.ts

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -291,43 +291,53 @@ async function createFromTemplate({
291291
if (process.platform === 'darwin') {
292292
const installPodsValue = String(installCocoaPods);
293293

294-
if (installPodsValue === 'true') {
295-
didInstallPods = true;
296-
await installPods(loader);
297-
loader.succeed();
298-
setEmptyHashForCachedDependencies(projectName);
299-
} else if (installPodsValue === 'undefined') {
300-
const {installCocoapods} = await prompt({
301-
type: 'confirm',
302-
name: 'installCocoapods',
303-
message: `Do you want to install CocoaPods now? ${chalk.reset.dim(
304-
'Only needed if you run your project in Xcode directly',
305-
)}`,
306-
});
307-
didInstallPods = installCocoapods;
308-
309-
if (installCocoapods) {
294+
try {
295+
if (installPodsValue === 'true') {
296+
didInstallPods = true;
310297
await installPods(loader);
311298
loader.succeed();
312299
setEmptyHashForCachedDependencies(projectName);
300+
} else if (installPodsValue === 'undefined') {
301+
const {installCocoapods} = await prompt({
302+
type: 'confirm',
303+
name: 'installCocoapods',
304+
message: `Do you want to install CocoaPods now? ${chalk.reset.dim(
305+
'Only needed if you run your project in Xcode directly',
306+
)}`,
307+
});
308+
didInstallPods = installCocoapods;
309+
310+
if (installCocoapods) {
311+
await installPods(loader);
312+
loader.succeed();
313+
setEmptyHashForCachedDependencies(projectName);
314+
}
313315
}
316+
} catch (error) {
317+
logger.error(
318+
`Installing Cocoapods failed. This doesn't affect project initialization and you can safely proceed. However, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n\nError: ${
319+
(error as Error).message as string
320+
}\n`,
321+
);
314322
}
315323
}
316324
} else {
317325
didInstallPods = false;
318326
loader.succeed('Dependencies installation skipped');
319327
}
328+
329+
fs.removeSync(templateSourceDir);
320330
} catch (e) {
321-
loader.fail();
322-
if (e instanceof Error) {
323-
logger.error(
324-
'Installing pods failed. This doesn\'t affect project initialization and you can safely proceed. \nHowever, you will need to install pods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n',
325-
);
326-
logger.debug(e as any);
331+
logger.log('\n');
332+
if (e instanceof CLIError) {
333+
logger.error(e.message);
334+
} else if (e instanceof Error) {
335+
logger.error(`An unexpected error occurred: ${e.message}.`);
327336
}
328337
didInstallPods = false;
329-
} finally {
338+
logger.debug(e as any);
330339
fs.removeSync(templateSourceDir);
340+
process.exit(1);
331341
}
332342

333343
if (process.platform === 'darwin') {

0 commit comments

Comments
 (0)