Permalink
Browse files

packager: Server: more consistent error handling

Reviewed By: cpojer

Differential Revision: D5137887

fbshipit-source-id: fe73f9a74ac7091fcad66d91859e2ff90733ce45
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed May 30, 2017
1 parent dfb0812 commit 994d500b5af7d809bbcedc032697fd2415e794ea
Showing with 24 additions and 8 deletions.
  1. +6 −4 packager/src/Server/index.js
  2. +15 −3 packager/src/lib/TerminalReporter.js
  3. +3 −1 packager/src/lib/reporting.js
@@ -507,7 +507,6 @@ class Server {
}, error => {
this._reporter.update({
entryFilePath: options.entryFile,
error,
type: 'bundle_build_failed',
});
return Promise.reject(error);
@@ -800,9 +799,11 @@ class Server {
'Content-Type': 'application/json; charset=UTF-8',
});
if (error.type === 'TransformError' ||
error.type === 'NotFoundError' ||
error.type === 'UnableToResolveError') {
if (error instanceof Error && (
error.type === 'TransformError' ||
error.type === 'NotFoundError' ||
error.type === 'UnableToResolveError'
)) {
error.errors = [{
description: error.description,
filename: error.filename,
@@ -813,6 +814,7 @@ class Server {
if (error.type === 'NotFoundError') {
delete this._bundles[bundleID];
}
this._reporter.update({error, type: 'bundling_error'});
} else {
console.error(error.stack || error);
res.end(JSON.stringify({
@@ -126,8 +126,7 @@ class TerminalReporter {
}
}
_logBundleBuildFailed(entryFilePath: string, error: Error) {
reporting.logError(terminal, 'bundling: %s', error.stack);
_logBundleBuildFailed(entryFilePath: string) {
const progress = this._activeBundles.get(entryFilePath);
if (progress != null) {
const msg = this._getBundleStatusMessage(entryFilePath, progress, 'failed');
@@ -201,7 +200,10 @@ class TerminalReporter {
this._logBundleBuildDone(event.entryFilePath);
break;
case 'bundle_build_failed':
this._logBundleBuildFailed(event.entryFilePath, event.error);
this._logBundleBuildFailed(event.entryFilePath);
break;
case 'bundling_error':
this._logBundlingError(event.error);
break;
case 'dep_graph_loaded':
terminal.log(`${DEP_GRAPH_MESSAGE}, done.`);
@@ -221,6 +223,16 @@ class TerminalReporter {
}
}
/**
* We do not want to log the whole stacktrace for bundling error, because
* these are operational errors, not programming errors, and the stacktrace
* is not actionable to end users.
*/
_logBundlingError(error: Error) {
const str = JSON.stringify(error.message);
reporting.logError(terminal, 'bundling failed: %s', str);
}
_logWorkerChunk(origin: 'stdout' | 'stderr', chunk: string) {
const lines = chunk.split('\n');
if (lines.length >= 1 && lines[lines.length - 1] === '') {
@@ -37,11 +37,13 @@ export type ReportableEvent = {
type: 'bundle_build_done',
} | {
entryFilePath: string,
error: Error,
type: 'bundle_build_failed',
} | {
entryFilePath: string,
type: 'bundle_build_started',
} | {
error: Error,
type: 'bundling_error',
} | {
type: 'dep_graph_loading',
} | {

0 comments on commit 994d500

Please sign in to comment.