Skip to content

Commit b4df1f9

Browse files
committed
Fix duplicate file location line in error output
The extracted formatSourceCodeFrame helper included a filePath:line:column header, but this was already present in the issue title for the primary source. Added an includeLocation parameter: false for the primary source (location already in title), true for additional sources (need their own location header).
1 parent 77189f2 commit b4df1f9

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/next/src/shared/lib/turbopack/format-issue.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,27 @@ function formatFilePath(filePath: string): string {
1818
}
1919

2020
/**
21-
* Formats an IssueSource as a code frame with file location header.
21+
* Renders the code frame for an IssueSource (the highlighted snippet).
2222
* Returns empty string if the source has no range, no content, or
2323
* points to an internal (Next.js/React) file.
24+
*
25+
* When `includeLocation` is true, prepends a `filePath:line:column` header.
26+
* The primary source omits this (the location is already in the issue title),
27+
* while additional sources include it.
2428
*/
25-
function formatSourceCodeFrame(source: IssueSource, filePath: string): string {
29+
function formatSourceCodeFrame(
30+
source: IssueSource,
31+
filePath: string,
32+
includeLocation: boolean
33+
): string {
2634
if (!source.range || !source.source.content || isInternal(filePath)) {
2735
return ''
2836
}
2937
const { start, end } = source.range
30-
let result = `${formatFilePath(filePath)}:${start.line + 1}:${start.column + 1}\n`
38+
let result = ''
39+
if (includeLocation) {
40+
result += `${formatFilePath(filePath)}:${start.line + 1}:${start.column + 1}\n`
41+
}
3142
const frame = codeFrameColumns(
3243
source.source.content,
3344
{
@@ -76,7 +87,8 @@ export function formatIssue(issue: Issue) {
7687

7788
if (source) {
7889
// TODO(lukesandberg): move codeFrame formatting into turbopack, it would be more efficient than passing the source back and forth
79-
message += formatSourceCodeFrame(source, filePath)
90+
// Primary source: location is already in the message title above, so skip it here
91+
message += formatSourceCodeFrame(source, filePath, false)
8092
}
8193

8294
if (description) {
@@ -100,9 +112,11 @@ export function formatIssue(issue: Issue) {
100112

101113
// Render additional sources (e.g., generated code from a loader)
102114
for (const additional of issue.additionalSources ?? []) {
115+
// Additional sources need the location header since they aren't part of the title
103116
const codeFrame = formatSourceCodeFrame(
104117
additional.source,
105-
additional.source.source.filePath
118+
additional.source.source.filePath,
119+
true
106120
)
107121
if (codeFrame) {
108122
message += `${additional.description}:\n${codeFrame}`

0 commit comments

Comments
 (0)