Skip to content

Commit

Permalink
fix(core): ensure tuple passed to aggregate create nodes error (#26456)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored Jun 7, 2024
1 parent 08a0e5c commit 8891bdc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
15 changes: 15 additions & 0 deletions packages/nx/src/project-graph/error-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ export class AggregateCreateNodesError extends Error {
) {
super('Failed to create nodes');
this.name = this.constructor.name;
if (
// Errors should be an array
!Array.isArray(errors) ||
!errors.every(
// Where every element is a tuple
(errorTuple) =>
Array.isArray(errorTuple) &&
// That has a length of 2
errorTuple.length === 2
)
) {
throw new Error(
'AggregateCreateNodesError must be constructed with an array of tuples where the first element is a filename or undefined and the second element is the underlying error.'
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/project-graph/plugins/internal-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class LoadedNxPlugin {
throw e;
}
// The underlying plugin errored out. We can't know any partial results.
throw new AggregateCreateNodesError([null, e], []);
throw new AggregateCreateNodesError([[null, e]], []);
} finally {
performance.mark(`${plugin.name}:createNodes - end`);
performance.measure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,14 @@ export async function createProjectConfigurations(
: // This represents a single plugin erroring out with a hard error.
new AggregateCreateNodesError([[null, e]], []);

errorBodyLines.push(
...error.errors.map(([file, e]) => ` - ${file}: ${e.message}`)
);
const innerErrors = error.errors;
for (const [file, e] of innerErrors) {
if (file) {
errorBodyLines.push(` - ${file}: ${e.message}`);
} else {
errorBodyLines.push(` - ${e.message}`);
}
}

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

Expand Down

0 comments on commit 8891bdc

Please sign in to comment.