Skip to content

Commit 95f851c

Browse files
AgentEnderFrozenPandaz
authored andcommitted
fix(core): ensure better create nodes error messaging (#26811)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior We see a stack trace pointing to where the aggregate create nodes error is thrown rather than the messaging about the individual errors <img width="911" alt="image" src="https://github.com/nrwl/nx/assets/6933928/61907d8c-bb77-4a39-b55f-42fa38c0ed19"> ## Expected Behavior The message is shown <img width="946" alt="image" src="https://github.com/nrwl/nx/assets/6933928/f79f5aeb-e5b2-4ff1-9cbc-a7f10e8f910e"> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # (cherry picked from commit 3cbe2ab)
1 parent 3493ef7 commit 95f851c

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

packages/nx/src/project-graph/plugins/isolation/messaging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export interface PluginCreateMetadataResult {
106106
}
107107
| {
108108
success: false;
109-
error: string;
109+
error: Error;
110110
tx: string;
111111
};
112112
}

packages/nx/src/project-graph/plugins/isolation/plugin-worker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ const server = createServer((socket) => {
121121
} catch (e) {
122122
return {
123123
type: 'createMetadataResult',
124-
payload: { success: false, error: e.stack, tx },
124+
payload: {
125+
success: false,
126+
error: createSerializableError(e),
127+
tx,
128+
},
125129
};
126130
}
127131
},

packages/nx/src/project-graph/utils/project-configuration-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,11 @@ export async function createProjectConfigurations(
393393
} else {
394394
errorBodyLines.push(` - ${e.message}`);
395395
}
396+
const innerStackTrace = ' ' + e.stack.split('\n').join('\n ');
397+
errorBodyLines.push(innerStackTrace);
396398
}
397399

398-
error.message = errorBodyLines.join('\n');
400+
error.stack = errorBodyLines.join('\n');
399401

400402
// This represents a single plugin erroring out with a hard error.
401403
errors.push(error);

packages/nx/src/utils/serializable-error.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export function createSerializableError<T extends Error>(error: T): T {
1717
value = value.map((v) => {
1818
if (typeof v === 'object' && v instanceof Error) {
1919
return createSerializableError(v);
20+
// Support for AggregateCreateNodesError
21+
} else if (
22+
Array.isArray(v) &&
23+
v.length === 2 &&
24+
v[1] instanceof Error
25+
) {
26+
return [v[0], createSerializableError(v[1])];
2027
}
2128
return v;
2229
});

0 commit comments

Comments
 (0)