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

feat(core): create structured project graph errors with all plugin er… #22404

Merged
merged 1 commit into from
Mar 21, 2024

Conversation

FrozenPandaz
Copy link
Collaborator

@FrozenPandaz FrozenPandaz commented Mar 19, 2024

…rors

Current Behavior

When an error is thrown while creating a part of the project graph, the rest of the project graph is not created. The underlying error is thrown immediately.

Expected Behavior

When an error is thrown when creating a part of the project graph, the error is stored and thrown later. These errors are all exposed via the ProjectGraphError class which will contain a few things:

  1. A partial project graph
  2. The partial source maps
  3. The underlying errors

This error is still a legitimate error but in some cases it could be handled.

Most processes likely need the full project graph so the error will be printed out. The full stacktraces are hidden unless --verbose is passed.

For example, in the graph app such as the graph or the project details view, we can still show the partial graph or the partial project.

~/p/nx-examples (master↑1|●1✚3) $ nx lint cart

 NX   Failed to process project graph.

Pass --verbose to see the stacktraces.

~/p/nx-examples (master↑1|●1✚3) $ nx lint cart --verbose

 NX   Failed to process project graph. See errors below.

Failed to process project graph.
  The "@nx/jest/plugin" plugin threw an error while creating nodes from apps/cart/jest.config.ts:
    Error: Jest: Failed to parse the TypeScript config file /home/jason/projects/nx-examples/apps/cart/jest.config.ts
      TSError: ⨯ Unable to compile TypeScript:
    apps/cart/jest.config.ts(9,12): error TS1109: Expression expected.
    
        at readConfigFileAndSetRootDir (/home/jason/projects/nx-examples/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:116:13)
        at async readInitialOptions (/home/jason/projects/nx-examples/node_modules/jest-config/build/index.js:403:13)
        at async readConfig (/home/jason/projects/nx-examples/node_modules/jest-config/build/index.js:147:48)
        at async buildJestTargets (/home/jason/projects/nx-examples/node_modules/@nx/jest/src/plugins/plugin.js:71:20)
        at async exports.createNodes (/home/jason/projects/nx-examples/node_modules/@nx/jest/src/plugins/plugin.js:58:14)
        at async Promise.all (index 0)
        at async Promise.all (index 3)
        at async processFilesAndCreateAndSerializeProjectGraph (/home/jason/projects/nx-examples/node_modules/nx/src/daemon/server/project-graph-incremental-recomputation.js:148:26)
        at async handleRequestProjectGraph (/home/jason/projects/nx-examples/node_modules/nx/src/daemon/server/handle-request-project-graph.js:12:24)
        at async handleResult (/home/jason/projects/nx-examples/node_modules/nx/src/daemon/server/server.js:110:16)

Related Issue(s)

Fixes #

Copy link

vercel bot commented Mar 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview Mar 21, 2024 6:49pm

@FrozenPandaz FrozenPandaz force-pushed the graph-errors branch 3 times, most recently from 8527813 to 6dad954 Compare March 21, 2024 14:57
@FrozenPandaz FrozenPandaz marked this pull request as ready for review March 21, 2024 16:09
@FrozenPandaz FrozenPandaz requested review from a team as code owners March 21, 2024 16:09
Copy link
Member

@AgentEnder AgentEnder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments

Comment on lines +357 to 393
export class ProcessDependenciesError extends Error {
constructor(public readonly pluginName: string, { cause }) {
super(
`The "${pluginName}" plugin threw an error while creating dependencies:`,
{
cause,
}
);
this.name = this.constructor.name;
this.stack = `${this.message}\n ${cause.stack.split('\n').join('\n ')}`;
}
}

export class ProcessProjectGraphError extends Error {
constructor(public readonly pluginName: string, { cause }) {
super(
`The "${pluginName}" plugin threw an error while processing the project graph:`,
{
cause,
}
);
this.name = this.constructor.name;
this.stack = `${this.message}\n ${cause.stack.split('\n').join('\n ')}`;
}
}

export class CreateDependenciesError extends Error {
constructor(
public readonly errors: Array<
ProcessDependenciesError | ProcessProjectGraphError
>,
public readonly partialProjectGraph: ProjectGraph
) {
super('Failed to create dependencies. See above for errors');
this.name = this.constructor.name;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

followup: move to be near CreateNodesError, consider devkit export

@FrozenPandaz FrozenPandaz merged commit 7849e66 into nrwl:master Mar 21, 2024
4 of 6 checks passed
@FrozenPandaz FrozenPandaz deleted the graph-errors branch March 21, 2024 19:54
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants