Skip to content

Capture exception message in browser telemetry#304

Open
archandatta wants to merge 2 commits into
mainfrom
hypeship/telemetry-exception-message
Open

Capture exception message in browser telemetry#304
archandatta wants to merge 2 commits into
mainfrom
hypeship/telemetry-exception-message

Conversation

@archandatta

@archandatta archandatta commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Runtime.exceptionThrown telemetry events set console_error.data.text to CDP's generic "Uncaught" / "Uncaught (in promise)" prefix and dropped the actual error message. The message lives on the exception RemoteObject (exceptionDetails.exception), which was already parsed into the struct but never read — so consumers could see that an exception fired and where (line/column/source_url/stack), but not what it said. console.error() messages were unaffected.

Changes

  • Add message to BrowserConsoleErrorEventData (openapi.yaml + regenerated oapi).
  • Decode a minimal RemoteObject (description, value) and derive the message: first line of description (e.g. Error: boom) → thrown value for non-Error throws → fall back to the generic text. The full stack stays in stack_trace, so message is just the name+message line.
  • message is present only on exceptionThrown-sourced events; text is left unchanged so the uncaught-vs-in-promise signal is preserved.
  • Unit tests for the derivation (Error, primitive throws, fallbacks).

Test plan

  • go build ./...
  • go test ./lib/cdpmonitor/ -run TestExceptionMessage
  • e2e: assert an injected throw new Error("...") yields console_error.data.message containing the message (needs Docker + image)
  • Verify the field propagates through the public API / SDK telemetry path (kernel/kernel) — additive/back-compat; add there if it re-serializes through a typed schema

Note

Low Risk
Additive optional telemetry field with localized parsing logic and tests; no auth or breaking API changes.

Overview
Runtime.exceptionThrown console_error events previously exposed only CDP’s generic text ("Uncaught" / "Uncaught (in promise)"), so consumers could not see the real error text. This PR adds an optional message on BrowserConsoleErrorEventData (OpenAPI + regenerated oapi) and fills it in the CDP monitor when handling exceptions.

exceptionMessage reads the exception RemoteObject: first line of description for Error throws, thrown primitives via value, Symbol/BigInt via unserializableValue, with fallbacks to the existing text. text is unchanged so uncaught vs in-promise signaling stays the same; full stacks remain in stack_trace. message is set only for exceptionThrown-sourced events, not console.error. Unit tests cover the derivation paths.

Reviewed by Cursor Bugbot for commit 77185e4. Bugbot is set up for automated code reviews on this repo. Configure here.

Runtime.exceptionThrown events set console_error.data.text to CDP's
generic "Uncaught" prefix and dropped the actual error message, which
lives on the exception RemoteObject (already parsed but unused). Add a
`message` field populated from the object's description (first line) or
thrown value, so consumers can see what an exception said, not just that
one occurred and where.
@archandatta archandatta marked this pull request as ready for review July 3, 2026 18:11
Comment thread server/lib/cdpmonitor/handlers.go
Comment thread server/lib/cdpmonitor/handlers.go
A thrown JSON null rendered as "<nil>" instead of falling back to the generic
text; guard the nil case. Symbol/BigInt/NaN/Infinity throws land in
unserializableValue, which was ignored and dropped the thrown value; read it
after description. Adds regression tests for both.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 77185e4. Configure here.

if i := strings.IndexByte(o.Description, '\n'); i >= 0 {
return o.Description[:i]
}
return o.Description

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Leading newline yields empty message

Medium Severity

The exceptionMessage function returns an empty string when a CDP exception's description begins with a newline. This occurs because the first-line extraction logic misinterprets a leading newline, resulting in a blank message field in telemetry despite the generic text fallback.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 77185e4. Configure here.

@archandatta archandatta requested review from Sayan- and rgarcia July 3, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant