packager: Server: more consistent error handling
Reviewed By: cpojer Differential Revision: D5137887 fbshipit-source-id: fe73f9a74ac7091fcad66d91859e2ff90733ce45
This commit is contained in:
parent
dfb081282f
commit
994d500b5a
|
@ -507,7 +507,6 @@ class Server {
|
||||||
}, error => {
|
}, error => {
|
||||||
this._reporter.update({
|
this._reporter.update({
|
||||||
entryFilePath: options.entryFile,
|
entryFilePath: options.entryFile,
|
||||||
error,
|
|
||||||
type: 'bundle_build_failed',
|
type: 'bundle_build_failed',
|
||||||
});
|
});
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
@ -800,9 +799,11 @@ class Server {
|
||||||
'Content-Type': 'application/json; charset=UTF-8',
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error.type === 'TransformError' ||
|
if (error instanceof Error && (
|
||||||
error.type === 'NotFoundError' ||
|
error.type === 'TransformError' ||
|
||||||
error.type === 'UnableToResolveError') {
|
error.type === 'NotFoundError' ||
|
||||||
|
error.type === 'UnableToResolveError'
|
||||||
|
)) {
|
||||||
error.errors = [{
|
error.errors = [{
|
||||||
description: error.description,
|
description: error.description,
|
||||||
filename: error.filename,
|
filename: error.filename,
|
||||||
|
@ -813,6 +814,7 @@ class Server {
|
||||||
if (error.type === 'NotFoundError') {
|
if (error.type === 'NotFoundError') {
|
||||||
delete this._bundles[bundleID];
|
delete this._bundles[bundleID];
|
||||||
}
|
}
|
||||||
|
this._reporter.update({error, type: 'bundling_error'});
|
||||||
} else {
|
} else {
|
||||||
console.error(error.stack || error);
|
console.error(error.stack || error);
|
||||||
res.end(JSON.stringify({
|
res.end(JSON.stringify({
|
||||||
|
|
|
@ -126,8 +126,7 @@ class TerminalReporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_logBundleBuildFailed(entryFilePath: string, error: Error) {
|
_logBundleBuildFailed(entryFilePath: string) {
|
||||||
reporting.logError(terminal, 'bundling: %s', error.stack);
|
|
||||||
const progress = this._activeBundles.get(entryFilePath);
|
const progress = this._activeBundles.get(entryFilePath);
|
||||||
if (progress != null) {
|
if (progress != null) {
|
||||||
const msg = this._getBundleStatusMessage(entryFilePath, progress, 'failed');
|
const msg = this._getBundleStatusMessage(entryFilePath, progress, 'failed');
|
||||||
|
@ -201,7 +200,10 @@ class TerminalReporter {
|
||||||
this._logBundleBuildDone(event.entryFilePath);
|
this._logBundleBuildDone(event.entryFilePath);
|
||||||
break;
|
break;
|
||||||
case 'bundle_build_failed':
|
case 'bundle_build_failed':
|
||||||
this._logBundleBuildFailed(event.entryFilePath, event.error);
|
this._logBundleBuildFailed(event.entryFilePath);
|
||||||
|
break;
|
||||||
|
case 'bundling_error':
|
||||||
|
this._logBundlingError(event.error);
|
||||||
break;
|
break;
|
||||||
case 'dep_graph_loaded':
|
case 'dep_graph_loaded':
|
||||||
terminal.log(`${DEP_GRAPH_MESSAGE}, done.`);
|
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) {
|
_logWorkerChunk(origin: 'stdout' | 'stderr', chunk: string) {
|
||||||
const lines = chunk.split('\n');
|
const lines = chunk.split('\n');
|
||||||
if (lines.length >= 1 && lines[lines.length - 1] === '') {
|
if (lines.length >= 1 && lines[lines.length - 1] === '') {
|
||||||
|
|
|
@ -37,11 +37,13 @@ export type ReportableEvent = {
|
||||||
type: 'bundle_build_done',
|
type: 'bundle_build_done',
|
||||||
} | {
|
} | {
|
||||||
entryFilePath: string,
|
entryFilePath: string,
|
||||||
error: Error,
|
|
||||||
type: 'bundle_build_failed',
|
type: 'bundle_build_failed',
|
||||||
} | {
|
} | {
|
||||||
entryFilePath: string,
|
entryFilePath: string,
|
||||||
type: 'bundle_build_started',
|
type: 'bundle_build_started',
|
||||||
|
} | {
|
||||||
|
error: Error,
|
||||||
|
type: 'bundling_error',
|
||||||
} | {
|
} | {
|
||||||
type: 'dep_graph_loading',
|
type: 'dep_graph_loading',
|
||||||
} | {
|
} | {
|
||||||
|
|
Loading…
Reference in New Issue