Skip to content

Commit 9968d94

Browse files
fix(web): terminal links open bash, PHP and Perl error paths at their line (#47119)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 515b8c9 commit 9968d94

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

‎apps/web/src/terminal-links.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,18 @@ describe("extractTerminalLinks", () => {
296296
]);
297297
});
298298
299+
it.each([
300+
["/home/dev/app/run.sh: line 3: foo: command not found", "/home/dev/app/run.sh"],
301+
["PHP Warning: x in /home/dev/app/index.php on line 12", "/home/dev/app/index.php"],
302+
['syntax error at /home/dev/app/job.pl line 7, near "}"', "/home/dev/app/job.pl"],
303+
])("opens the path at the line the words after it name in %s", (line, path) => {
304+
const start = line.indexOf(path);
305+
const row = /line (\d+)/.exec(line)?.[1];
306+
expect(extractTerminalLinks(line)).toEqual([
307+
{ kind: "path", text: `${path}:${row}`, start, end: start + path.length },
308+
]);
309+
});
310+
299311
it("keeps the position a quoted traceback path already carries", () => {
300312
expect(extractTerminalLinks(' File "/home/dev/app/x.py:5", line 12')).toEqual([
301313
{ kind: "path", text: "/home/dev/app/x.py:5", start: 8, end: 28 },

‎apps/web/src/terminal-links.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const NUMBER_AFTER_LINE_WORD_PATTERN = /^ (\d+)\b/u;
6060
// The `, line 12` that a Python traceback puts after the quoted file name, and the ` line: 12`
6161
// that Gradle puts after `Build file '...'`.
6262
const LINE_AFTER_QUOTE_PATTERN = /^(?:", line |' line: )(\d+)\b/u;
63+
// The `: line 3` of bash, the ` on line 3` of PHP and the ` line 3` of Perl after a bare path.
64+
const LINE_AFTER_PATH_PATTERN = /^(?::| on)? line (\d+)\b/u;
6365
// The `(line)` that pdb follows with the function name, as in `/a.py(3)f()` or `/a.py(3)f()->None`;
6466
// the candidate stops at the `>`.
6567
const POSITION_BEFORE_FUNCTION_PATTERN = /^.+[^\\/]\(\d+\)(?=[\p{L}\p{M}\p{N}_]+\(\)-?$)/u;
@@ -167,13 +169,15 @@ function collectMatches(
167169
kind === "path" && quotedPath === undefined
168170
? POSITION_BEFORE_FUNCTION_PATTERN.exec(text)?.[0]
169171
: undefined;
170-
const lineAfterQuote =
171-
quotedPath !== undefined && !/:\d+(?:-\d+)?$/u.test(trimmed)
172-
? LINE_AFTER_QUOTE_PATTERN.exec(line.slice(start + trimmed.length))?.[1]
172+
const lineAfterPath =
173+
kind === "path" && !/:\d+(?:-\d+)?$/u.test(trimmed)
174+
? (quotedPath !== undefined ? LINE_AFTER_QUOTE_PATTERN : LINE_AFTER_PATH_PATTERN).exec(
175+
line.slice(start + trimmed.length),
176+
)?.[1]
173177
: undefined;
174178
const candidate: TerminalLinkMatch = {
175179
kind,
176-
text: lineAfterQuote === undefined ? text : `${text}:${lineAfterQuote}`,
180+
text: lineAfterPath === undefined ? text : `${text}:${lineAfterPath}`,
177181
start,
178182
// A position outside quotes spans the closing quote in the terminal buffer.
179183
end: start + trimmed.length + (rawMatch.groups?.position ? 1 : 0),

0 commit comments

Comments
 (0)