-
Notifications
You must be signed in to change notification settings - Fork 570
*js.Error and *js.Object treating null objects differently #275
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
Comments
This sounds related to #240. Before that PR, there was no clean mapping from Perhaps this is yet another similar unhanded case. I need to think about it more. |
I've honestly almost never dealt with
type Error struct {
*Object
} I tried your example code and I've noticed if I add these logs: if result.Object == nil {
console.Log("result.Object is nil")
}
if result.Object != nil {
console.Log("result.Object is not nil")
} Then the output is as expected:
Perhaps that's the right way to check if the error was nil? I'm actually not quite sure why a wrapper struct is needed at all. Perhaps it's to enable the Another possibility could've been to expose that via an interface that js errors implement, ala: var err error
err = foo()
if jserr, ok := err.(js.Error); ok {
fmt.Println(jserr.Stack())
} Anyway, I don't think I can comment beyond this, you'll want to wait and see what @neelance says. |
Actually, looking at this one piece of code that deals with possible Since it only checks if Edit: Oh, never mind. It doesn't necessarily do something wrong. It'd be the user's responsibility to look at jsErr.Object, presumably. |
I don't know about all the internal details. I just know that an object that conforms to the If you need my help to dig into the issue a bit, let me know. I'm not afraid of getting my hands dirty, but I really know very little about the internals at play here. But if I need to familiarize myself, I can. |
The intention of |
Doing |
That makes sense to me. Sorry, didn't see this question earlier. |
Maybe we try and fix this as part of #617? |
I originally asked about this on the Google Group, but GH seems to be more active, so I'm re-posting here (plus markdown!!)
I'm not sure if I've run into a bug, or if I'm misusing GopherJS, but I've run into a problem with the way my Go code receives errors passed by Javascript Callbacks. To demonstrate the problem, I've built this code:
My main.js:
And main.go:
The output on my javascript console (in Chrome 43, FWIW) is:
If I do a
s/*js.Error/*js.Object/
in main.go, I get the expected result:So it seems that somehow the Error struct around *js.Object is obfuscating the nullness of the javascript object? Am I doing this wrong?
The text was updated successfully, but these errors were encountered: