Skip to content

Commit

Permalink
Improve codegen warnings when missing deps (#1975)
Browse files Browse the repository at this point in the history
* Fix conditional to avoid swallowing warnings

* Avoid existing parent process when Codegen fails

* Parse AbortError messages from child process properly
  • Loading branch information
frandiox committed Apr 11, 2024
1 parent 052eb14 commit 94a0c63
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/cli/src/lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -76,23 +84,19 @@ 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});
});

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);
}
});

Expand All @@ -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,
Expand Down

0 comments on commit 94a0c63

Please sign in to comment.