question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

compile.run not propagating thrown errors

See original GitHub issue

Bug report

What is the current behavior? When using the node api, throwing an error within the compiler.run function does not propagate the error to the calling process:

// scripts/build.js
let compiler = webpack(compilerConfig);

compiler.run(function(err, stats) {
  if (err) {
    throw new Error(err);
    
  } else if (stats.hasErrors()) {
    throw new Error(stats.toString({ colors: true })); // Error not propagated
  }
});

// index.js
const result = spawnSync(
  'node',
  [require.resolve('./scripts/build.js')].concat(args),
  { stdio: 'inherit' }
);

process.exit(result.status); // result.status is always 0
break;

The only way I can produce a non-zero exit status is if I manually call process.exit(1) within the build.js code.

If the current behavior is a bug, please provide the steps to reproduce. Just throw an error in the compiler.run function

What is the expected behavior? The error should be propagated, and the exit status of the script should not be 0.

Other relevant information: webpack version: 4.26.0 Node.js version: 11.6.0 Operating System: Mac OSX Additional tools: n/a

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
webpack-botcommented, Aug 5, 2019

This issue had no activity for at least half a year.

It’s subject to automatic issue closing if there is no activity in the next 15 days.

1reaction
aryzingcommented, Aug 10, 2019

Still an issue I believe

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Error not propagated
You are throwing Exception in a Task. So, Exception is throwing in different thread. Try look at that question: What is the best...
Read more >
Exceptions and Error Handling, C++ FAQ
Writing code with error-return codes and tests is not free either. As a rule of thumb, exception handling is extremely cheap when you...
Read more >
Exception Propagation in Java
Only unchecked exceptions are propagated. Checked exceptions throw compilation error. In example below, If we omit the throws keyword from ...
Read more >
Top 15 C++ Exception handling mistakes and how to avoid ...
Mistake # 6: Not Throwing an exception by value​​ But if you do that, there are two issues – the exception you're trying...
Read more >
To throw or not to throw — error propagation in JS and TS
Everything starts from error propagation. The method with which an error is returned determines whether the application can continue functioning or it's better ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found