Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/formatters/ConsoleFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ export class ConsoleFormatter {
}

toJSONDetailed(): object {
const location = this.#getTopFrameLocation();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the feature is about adding the first line of the stack to the non-detailed variants (toString(), toJSON()) so that the first source line appears in the list of console message. toJSONDetailed is not used in list_console_messages.

Copy link
Copy Markdown
Author

@kopalg20 kopalg20 Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made required changes. Let me know any further improvements needed.
Also added test cases for the same. @OrKoN


return {
id: this.#id,
type: this.#type,
Expand All @@ -322,6 +324,43 @@ export class ConsoleFormatter {
typeof arg === 'object' ? arg : String(arg),
),
stackTrace: this.#stack,
...(location ? { location } : {}),
};
}

#getTopFrameLocation():
| { url: string; lineNumber: number; columnNumber: number }
| undefined {

if (!this.#stack) {
return undefined;
}

const frame = this.#stack.syncFragment.frames.find(
f => !this.#isIgnored(f),
);

if (!frame) {
return undefined;
}

if (frame.uiSourceCode) {
const location = frame.uiSourceCode.uiLocation(frame.line, frame.column);
return {
url: location.uiSourceCode.url(),
lineNumber: location.lineNumber + 1,
columnNumber: location.columnNumber! + 1,
};
}

if (frame.url) {
return {
url: frame.url,
lineNumber: frame.line,
columnNumber: frame.column,
};
}

return undefined;
}
}
Loading