Navigation Menu

Skip to content

Commit

Permalink
Support reporting on ERESOLVE errors when current is missing
Browse files Browse the repository at this point in the history
While it is somewhat helpful to get reports on this, since it indicates
an underlying problem in Arborist, it's also very disruptive and
unhelpful for users.  As of 2.3.0, Arborist gives us the currentEdge if
available, so we _can_ report on that at least.  If there is no node
_or_ edge, then we just don't say what the current state is, which isn't
useful, but at least is less annoying than a 'property of null'
exception.

PR-URL: #3015
Credit: @isaacs
Close: #3015
Reviewed-by: @wraithgar
  • Loading branch information
isaacs authored and wraithgar committed Apr 1, 2021
1 parent 9237d37 commit cb6eb0d
Show file tree
Hide file tree
Showing 3 changed files with 333 additions and 69 deletions.
11 changes: 9 additions & 2 deletions lib/utils/explain-eresolve.js
Expand Up @@ -15,13 +15,20 @@ const { explainEdge, explainNode, printNode } = require('./explain-dep.js')
// The full report (ie, depth=Infinity) is always written to the cache folder
// at ${cache}/eresolve-report.txt along with full json.
const explainEresolve = (expl, color, depth) => {
const { edge, current, peerConflict } = expl
const { edge, current, peerConflict, currentEdge } = expl

const out = []
if (edge.from && edge.from.whileInstalling)
out.push('While resolving: ' + printNode(edge.from.whileInstalling, color))

out.push('Found: ' + explainNode(current, depth, color))
// it "should" be impossible for an ERESOLVE explanation to lack both
// current and currentEdge, but better to have a less helpful error
// than a crashing failure.
if (current)
out.push('Found: ' + explainNode(current, depth, color))
else if (currentEdge)
out.push('Found: ' + explainEdge(currentEdge, depth, color))

out.push('\nCould not resolve dependency:\n' +
explainEdge(edge, depth, color))

Expand Down
182 changes: 182 additions & 0 deletions tap-snapshots/test-lib-utils-explain-eresolve.js-TAP.test.js
Expand Up @@ -418,6 +418,188 @@ to accept an incorrect (and potentially broken) dependency resolution.
See \${REPORT} for a full report.
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > explain with color 1`] = `
While resolving: eslint@7.22.0
Found: dev eslint@"file:." from the root project
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > explain with no color, depth of 6 1`] = `
While resolving: eslint@7.22.0
Found: dev eslint@"file:." from the root project
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report 1`] = `
# npm resolution error report
\${TIME}
While resolving: eslint@7.22.0
Found: dev eslint@"file:." from the root project
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
Raw JSON explanation object:
{
"name": "no current node, but has current edge",
"json": true
}
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report with color 1`] = `
While resolving: eslint@7.22.0
Found: dev eslint@"file:." from the root project
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
See \${REPORT} for a full report.
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report with color, depth only 2 1`] = `
While resolving: eslint@7.22.0
Found: dev eslint@"file:." from the root project
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
See \${REPORT} for a full report.
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report with no color, depth of 6 1`] = `
While resolving: eslint@7.22.0
Found: dev eslint@"file:." from the root project
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
See \${REPORT} for a full report.
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > explain with color 1`] = `
While resolving: eslint@7.22.0
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > explain with no color, depth of 6 1`] = `
While resolving: eslint@7.22.0
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report 1`] = `
# npm resolution error report
\${TIME}
While resolving: eslint@7.22.0
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
Raw JSON explanation object:
{
"name": "no current node, no current edge, idk",
"json": true
}
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report with color 1`] = `
While resolving: eslint@7.22.0
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
See \${REPORT} for a full report.
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report with color, depth only 2 1`] = `
While resolving: eslint@7.22.0
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
See \${REPORT} for a full report.
`

exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report with no color, depth of 6 1`] = `
While resolving: eslint@7.22.0
Could not resolve dependency:
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
node_modules/eslint-plugin-jsdoc
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
Fix the upstream dependency conflict, or retry
this command with --force, or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
See \${REPORT} for a full report.
`

exports[`test/lib/utils/explain-eresolve.js TAP withShrinkwrap > explain with color 1`] = `
While resolving: @isaacs/peer-dep-cycle-b@1.0.0
Found: @isaacs/peer-dep-cycle-c@2.0.0
Expand Down

0 comments on commit cb6eb0d

Please sign in to comment.