Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors when serializing logged objects in console plugin #760

Merged
merged 2 commits into from
Oct 17, 2024
Merged
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
27 changes: 15 additions & 12 deletions plugins/debug-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ debugTab.renderLine = function (errorType, args) {
var text = [];
args.forEach(function (v) {
if (typeof v !== 'string' && typeof v !== 'number') {
var cache = [];
v = JSON.stringify(v, function (key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
try {
var cache = [];
v = JSON.stringify(v, function (key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.push(value);
}
// Store value in our collection
cache.push(value);
}
return value;
});
cache = null;
return value;
});
} finally {
Copy link
Contributor

Choose a reason for hiding this comment

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

There/here also needs to be a catch, otherwise the error thrown will continue until browser handles it.
The catch should also return something for the output...
Maybe smth like

} catch (e) {
  return "error rendering: " + String.valueOf(value);
}

... the idea is to output the message and string representation of that object which should output some nonsense like [[Object object]] - which is still less confusing that either error or empty/undefined value

Copy link
Contributor

Choose a reason for hiding this comment

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

indeed, but more likely v = "error rendering: " + String.valueOf(v); just in case the dev used console.log(window, 42)

cache = null;
}
}
text.push(v);
});
Expand Down
Loading