packager: Server: more consistent error handling

Reviewed By: cpojer

Differential Revision: D5137887

fbshipit-source-id: fe73f9a74ac7091fcad66d91859e2ff90733ce45
This commit is contained in:
Jean Lauliac 2017-05-30 06:17:23 -07:00 committed by Facebook Github Bot
parent e554efaee4
commit 90824bdd98
3 changed files with 24 additions and 8 deletions

View File

@ -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({

View File

@ -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] === '') {

View File

@ -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',
} | {