Skip to content

Commit

Permalink
fix(misc): ensure serializable error works with plugin iso
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jul 3, 2024
1 parent 734b4a1 commit 03465e2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
9 changes: 1 addition & 8 deletions packages/nx/src/project-graph/error-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}`;
}

Expand Down
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

0 comments on commit 03465e2

Please sign in to comment.