Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): ensure better create nodes error messaging #26811

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export interface PluginCreateMetadataResult {
}
| {
success: false;
error: string;
error: Error;
tx: string;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ const server = createServer((socket) => {
} catch (e) {
return {
type: 'createMetadataResult',
payload: { success: false, error: e.stack, tx },
payload: {
success: false,
error: createSerializableError(e),
tx,
},
};
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,11 @@ export async function createProjectConfigurations(
} else {
errorBodyLines.push(` - ${e.message}`);
}
const innerStackTrace = ' ' + e.stack.split('\n').join('\n ');
errorBodyLines.push(innerStackTrace);
}

error.message = errorBodyLines.join('\n');
error.stack = errorBodyLines.join('\n');

// This represents a single plugin erroring out with a hard error.
errors.push(error);
Expand Down
7 changes: 7 additions & 0 deletions packages/nx/src/utils/serializable-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export function createSerializableError<T extends Error>(error: T): T {
value = value.map((v) => {
if (typeof v === 'object' && v instanceof Error) {
return createSerializableError(v);
// Support for AggregateCreateNodesError
} else if (
Array.isArray(v) &&
v.length === 2 &&
v[1] instanceof Error
) {
return [v[0], createSerializableError(v[1])];
}
return v;
});
Expand Down