Skip to content

Commit

Permalink
Print stack traces on error (#114)
Browse files Browse the repository at this point in the history
* Print stack traces on error

* Append the original error message

* Move try/catch

* Fix catch block

* Revert, only generate code frames on module error

* Better logic for error code frame generation
  • Loading branch information
shawwn authored and devongovett committed Dec 8, 2017
1 parent a678259 commit 4ab9b87
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,18 @@ class Bundler extends EventEmitter {
try {
return await this.resolveAsset(dep.name, asset.name);
} catch (err) {
err.message = `Cannot resolve dependency '${dep.name}'`;
if (err.message.indexOf(`Cannot find module '${dep.name}'`) === 0) {
err.message = `Cannot resolve dependency '${dep.name}'`;

// Generate a code frame where the dependency was used
if (dep.loc) {
await asset.loadIfNeeded();
err.loc = dep.loc;
err = asset.generateErrorMessage(err);
}

// Generate a code frame where the dependency was used
if (dep.loc) {
await asset.loadIfNeeded();
err.loc = dep.loc;
err = asset.generateErrorMessage(err);
err.fileName = asset.name;
}

err.fileName = asset.name;
throw err;
}
}
Expand Down

0 comments on commit 4ab9b87

Please sign in to comment.