Unverified Commit b0641f12 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[turbopack] Improve internal error message when source map retrieval fails (#81508)

Mostly so that I know which source URL slipped through.
parent 535ba067
...@@ -1411,7 +1411,7 @@ pub async fn get_source_map_rope( ...@@ -1411,7 +1411,7 @@ pub async fn get_source_map_rope(
}, },
) )
} }
_ => bail!("Unknown url scheme"), _ => bail!("Unknown url scheme '{}'", url.scheme()),
}, },
Err(_) => (file_path.to_string(), None), Err(_) => (file_path.to_string(), None),
}; };
......
...@@ -716,5 +716,6 @@ ...@@ -716,5 +716,6 @@
"715": "Server Action \"%s\" was not found on the server. \\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action", "715": "Server Action \"%s\" was not found on the server. \\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action",
"716": "NEXT_DEVTOOLS_SIMULATED_ERROR", "716": "NEXT_DEVTOOLS_SIMULATED_ERROR",
"717": "Unsupported environment condition \"%s\" and react condition \"%s\". This is a bug in Next.js.", "717": "Unsupported environment condition \"%s\" and react condition \"%s\". This is a bug in Next.js.",
"718": "Invariant: projectDir is required for node runtime" "718": "Invariant: projectDir is required for node runtime",
"719": "Failed to get source map for '%s'. This is a bug in Next.js"
} }
...@@ -7,7 +7,6 @@ import { ...@@ -7,7 +7,6 @@ import {
} from '../../next-devtools/server/shared' } from '../../next-devtools/server/shared'
import { middlewareResponse } from '../../next-devtools/server/middleware-response' import { middlewareResponse } from '../../next-devtools/server/middleware-response'
import path from 'path' import path from 'path'
import url from 'url'
import { openFileInEditor } from '../../next-devtools/server/launch-editor' import { openFileInEditor } from '../../next-devtools/server/launch-editor'
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser' import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
import { import {
...@@ -21,7 +20,7 @@ import { ...@@ -21,7 +20,7 @@ import {
} from '../lib/source-maps' } from '../lib/source-maps'
import { getSourceMapFromFile } from './get-source-map-from-file' import { getSourceMapFromFile } from './get-source-map-from-file'
import { findSourceMap } from 'node:module' import { findSourceMap } from 'node:module'
import { pathToFileURL } from 'node:url' import { fileURLToPath, pathToFileURL } from 'node:url'
import { inspect } from 'node:util' import { inspect } from 'node:util'
function shouldIgnorePath(modulePath: string): boolean { function shouldIgnorePath(modulePath: string): boolean {
...@@ -302,7 +301,7 @@ async function createOriginalStackFrame( ...@@ -302,7 +301,7 @@ async function createOriginalStackFrame(
) { ) {
normalizedStackFrameLocation = path.relative( normalizedStackFrameLocation = path.relative(
projectPath, projectPath,
url.fileURLToPath(normalizedStackFrameLocation) fileURLToPath(normalizedStackFrameLocation)
) )
} }
...@@ -432,11 +431,15 @@ export function getSourceMapMiddleware(project: Project) { ...@@ -432,11 +431,15 @@ export function getSourceMapMiddleware(project: Project) {
try { try {
// Turbopack chunk filenames might be URL-encoded. // Turbopack chunk filenames might be URL-encoded.
filename = decodeURI(filename) filename = decodeURI(filename)
} catch {
return middlewareResponse.badRequest(res)
}
if (path.isAbsolute(filename)) { if (path.isAbsolute(filename)) {
filename = url.pathToFileURL(filename).href filename = pathToFileURL(filename).href
} }
try {
const sourceMapString = await project.getSourceMap(filename) const sourceMapString = await project.getSourceMap(filename)
if (sourceMapString) { if (sourceMapString) {
...@@ -450,8 +453,16 @@ export function getSourceMapMiddleware(project: Project) { ...@@ -450,8 +453,16 @@ export function getSourceMapMiddleware(project: Project) {
return middlewareResponse.json(res, sourceMap) return middlewareResponse.json(res, sourceMap)
} }
} }
} catch (error) { } catch (cause) {
console.error('Failed to get source map:', error) return middlewareResponse.internalServerError(
res,
new Error(
`Failed to get source map for '${filename}'. This is a bug in Next.js`,
{
cause,
}
)
)
} }
middlewareResponse.noContent(res) middlewareResponse.noContent(res)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment