browserify / browserify/module-deps
How to retrieve the file where an error occurred?
- Dominant language
- JavaScript
- Stars
- 208
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to retrieve the file where an error occurred and all I'm able to catch is a standard JavaScript error with a message but not file.
For example:
> index.js
```javascript
const mdeps = require('module-deps');
const md = mdeps();
md.on('error', (e) => {
console.warn(e);
});
md.end({ file:'./main.js' });
```
> main.js
```javascript
require('./partial'); // ./partial exists
require('unknown'); // unknown doesn't
```
The error thrown is:
> Error: Cannot find module 'unknown' from '/home/ericmorand/Projects/module-deps-test'
Except by parsing the error message, which is not a serious option - and even this way I would not be able to get the file name, I can't find a way to retrieve the file where the error happened.
I thought that I would be able to catch the correct file by registering to the `file` event like this:
```javascript
const mdeps = require('module-deps');
const md = mdeps();
let currentFile;
md.on('file', (file) => {
currentFile = file;
});
md.on('error', (e) => {
console.warn(currentFile); // will print ./partial
console.warn(e);
});
md.end({ file:'./main.js' });
```
But the `currentFile` contains `./partial.js` because it is the latest file encountered successfully by module-deps. And it is not where the error happens.
Can someone point me to the solution?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.