Commit 3d5b4cd
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.
Signed-off-by: sangwook <rewq5991@gmail.com>1 parent 8d3245e commit 3d5b4cd
3 files changed
Lines changed: 35 additions & 14 deletions
File tree
- lib/internal/modules/cjs
- test
- parallel
- sequential
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
565 | | - | |
566 | 565 | | |
567 | 566 | | |
568 | 567 | | |
| |||
1475 | 1474 | | |
1476 | 1475 | | |
1477 | 1476 | | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
1478 | 1485 | | |
1479 | 1486 | | |
1480 | 1487 | | |
| |||
1487 | 1494 | | |
1488 | 1495 | | |
1489 | 1496 | | |
1490 | | - | |
| 1497 | + | |
1491 | 1498 | | |
1492 | 1499 | | |
1493 | 1500 | | |
1494 | 1501 | | |
1495 | 1502 | | |
1496 | 1503 | | |
1497 | 1504 | | |
1498 | | - | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
1499 | 1514 | | |
1500 | 1515 | | |
1501 | 1516 | | |
| |||
1504 | 1519 | | |
1505 | 1520 | | |
1506 | 1521 | | |
1507 | | - | |
1508 | | - | |
1509 | | - | |
1510 | | - | |
1511 | | - | |
1512 | | - | |
1513 | | - | |
1514 | | - | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
1515 | 1530 | | |
| 1531 | + | |
1516 | 1532 | | |
1517 | 1533 | | |
1518 | 1534 | | |
| |||
1552 | 1568 | | |
1553 | 1569 | | |
1554 | 1570 | | |
| 1571 | + | |
1555 | 1572 | | |
1556 | 1573 | | |
1557 | | - | |
| 1574 | + | |
1558 | 1575 | | |
1559 | 1576 | | |
1560 | 1577 | | |
1561 | 1578 | | |
1562 | 1579 | | |
1563 | 1580 | | |
1564 | | - | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
1565 | 1584 | | |
1566 | 1585 | | |
1567 | 1586 | | |
| |||
| 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