Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit with code 1 when build fails #55

Merged
merged 1 commit into from
Mar 29, 2017

Conversation

despairblue
Copy link
Contributor

fixes #54

@despairblue
Copy link
Contributor Author

This is probably a breaking change, if people relied on the fact that backback exited with code 0 on failure.

@jaredpalmer
Copy link
Owner

This is from another project we use internally... will this work?

....

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
  throw err;
});

compile(serverConfig, (err, serverStats) => {
  handleWebpackErrors(err, serverStats)
  console.log(chalk.green('Compiled successfully'))
})

// Wrap webpack compile in a try catch.
function compile(config, cb) {
  let compiler;
  try {
    compiler = webpack(config);
  } catch (e) {
    printErrors('Failed to compile.', [e]);
    process.exit(1);
  }
  compiler.run((err, stats) => {
    cb(err, stats);
  });
}

// Print out errors
function printErrors(summary, errors) {
  console.log(chalk.red(summary));
  console.log();
  errors.forEach(err => {
    console.log(err.message || err);
    console.log();
  });
}

// Gracefully handle errors and print them to console.
function handleWebpackErrors(err, stats) {
  if (err) {
    printErrors('Failed to compile.', [err]);
    process.exit(1);
  }

  if (stats.compilation.errors && stats.compilation.errors.length) {
    printErrors('Failed to compile.', stats.compilation.errors);
    process.exit(1);
  }
  if (
    process.env.CI &&
    stats.compilation.warnings &&
    stats.compilation.warnings.length
  ) {
    printErrors(
      'Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.',
      stats.compilation.warnings
    );
    process.exit(1);
  }
}

@despairblue
Copy link
Contributor Author

@jaredpalmer Yeah that works as well, but it will duplicate the output in the error case:
screen shot 2017-03-29 at 19 06 24

@jaredpalmer
Copy link
Owner

@despairblue yeah, i pulled it from a project that has a custom webpack logging plugin. Forgot that backpack has that totally baked in tbh.

@despairblue
Copy link
Contributor Author

@jaredpalmer So how are we going to proceed from here? 😄
Should I change anything?

@jaredpalmer jaredpalmer merged commit 9a95006 into jaredpalmer:master Mar 29, 2017
@despairblue
Copy link
Contributor Author

@jaredpalmer hey, is anything holding back a new release? Can I help somehow?

@jaredpalmer
Copy link
Owner

@despairblue done.

@despairblue
Copy link
Contributor Author

You are awesome, I was just running yarn upgrade-interactive again and wondering if I just missed it in the output the first time 😄

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

exit code is 0 when build failed
2 participants