Use toString check rather than instanceof check.#3
Conversation
|
Seems like the issue with this is that I can define my own |
|
Well, if it's a user defined type, the That sort of raises the question, what do you do for user defined
In any other case, just wrap in an |
|
Also, since I'm not fully confident in js's prototypal semantics, It'd be great to hear some feedback from others like @michaelficarra |
|
I'd like to keep this as simple as possible. Why not just if something is an |
There was a problem hiding this comment.
{}.toString.call(e) === '[object Error]'is more idiomatic.
There was a problem hiding this comment.
I guess that wouldn't match TypeError and the like though?
There was a problem hiding this comment.
Oh, nevermind, nor would the slice.
|
I agree, the simpler the better. Unfortunately, I think that the ugliness of js will either show up in this library or with users of the library. If we stringify and wrap things that fail the The I think we actually lose a bit of expressivity by just wrapping anything that doesn't pass the I might be overthinking it. Or, more likely, underthinking it. Or, maybe it's more unsafe to have these separate checks. But it feels like someone is going to get the ugliness of this, and mitigating it to the library sounds like the better way. |
|
Actually, I guess since the Hmm, I think I'm actually okay with this. |
|
Alright, let me know of any other changes. |
There was a problem hiding this comment.
Why did you remove the cross-realm support? I think that is useful for people working in a browser environment.
There was a problem hiding this comment.
I agree entirely that this is very useful for these different scenarios. I think to be robust, we should handle more cases (at least the three mentioned here). But, it also seems like you're not losing much information if you parse the message returned. You lose the stack, but that's non-standard anyway. Maybe it's more important to support that as well?
My thoughts on this whole situation is that I'd rather not have to deal with js semantics at all and especially not exceptions. At this point, if something is thrown somewhere, it's more than likely something that could have been caught on the ps side if it were implemented there. So, until more things are implemented there, I'm fine with dealing with partially implemented solutions. I don't actually care enough what catchException does so long as I can handle it. It might not be pretty or robust, but so long as it's not a runtime error I can deal with it. And, if partially solving this at the moment is what it takes to get this merged, I'd rather that. I'm surely not the only one who has (or will) run into this issue, and I'd rather there be some fix than none at all.
Not mad, not angry, not trying to be condescending or snarky or anything like that, just wanting to explain my thoughts over the internet :).
There was a problem hiding this comment.
Oh, and if you have a different or better way to do this, please, relay the info or submit a pr or whatever.
As I said, I don't really care what happens here, so long as it's not a runtime error I can't do anything about.
There was a problem hiding this comment.
I think it's worth the slightly less clear (but common and idiomatic) {}.toString call. If there was a downside to doing it the right way, I'd be 100% on your side, but it doesn't hurt anything in this case.
There was a problem hiding this comment.
But then, don't we miss out on a user/library defined Error type? Since {}.toString.call(myError) === '[object Object]'. Or is there a way to make this work as well?
Again, I'm indifferent either way, because at least we've not got a runtime error now. But, I don't think this can be a simple one case check. There's multiple ways to construct an error that should be caught here, and we should have cases for each if we're going to do it right.
@paf31 thoughts?
There was a problem hiding this comment.
I really only care to handle the Error type, and to wrap other things. If we can handle Errors from other domains, that's a plus in my book.
I'll let you both decide :)
There was a problem hiding this comment.
Alright, so @michaelficarra what say you?
Just the one {}.toString.call(e).slice(8, -1) === 'Error' check, or also an instance check so we catch user/lib defined Error's as well?
|
Alright, can we call this good? or more changes? |
|
Yeah, looks good to me. |
👍, do both. That should achieve cross-realm support as well as Error subclass support. |
Use `toString` check AND `instanceof` check.
|
Okay. Good all around? @paf31 @michaelficarra ? |
|
🏁 |
|
💝 Perfect. |
|
How about over here 😉 |
Use `toString` check rather than `instanceof` check.
Re: discussion in #1 Should fix wonky js context things.
This seems to provide the semantics of what the type specifies, since
throwing if we didn't immediately get anErroractually introduces back anExceptioneffect. whichcatchExceptionis supposed to remove.