Skip to content

Conversation

vzaidman
Copy link

Fixing Error Causes of String Type Printed To Console Without New Line

The bug is caused by error type being a "span" to which a "text" "cause" is appended, without appending a new line beforehand.

That "span" actually creates a new line if the last span within it contains more than one element.

To solve it, I wrap all "causes" with divs.

Test plan

For the code:

// cause is "string"
console.error(new Error('aaa', {cause: 'bbb'}));

// cause is "error" which cause is "string"
console.error(new Error('ccc', {
    cause: new Error('ddd', {cause: 'eee'})
}));

// cause is "error" which cause also "error" which cause is "string"
console.error(new Error('fff', {
    cause: new Error('ggg', {
        cause: new Error('hhh', {
          cause: 'iii'
        })
    })
}));

Before:

Notice the cause in the second line in the first error is appended directly to the stack trace:

at global (:1:24)Caused by: bbb
Screenshot 2025-06-30 at 16 16 00

After:

Screenshot 2025-06-30 at 11 43 00

Also tested more complicated use cases with ignored frames and such.

  • This change maintains backwards compatibility with previous Local Storage data (if modifying settings, experiments, or other persisted client state).

Upstreaming plan

  • This commit should be sent as a patch to the upstream devtools-frontend repo. I've reviewed the contribution guide.
  • This commit is React Native-specific and cannot be upstreamed.

Copy link

@hoxyq hoxyq left a comment

Choose a reason for hiding this comment

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

Please add a test that covers this logic.

There are screenshot tests also, but the last time I checked, screenshots are downloaded from some Google's CDN, which requires authorization, so we probably can't add more :(

@vzaidman vzaidman force-pushed the fix-printed-string-cause branch from 5dfb164 to 2be5236 Compare June 30, 2025 15:51
@vzaidman
Copy link
Author

I don't see a neat way to test this very UI centric feature. I'd suggest upstreaming it as is.

@vzaidman vzaidman requested a review from hoxyq July 3, 2025 15:25
@vzaidman vzaidman merged commit 761b969 into main Jul 4, 2025
5 checks passed
@vzaidman vzaidman deleted the fix-printed-string-cause branch July 4, 2025 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants