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 tuple passed to aggregate create nodes error #26456

Merged
merged 1 commit into from
Jun 7, 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
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