From b2efda00a866c5e45484e4427d5f3dc14574395b Mon Sep 17 00:00:00 2001 From: Nick Lefever Date: Sun, 1 Mar 2026 17:49:19 -0800 Subject: [PATCH] Improve bundling error message formatting (#55794) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55794 Format the error messages coming from bundling to mainting the formatting and make these easier to read. Changelog: [Internal] Reviewed By: javache Differential Revision: D94611951 fbshipit-source-id: cbb8b2d1ff517b5487d4b799b1e2e3476629f84c --- private/react-native-fantom/runner/bundling.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/private/react-native-fantom/runner/bundling.js b/private/react-native-fantom/runner/bundling.js index cb57a93dc81..de334ec28cc 100644 --- a/private/react-native-fantom/runner/bundling.js +++ b/private/react-native-fantom/runner/bundling.js @@ -52,9 +52,19 @@ export async function createBundle(options: BundleOptions): Promise { ); if (lastBundleError || lastBundleResult?.ok !== true) { - throw new Error( - `Failed to request bundle from Metro: ${lastBundleError?.message ?? (await lastBundleResult?.text()) ?? ''}`, - ); + let errorMessage = + lastBundleError?.message ?? (await lastBundleResult?.text()) ?? ''; + + try { + const parsed = JSON.parse(errorMessage); + if (typeof parsed.message === 'string') { + errorMessage = parsed.message; + } + } catch { + // Not JSON — use the raw text as-is. + } + + throw new Error(`Failed to request bundle from Metro:\n${errorMessage}`); } await fs.promises.writeFile(