diff --git a/packages/nx/src/project-graph/error-types.ts b/packages/nx/src/project-graph/error-types.ts index 74ce2f39b40f0..795e1c3d0cfbd 100644 --- a/packages/nx/src/project-graph/error-types.ts +++ b/packages/nx/src/project-graph/error-types.ts @@ -42,14 +42,7 @@ export class ProjectGraphError extends Error { this.#partialProjectGraph = partialProjectGraph; this.#partialSourceMaps = partialSourceMaps; this.stack = `${this.message}\n ${errors - .map((error) => { - if (isAggregateCreateNodesError(error)) { - // AggregateCreateNodesError has a custom error message that shows more detail than the stack. - return error.message; - } else { - return error.stack.split('\n').join('\n '); - } - }) + .map((error) => error.stack.split('\n').join('\n ')) .join('\n')}`; } diff --git a/packages/nx/src/project-graph/plugins/isolation/messaging.ts b/packages/nx/src/project-graph/plugins/isolation/messaging.ts index bafc17fd32551..7b27e92f46a0c 100644 --- a/packages/nx/src/project-graph/plugins/isolation/messaging.ts +++ b/packages/nx/src/project-graph/plugins/isolation/messaging.ts @@ -106,7 +106,7 @@ export interface PluginCreateMetadataResult { } | { success: false; - error: string; + error: Error; tx: string; }; } diff --git a/packages/nx/src/project-graph/plugins/isolation/plugin-worker.ts b/packages/nx/src/project-graph/plugins/isolation/plugin-worker.ts index 0303021a83da1..e032128ccba2a 100644 --- a/packages/nx/src/project-graph/plugins/isolation/plugin-worker.ts +++ b/packages/nx/src/project-graph/plugins/isolation/plugin-worker.ts @@ -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, + }, }; } }, diff --git a/packages/nx/src/project-graph/utils/project-configuration-utils.ts b/packages/nx/src/project-graph/utils/project-configuration-utils.ts index 20da0e6b61bbc..e1a38c2c12eaf 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -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); diff --git a/packages/nx/src/utils/serializable-error.ts b/packages/nx/src/utils/serializable-error.ts index bdef0aa7fffb2..9848dd1819566 100644 --- a/packages/nx/src/utils/serializable-error.ts +++ b/packages/nx/src/utils/serializable-error.ts @@ -17,6 +17,13 @@ export function createSerializableError(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; });