From 94a0c63a95e83e620c67b6bab259d1a299dc321f Mon Sep 17 00:00:00 2001 From: Fran Dios Date: Thu, 11 Apr 2024 17:16:40 +0200 Subject: [PATCH] Improve codegen warnings when missing deps (#1975) * Fix conditional to avoid swallowing warnings * Avoid existing parent process when Codegen fails * Parse AbortError messages from child process properly --- packages/cli/src/lib/codegen.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/lib/codegen.ts b/packages/cli/src/lib/codegen.ts index 92a9b23275..37c6bd27e5 100644 --- a/packages/cli/src/lib/codegen.ts +++ b/packages/cli/src/lib/codegen.ts @@ -26,6 +26,14 @@ if (isStandaloneProcess) { } function normalizeCodegenError(errorMessage: string, rootDirectory?: string) { + if (errorMessage.includes('AbortError: ')) { + const parsedError = errorMessage.split('AbortError: ')[1] ?? ''; + const message = parsedError.split('\n')[0]; + const details = parsedError.match(/tryMessage: '(.*)',$/m)?.[1]; + + if (message) return {message, details}; + } + const [first = '', ...rest] = errorMessage .replaceAll('[FAILED]', '') .replace(/\s{2,}/g, '\n') @@ -76,7 +84,8 @@ export function spawnCodegenProcess({ // Filter these logs even on verbose mode because it floods the terminal: if (/`punycode`/.test(message)) return; - if (/\.body\[\d\]/) return; + if (/\.body\[\d\]/.test(message)) return; + if (/console\.time(End)?\(\)/.test(message)) return; console.log(''); renderWarning({headline: message, body: details}); @@ -84,15 +93,10 @@ export function spawnCodegenProcess({ child.on('close', (code) => { if (code && code > 0) { - renderFatalError({ - type: 0, - name: 'CodegenError', - message: `Codegen process exited with code ${code}`, - skipOclifErrorHandling: true, - tryMessage: 'Try restarting the dev server.', + renderWarning({ + headline: 'Codegen process exited with code ' + code, + body: 'There should be more logs above.', }); - - process.exit(code); } }); @@ -112,6 +116,8 @@ type CodegenOptions = ProjectDirs & { export function codegen(options: CodegenOptions) { return generateTypes(options).catch((error: Error) => { + if (error instanceof AbortError) throw error; + const {message, details} = normalizeCodegenError( error.message, options.rootDirectory,