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

fix(core): catch all lock file parsing/pruning errors and provide fallback #15158

Merged
merged 4 commits into from
Mar 7, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/nx/src/lock-file/npm-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../config/project-graph';
import { NormalizedPackageJson } from './utils/package-json';
import { defaultHashing } from '../hasher/hashing-impl';
import { output } from '../devkit-exports';

/**
* NPM
Expand Down Expand Up @@ -524,7 +525,13 @@ function nestMappedPackages(
});

if (initialSize === nestedNodes.size) {
throw Error('Loop detected while pruning. Please report this issue.');
output.error({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this reported so low? Shouldn't we have a try catch around parseLockFile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This error happens on pruning and although it should not fail anymore, we still want to show error log if it does so we can track it.

This is the only remaining place we anticipate that error might occur.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should catch even unanticipated errors.

Throwing an Error here is fine. But we should catch it higher up if the whole operation is not necessary (/ there is a workaround)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be an error again right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intention was to try not break the lock file creation, as even without a few packages missing the installation might still work.

But I guess it's safer to just return the root lock file.

title: 'An error occured while creating pruned lockfile',
bodyLines: [
'`npm ci` might fail due to missing dependencies in the lockfile. If this happens, please open an issue at `https://github.com/nrwl/nx/issues/new?template=1-bug.yml` and provide a reproduction.',
'You can still install your dependencies using full `npm install` that would override the pruned lockfile.',
],
});
} else {
nestMappedPackages(
invertedGraph,
Expand Down