Commit 7b29458
committed
module: add requireStack to all error paths
Previously, `requireStack` was only set on the final fallback error
in `Module._resolveFilename`. Errors thrown earlier in the resolution
pipeline β from `tryPackage` (via `Module._findPath`) when a
`package.json` `main` field points to a missing file, from `trySelf`
during self-referential package resolution, and from
`createEsmNotFoundErr` β did not include `requireStack`.
Fix this by building `requireStack` from the parent chain before any
resolution attempt and propagating it to all `MODULE_NOT_FOUND` error
paths:
- Wrap `trySelf` and `Module._findPath` calls in try-catch blocks
that attach `requireStack` to any thrown `MODULE_NOT_FOUND` error
that does not already have one.
- Add an optional `requireStack` parameter to `createEsmNotFoundErr`
and pass it from `_resolveFilename` where the error is thrown
directly.1 parent 6964b53 commit 7b29458
File tree
3 files changed
+35
-14
lines changed- lib/internal/modules/cjs
- test
- parallel
- sequential
3 files changed
+35
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
537 | | - | |
538 | 537 | | |
539 | 538 | | |
540 | 539 | | |
| |||
1406 | 1405 | | |
1407 | 1406 | | |
1408 | 1407 | | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
1409 | 1416 | | |
1410 | 1417 | | |
1411 | 1418 | | |
| |||
1419 | 1426 | | |
1420 | 1427 | | |
1421 | 1428 | | |
1422 | | - | |
| 1429 | + | |
1423 | 1430 | | |
1424 | 1431 | | |
1425 | 1432 | | |
| |||
1428 | 1435 | | |
1429 | 1436 | | |
1430 | 1437 | | |
1431 | | - | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
1432 | 1447 | | |
1433 | 1448 | | |
1434 | 1449 | | |
| |||
1437 | 1452 | | |
1438 | 1453 | | |
1439 | 1454 | | |
1440 | | - | |
1441 | | - | |
1442 | | - | |
1443 | | - | |
1444 | | - | |
1445 | | - | |
1446 | | - | |
1447 | | - | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
1448 | 1463 | | |
| 1464 | + | |
1449 | 1465 | | |
1450 | 1466 | | |
1451 | 1467 | | |
| |||
1485 | 1501 | | |
1486 | 1502 | | |
1487 | 1503 | | |
| 1504 | + | |
1488 | 1505 | | |
1489 | 1506 | | |
1490 | | - | |
| 1507 | + | |
1491 | 1508 | | |
1492 | 1509 | | |
1493 | 1510 | | |
1494 | 1511 | | |
1495 | 1512 | | |
1496 | 1513 | | |
1497 | | - | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
1498 | 1517 | | |
1499 | 1518 | | |
1500 | 1519 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
0 commit comments