Skip to content

Commit 69cd9cf

Browse files
committed
Support reporting on ERESOLVE errors when current is missing
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.
1 parent fb095a7 commit 69cd9cf

3 files changed

Lines changed: 333 additions & 69 deletions

File tree

lib/utils/explain-eresolve.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ const { explainEdge, explainNode, printNode } = require('./explain-dep.js')
1515
// The full report (ie, depth=Infinity) is always written to the cache folder
1616
// at ${cache}/eresolve-report.txt along with full json.
1717
const explainEresolve = (expl, color, depth) => {
18-
const { edge, current, peerConflict } = expl
18+
const { edge, current, peerConflict, currentEdge } = expl
1919

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

24-
out.push('Found: ' + explainNode(current, depth, color))
24+
// it "should" be impossible for an ERESOLVE explanation to lack both
25+
// current and currentEdge, but better to have a less helpful error
26+
// than a crashing failure.
27+
if (current)
28+
out.push('Found: ' + explainNode(current, depth, color))
29+
else if (currentEdge)
30+
out.push('Found: ' + explainEdge(currentEdge, depth, color))
31+
2532
out.push('\nCould not resolve dependency:\n' +
2633
explainEdge(edge, depth, color))
2734

tap-snapshots/test-lib-utils-explain-eresolve.js-TAP.test.js

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,188 @@ to accept an incorrect (and potentially broken) dependency resolution.
418418
See \${REPORT} for a full report.
419419
`
420420

421+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > explain with color 1`] = `
422+
While resolving: eslint@7.22.0
423+
Found: dev eslint@"file:." from the root project
424+
425+
Could not resolve dependency:
426+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
427+
node_modules/eslint-plugin-jsdoc
428+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
429+
`
430+
431+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > explain with no color, depth of 6 1`] = `
432+
While resolving: eslint@7.22.0
433+
Found: dev eslint@"file:." from the root project
434+
435+
Could not resolve dependency:
436+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
437+
node_modules/eslint-plugin-jsdoc
438+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
439+
`
440+
441+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report 1`] = `
442+
# npm resolution error report
443+
444+
\${TIME}
445+
446+
While resolving: eslint@7.22.0
447+
Found: dev eslint@"file:." from the root project
448+
449+
Could not resolve dependency:
450+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
451+
node_modules/eslint-plugin-jsdoc
452+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
453+
454+
Fix the upstream dependency conflict, or retry
455+
this command with --force, or --legacy-peer-deps
456+
to accept an incorrect (and potentially broken) dependency resolution.
457+
458+
Raw JSON explanation object:
459+
460+
{
461+
"name": "no current node, but has current edge",
462+
"json": true
463+
}
464+
465+
`
466+
467+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report with color 1`] = `
468+
While resolving: eslint@7.22.0
469+
Found: dev eslint@"file:." from the root project
470+
471+
Could not resolve dependency:
472+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
473+
node_modules/eslint-plugin-jsdoc
474+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
475+
476+
Fix the upstream dependency conflict, or retry
477+
this command with --force, or --legacy-peer-deps
478+
to accept an incorrect (and potentially broken) dependency resolution.
479+
480+
See \${REPORT} for a full report.
481+
`
482+
483+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report with color, depth only 2 1`] = `
484+
While resolving: eslint@7.22.0
485+
Found: dev eslint@"file:." from the root project
486+
487+
Could not resolve dependency:
488+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
489+
node_modules/eslint-plugin-jsdoc
490+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
491+
492+
Fix the upstream dependency conflict, or retry
493+
this command with --force, or --legacy-peer-deps
494+
to accept an incorrect (and potentially broken) dependency resolution.
495+
496+
See \${REPORT} for a full report.
497+
`
498+
499+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, but has current edge > report with no color, depth of 6 1`] = `
500+
While resolving: eslint@7.22.0
501+
Found: dev eslint@"file:." from the root project
502+
503+
Could not resolve dependency:
504+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
505+
node_modules/eslint-plugin-jsdoc
506+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
507+
508+
Fix the upstream dependency conflict, or retry
509+
this command with --force, or --legacy-peer-deps
510+
to accept an incorrect (and potentially broken) dependency resolution.
511+
512+
See \${REPORT} for a full report.
513+
`
514+
515+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > explain with color 1`] = `
516+
While resolving: eslint@7.22.0
517+
518+
Could not resolve dependency:
519+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
520+
node_modules/eslint-plugin-jsdoc
521+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
522+
`
523+
524+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > explain with no color, depth of 6 1`] = `
525+
While resolving: eslint@7.22.0
526+
527+
Could not resolve dependency:
528+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
529+
node_modules/eslint-plugin-jsdoc
530+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
531+
`
532+
533+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report 1`] = `
534+
# npm resolution error report
535+
536+
\${TIME}
537+
538+
While resolving: eslint@7.22.0
539+
540+
Could not resolve dependency:
541+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
542+
node_modules/eslint-plugin-jsdoc
543+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
544+
545+
Fix the upstream dependency conflict, or retry
546+
this command with --force, or --legacy-peer-deps
547+
to accept an incorrect (and potentially broken) dependency resolution.
548+
549+
Raw JSON explanation object:
550+
551+
{
552+
"name": "no current node, no current edge, idk",
553+
"json": true
554+
}
555+
556+
`
557+
558+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report with color 1`] = `
559+
While resolving: eslint@7.22.0
560+
561+
Could not resolve dependency:
562+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
563+
node_modules/eslint-plugin-jsdoc
564+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
565+
566+
Fix the upstream dependency conflict, or retry
567+
this command with --force, or --legacy-peer-deps
568+
to accept an incorrect (and potentially broken) dependency resolution.
569+
570+
See \${REPORT} for a full report.
571+
`
572+
573+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report with color, depth only 2 1`] = `
574+
While resolving: eslint@7.22.0
575+
576+
Could not resolve dependency:
577+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
578+
node_modules/eslint-plugin-jsdoc
579+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
580+
581+
Fix the upstream dependency conflict, or retry
582+
this command with --force, or --legacy-peer-deps
583+
to accept an incorrect (and potentially broken) dependency resolution.
584+
585+
See \${REPORT} for a full report.
586+
`
587+
588+
exports[`test/lib/utils/explain-eresolve.js TAP no current node, no current edge, idk > report with no color, depth of 6 1`] = `
589+
While resolving: eslint@7.22.0
590+
591+
Could not resolve dependency:
592+
peer eslint@"^6.0.0" from eslint-plugin-jsdoc@22.2.0
593+
node_modules/eslint-plugin-jsdoc
594+
dev eslint-plugin-jsdoc@"^22.1.0" from the root project
595+
596+
Fix the upstream dependency conflict, or retry
597+
this command with --force, or --legacy-peer-deps
598+
to accept an incorrect (and potentially broken) dependency resolution.
599+
600+
See \${REPORT} for a full report.
601+
`
602+
421603
exports[`test/lib/utils/explain-eresolve.js TAP withShrinkwrap > explain with color 1`] = `
422604
While resolving: @isaacs/peer-dep-cycle-b@1.0.0
423605
Found: @isaacs/peer-dep-cycle-c@2.0.0

0 commit comments

Comments
 (0)