fix(core): recommend nx reset when graph errors and print error in da… (#23014)

This commit is contained in:
Jason Jean 2024-04-26 12:40:23 -04:00 committed by GitHub
parent e957d13715
commit 252070fd5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 3 deletions

View File

@ -5,6 +5,10 @@ import { serializeResult } from '../socket-utils';
import { deleteDaemonJsonProcessCache } from '../cache';
import type { Watcher } from '../../native';
import { cleanupPlugins } from './plugins';
import {
DaemonProjectGraphError,
ProjectGraphError,
} from '../../project-graph/error-types';
export const SERVER_INACTIVITY_TIMEOUT_MS = 10800000 as const; // 10800000 ms = 3 hours
@ -95,13 +99,19 @@ export async function respondWithErrorAndExit(
description: string,
error: Error
) {
const normalizedError =
error instanceof DaemonProjectGraphError
? ProjectGraphError.fromDaemonProjectGraphError(error)
: error;
// print some extra stuff in the error message
serverLogger.requestLog(
`Responding to the client with an error.`,
description,
error.message
normalizedError.message
);
console.error(error.stack);
console.error(normalizedError.stack);
// Respond with the original error
await respondToClient(socket, serializeResult(error, null, null), null);
}

View File

@ -32,7 +32,9 @@ export class ProjectGraphError extends Error {
partialProjectGraph: ProjectGraph,
partialSourceMaps: ConfigurationSourceMaps
) {
super(`Failed to process project graph.`);
super(
`Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.`
);
this.name = this.constructor.name;
this.#errors = errors;
this.#partialProjectGraph = partialProjectGraph;

View File

@ -6,6 +6,7 @@ import type {
} from '../config/workspace-json-project-json';
import { output } from './output';
import type { ProjectGraphError } from '../project-graph/error-types';
import { daemonClient } from '../daemon/client/client';
const LIST_CHOICE_DISPLAY_LIMIT = 10;
@ -126,6 +127,9 @@ export async function handleErrors(isVerbose: boolean, fn: Function) {
logger.info(err.stack);
}
}
if (daemonClient.enabled()) {
daemonClient.reset();
}
return 1;
}
}