-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
fix(core): Log customInspect implementation errors #9095
Conversation
This was introduced in #3226. It can be troublesome if a broken
Logging should be throw-safe. |
Is this a desirable output? |
I'd omit the line break before the fallback output, it looks better for a nested property. |
Hmm I discovered something interesting while messing around with this. Turns out you can skip the inspect error pass by defining Deno.customInspect with a getter Is this desired behavior based on what we just discussed? const x = {}
Object.defineProperty(x, Deno.customInspect, {
enumerable: false,
configurable: false,
get: function(){
return Deno.env.toObject();
}
})
console.log(x) |
This comment has been minimized.
This comment has been minimized.
Mmm gotcha. I didn't know you could assign something other than a function to customInspect. This might cover my use case after all |
This comment has been minimized.
This comment has been minimized.
Doesn't look so great on variables. I think I'm gonna leave the line break there
|
@00ff0000red You are right. However it can be polyfilled easily with |
Actually, what I said was irrelevant anyway, since, in a browser, you wouldn't exactly have |
Ready for review |
What's the behavior in Node for this? It seems like we should just throw the exception rather than trying to log it. I agree silently swallowing the error is not great. But why try to catch it at all? |
Node throws const util = require("util");
const foo = {
[util.inspect.custom]() {
console.log("before");
throw new Error("error");
console.log("after");
},
};
util.inspect(foo);
console.log("done");
I don't get why we'd do anything special here at all really. |
Yeah I'm not crazy about this swallowing errors either (customInspect is an user implementation after all, it's not out of their control to fix the error). I'll revert to the original commit and look for customInspect implementations in Deno code that require manual error handling (like Headers) |
On second though since errors like trying to read |
It surprises me that Node throws for this, because it doesn't when evaluating getters with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - this is more explicit, easier to debug. Thanks @Soremwar
Right now, the
customInspect
function in core swallows all errors that are thrown in user defined inspection functions.I don't think there is a reason for this behavior to be inforced (in my particular use case this is swallowing Permission errors).With this PR, a warning will be appended to the inspected item showing the error thrown in the the inspect function