Skip to content

Commit

Permalink
[FIX] ProjectGraph: Improve error message when adding duplicate proje…
Browse files Browse the repository at this point in the history
…cts or extensions
  • Loading branch information
RandomByte committed Aug 25, 2023
1 parent b070972 commit 2b4a49e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/graph/ProjectGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class ProjectGraph {
const projectName = project.getName();
if (this._projects.has(projectName)) {
throw new Error(
`Failed to add project ${projectName} to graph: A project with that name has already been added`);
`Failed to add project ${projectName} to graph: A project with that name has already been added. ` +
`This might be caused by multiple modules containing projects with the same name`);
}
if (!isNaN(projectName)) {
// Reject integer-like project names. They would take precedence when traversing object keys which
Expand Down Expand Up @@ -126,7 +127,8 @@ class ProjectGraph {
if (this._extensions.has(extensionName)) {
throw new Error(
`Failed to add extension ${extensionName} to graph: ` +
`An extension with that name has already been added`);
`An extension with that name has already been added. ` +
`This might be caused by multiple modules containing extensions with the same name`);
}
if (!isNaN(extensionName)) {
// Reject integer-like extension names. They would take precedence when traversing object keys which
Expand Down
6 changes: 4 additions & 2 deletions test/lib/graph/ProjectGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ test("addProject: Add duplicate", async (t) => {
graph.addProject(project2);
});
t.is(error.message,
"Failed to add project application.a to graph: A project with that name has already been added",
"Failed to add project application.a to graph: A project with that name has already been added. " +
"This might be caused by multiple modules containing projects with the same name",
"Should throw with expected error message");

const res = graph.getProject("application.a");
Expand Down Expand Up @@ -261,7 +262,8 @@ test("addExtension: Add duplicate", async (t) => {
graph.addExtension(extension2);
});
t.is(error.message,
"Failed to add extension extension.a to graph: An extension with that name has already been added",
"Failed to add extension extension.a to graph: An extension with that name has already been added. " +
"This might be caused by multiple modules containing extensions with the same name",
"Should throw with expected error message");

const res = graph.getExtension("extension.a");
Expand Down
4 changes: 3 additions & 1 deletion test/lib/graph/projectGraphBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,8 @@ test("Multiple dependencies to different module containing the same extension",
}),
]);
await t.throwsAsync(projectGraphBuilder(t.context.provider), {
message: "Failed to add extension task-a to graph: An extension with that name has already been added"
message:
"Failed to add extension task-a to graph: An extension with that name has already been added. " +
"This might be caused by multiple modules containing extensions with the same name"
});
});

0 comments on commit 2b4a49e

Please sign in to comment.