Skip to content

Commit

Permalink
feat(build): when build fails -> print an error with a stacktrace (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
jukben authored and satya164 committed Nov 2, 2017
1 parent 03e63f6 commit ccdaf20
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/commands/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ async function bundle(opts: *) {
const stats = await new Promise((resolve, reject) =>
compiler.run((err, info) => {
if (err || info.hasErrors()) {
reject(new MessageError(messages.bundleFailed()));
reject(
new MessageError(
messages.bundleFailed({
errors: err
? [err.message]
: info.toJson({ errorDetails: true }).errors,
})
)
);
} else {
resolve(info);
}
Expand Down
6 changes: 5 additions & 1 deletion src/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ async function start(opts: *) {
stats => {
clear();
if (stats.hasErrors()) {
logger.error(messages.bundleFailed());
logger.error(
messages.bundleFailed({
errors: stats.toJson({ errorDetails: true }).errors,
})
);
} else {
logger.done(
messages.bundleBuilt({
Expand Down
9 changes: 8 additions & 1 deletion src/messages/bundleFailed.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@
*
* @flow
*/
const dedent = require('dedent');

module.exports = () => 'Failed to compile';
module.exports = ({ errors }: { errors: string[] }) => {
return dedent`
Failed to compile.
${errors.join('\n\n')}
`;
};
4 changes: 4 additions & 0 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function createServer(
lazy: false,
noInfo: true,
reporter: null,
/**
* Quiet the default errors, we will handle error by our own
*/
quiet: true,
stats: 'errors-only',
hot: true,
mimeTypes: { 'application/javascript': ['bundle'] },
Expand Down

1 comment on commit ccdaf20

@Titozzz
Copy link

@Titozzz Titozzz commented on ccdaf20 Nov 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this on warnings too 😢

Please sign in to comment.