Skip to content

Commit

Permalink
bootstrap: usable error on missing internal module
Browse files Browse the repository at this point in the history
Due to how bootstrap/loaders.js itself is loaded and invoked,
stacktraces from it are munged and no longer point back to the error
source.

That resulted in the following unhelpful error if an internal module
was missing or misnamed:

```
internal/bootstrap/loaders.js:190
  return mod.compile();
             ^

TypeError: Cannot read property 'compile' of undefined
```

This changes that to at least print the id that was attempted to be
loaded:

```
internal/bootstrap/loaders.js:189
  if (!mod) throw new TypeError(`Missing internal module '${id}'`);
            ^

TypeError: Missing internal module 'internal/a'
```
  • Loading branch information
Fishrock123 committed Sep 17, 2019
1 parent 3adec43 commit 9f804d1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/bootstrap/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ function nativeModuleRequire(id) {
}

const mod = NativeModule.map.get(id);
// Can't load the internal errors module from here, have to use a raw error.
// eslint-disable-next-line no-restricted-syntax
if (!mod) throw new TypeError(`Missing internal module '${id}'`);
return mod.compile();
}

Expand Down

0 comments on commit 9f804d1

Please sign in to comment.