From 5ddc8bb96cb5c9832e448261b66c2c70d51f4ccd Mon Sep 17 00:00:00 2001 From: islandryu Date: Sat, 18 May 2024 07:39:51 +0900 Subject: [PATCH 1/5] fix: Display correct error when config file does not exist --- packages/cli/src/commands/init/init.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index d26342c4e..f2829b64f 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -337,8 +337,9 @@ async function createFromTemplate({ loader.succeed('Dependencies installation skipped'); } } catch (e) { - loader.fail(); - if (e instanceof Error) { + if (e instanceof CLIError) { + logger.error(e.message); + } else if (e instanceof Error) { logger.error( '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', ); From 975afb340b79682abbfb379797bfbcb1062ca6f0 Mon Sep 17 00:00:00 2001 From: islandryu Date: Sat, 18 May 2024 08:08:48 +0900 Subject: [PATCH 2/5] fix: move cocoaPods Error --- packages/cli/src/commands/init/init.ts | 41 +++++++++++++++----------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index f2829b64f..758b19f15 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -310,26 +310,32 @@ async function createFromTemplate({ if (process.platform === 'darwin') { const installPodsValue = String(installCocoaPods); - if (installPodsValue === 'true') { - didInstallPods = true; - await installPods(loader); - loader.succeed(); - setEmptyHashForCachedDependencies(projectName); - } else if (installPodsValue === 'undefined') { - const {installCocoapods} = await prompt({ - type: 'confirm', - name: 'installCocoapods', - message: `Do you want to install CocoaPods now? ${chalk.reset.dim( - 'Only needed if you run your project in Xcode directly', - )}`, - }); - didInstallPods = installCocoapods; - - if (installCocoapods) { + try { + if (installPodsValue === 'true') { + didInstallPods = true; await installPods(loader); loader.succeed(); setEmptyHashForCachedDependencies(projectName); + } else if (installPodsValue === 'undefined') { + const {installCocoapods} = await prompt({ + type: 'confirm', + name: 'installCocoapods', + message: `Do you want to install CocoaPods now? ${chalk.reset.dim( + 'Only needed if you run your project in Xcode directly', + )}`, + }); + didInstallPods = installCocoapods; + + if (installCocoapods) { + await installPods(loader); + loader.succeed(); + setEmptyHashForCachedDependencies(projectName); + } } + } catch (e) { + throw new CLIError( + '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', + ); } } } else { @@ -340,8 +346,9 @@ async function createFromTemplate({ if (e instanceof CLIError) { logger.error(e.message); } else if (e instanceof Error) { + const unknownErrorMessage = 'Please report this issue'; logger.error( - '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', + `An unexpected error occurred: ${e.message}. ${unknownErrorMessage}`, ); logger.debug(e as any); } From 75fd26c0a67846fed129d302c397fd4906c4efd2 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Thu, 4 Jul 2024 15:25:50 +0200 Subject: [PATCH 3/5] fix: prettify output --- packages/cli/src/commands/init/init.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 758b19f15..11defabc7 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -333,8 +333,8 @@ async function createFromTemplate({ } } } catch (e) { - throw new CLIError( - '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', + logger.error( + 'Installing Cocoapods failed. This doesn\'t affect project initialization and you can safely proceed. \nHowever, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n', ); } } @@ -343,16 +343,15 @@ async function createFromTemplate({ loader.succeed('Dependencies installation skipped'); } } catch (e) { + logger.log('\n'); if (e instanceof CLIError) { logger.error(e.message); } else if (e instanceof Error) { - const unknownErrorMessage = 'Please report this issue'; - logger.error( - `An unexpected error occurred: ${e.message}. ${unknownErrorMessage}`, - ); - logger.debug(e as any); + logger.error(`An unexpected error occurred: ${e.message}.`); } didInstallPods = false; + logger.debug(e as any); + process.exit(1); } finally { fs.removeSync(templateSourceDir); } From 8149a771363a3386c1385c2e68528578d17d0053 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Tue, 27 Aug 2024 17:48:05 +0200 Subject: [PATCH 4/5] fix: pass an error --- packages/cli/src/commands/init/init.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 11defabc7..373e5c3e7 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -332,9 +332,11 @@ async function createFromTemplate({ setEmptyHashForCachedDependencies(projectName); } } - } catch (e) { + } catch (error) { logger.error( - 'Installing Cocoapods failed. This doesn\'t affect project initialization and you can safely proceed. \nHowever, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n', + `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: ${ + (error as Error).message as string + }\n`, ); } } From a25d027224d43f3d9904e15b20c2e2c7f5cc87b4 Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Tue, 27 Aug 2024 17:58:37 +0200 Subject: [PATCH 5/5] fix: do cleanup before exiting process --- packages/cli/src/commands/init/init.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 373e5c3e7..d6d115f80 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -344,6 +344,8 @@ async function createFromTemplate({ didInstallPods = false; loader.succeed('Dependencies installation skipped'); } + + fs.removeSync(templateSourceDir); } catch (e) { logger.log('\n'); if (e instanceof CLIError) { @@ -353,9 +355,8 @@ async function createFromTemplate({ } didInstallPods = false; logger.debug(e as any); - process.exit(1); - } finally { fs.removeSync(templateSourceDir); + process.exit(1); } if (process.platform === 'darwin') {