Skip to content

Commit 77e60c3

Browse files
authored
fix(core): log more information when ProjectConfigurationsError is thrown (#30661)
## Current Behavior When the `ProjectConfigurationsError` is thrown, no helpful information is logged. ## Expected Behavior When the `ProjectConfigurationsError` is thrown, helpful information should be logged. It replicates the handling previously done for `ProjectGraphError`. ## Related Issue(s) Fixes #
1 parent c71a783 commit 77e60c3

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

packages/nx/src/project-graph/error-types.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,40 @@ export class ProjectConfigurationsError extends Error {
202202
>,
203203
public readonly partialProjectConfigurationsResult: ConfigurationResult
204204
) {
205-
super('Failed to create project configurations');
205+
const messageFragments = ['Failed to create project configurations.'];
206+
const mergeNodesErrors = [];
207+
const unknownErrors = [];
208+
for (const e of errors) {
209+
if (
210+
// Known error type, but unlikely to be caused by the user
211+
isMergeNodesError(e)
212+
) {
213+
mergeNodesErrors.push(e);
214+
} else if (
215+
// Known errors that are self-explanatory
216+
!isAggregateCreateNodesError(e) &&
217+
!isProjectsWithNoNameError(e) &&
218+
!isMultipleProjectsWithSameNameError(e)
219+
) {
220+
unknownErrors.push(e);
221+
}
222+
}
223+
if (mergeNodesErrors.length > 0) {
224+
messageFragments.push(
225+
`This type of error most likely points to an issue within Nx. Please report it.`
226+
);
227+
}
228+
if (unknownErrors.length > 0) {
229+
messageFragments.push(
230+
`If the error cause is not obvious from the below error messages, running "nx reset" may fix it. Please report the issue if you keep seeing it.`
231+
);
232+
}
233+
super(messageFragments.join(' '));
206234
this.name = this.constructor.name;
235+
this.errors = errors;
236+
this.stack = errors
237+
.map((error) => indentString(formatErrorStackAndCause(error), 2))
238+
.join('\n');
207239
}
208240
}
209241

packages/nx/src/utils/handle-errors.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ProjectGraphError } from '../project-graph/error-types';
1+
import type {
2+
ProjectConfigurationsError,
3+
ProjectGraphError,
4+
} from '../project-graph/error-types';
25
import { logger } from './logger';
36
import { output } from './output';
47

@@ -33,6 +36,23 @@ export async function handleErrors(
3336
? formatErrorStackAndCause(projectGraphError, isVerbose)
3437
: projectGraphError.getErrors().map((e) => e.message),
3538
});
39+
} else if (err.name === 'ProjectConfigurationsError') {
40+
const projectConfigurationsError = err as ProjectConfigurationsError;
41+
let title = projectConfigurationsError.message;
42+
if (
43+
projectConfigurationsError.cause &&
44+
typeof projectConfigurationsError.cause === 'object' &&
45+
'message' in projectConfigurationsError.cause
46+
) {
47+
title += ' ' + projectConfigurationsError.cause.message + '.';
48+
}
49+
50+
output.error({
51+
title,
52+
bodyLines: isVerbose
53+
? formatErrorStackAndCause(projectConfigurationsError, isVerbose)
54+
: projectConfigurationsError.errors.map((e) => e.message),
55+
});
3656
} else {
3757
const lines = (err.message ? err.message : err.toString()).split('\n');
3858
const bodyLines: string[] = lines.slice(1);

0 commit comments

Comments
 (0)