Skip to content

Conversation

@vzaidman
Copy link

@vzaidman vzaidman commented Jun 27, 2025

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.

@vzaidman
Copy link
Author

improving the code

@vzaidman vzaidman closed this Jun 30, 2025
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