From 2a085f0c1b9545de7c2e6f2c2e23f3292c3ee338 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Fri, 16 Jun 2017 09:27:09 -0700 Subject: [PATCH] Display snippets of TransformErrors Reviewed By: cpojer Differential Revision: D5247080 fbshipit-source-id: a0c4515476246e6da4c33c9129f6273af838d04f --- .../metro-bundler/src/lib/TerminalReporter.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/metro-bundler/src/lib/TerminalReporter.js b/packages/metro-bundler/src/lib/TerminalReporter.js index f7a87414..40626c6b 100644 --- a/packages/metro-bundler/src/lib/TerminalReporter.js +++ b/packages/metro-bundler/src/lib/TerminalReporter.js @@ -18,6 +18,7 @@ const reporting = require('./reporting'); const throttle = require('lodash/throttle'); const util = require('util'); +import type Transformer from '../JSTransformer'; import type {BundleOptions} from '../Server'; import type Terminal from './Terminal'; import type {ReportableEvent, GlobalCacheDisabledReason} from './reporting'; @@ -248,8 +249,21 @@ class TerminalReporter { * 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); + _logBundlingError(error: Error | Transformer.TransformError) { + //$FlowFixMe T19379628 + let message = error.message; + //$FlowFixMe T19379628 + if (error.filename && !message.includes(error.filename)) { + //$FlowFixMe T19379628 + message += ` [${error.filename}]`; + } + + let str = JSON.stringify(message); + if (error.snippet != null) { + //$FlowFixMe T19379628 + str += '\n' + error.snippet; + } + reporting.logError(this.terminal, 'bundling failed: %s', str); }