I agree. That is what I settled on, basically. Thanks for the suggestion!

Will

On Fri, Dec 23, 2022 at 10:23 AM Brian Candler <b.cand...@pobox.com> wrote:
>
> I don't know how a raw Go interface value would be usable in Javascript.  As 
> an alternative, would it be any good to use sprintf("%T", readErr) as the 
> code, and readErr.Error() as the value? At least those are both strings.
>
> https://go.dev/play/p/nd1FXUvD_zg
>
> On Friday, 23 December 2022 at 14:33:21 UTC Will Hawkins wrote:
>>
>> Hello everyone!
>>
>> First, thank you *all* (I mean this great community) for the Go language and 
>> especially its support for a wasm target.
>>
>> As I was attempting to finish up a CL 
>> (https://go-review.googlesource.com/c/go/+/458395) I found occasion to need 
>> to great a JS Error based on a Go error. I was hoping to use the JS Error 
>> constructor that includes an option object to specify a cause and value 
>> (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
>>  by using the actual go error. Here's what I was thinking:
>>
>> readErrCause := js.Global().Get("Object").New()
>> readErrCause.Set("code", readErr.Error())
>> readErrCause.Set("value", js.ValueOf(readErr))
>> readErr := js.Global().Get("Error").New("ReadFull failed", readErrCause)
>>
>> (where readErr is of the `error` type, of course)
>>
>> Unfortunately,
>> readErrCause.Set("value", js.ValueOf(readErr))
>>
>> does not work because, as the comment so perfectly says, ValueOf
>>
>> // Panics if x is not one of the expected types.
>>
>> I am absolutely up for proposing and implementing a small addition to the 
>> "js package" if people think it would be helpful but I wanted to check here 
>> first.
>>
>> Again, thank you for all the great work that you *all* do!!
>>
>> Sincerely,
>> Will
>>
>>
>>
> --
> You received this message because you are subscribed to a topic in the Google 
> Groups "golang-nuts" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/golang-nuts/zwwA1wRjA58/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/08d9eb2b-49bb-4a8a-8b81-d54b70a24fc0n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CADx9qWjfhro4E1vPpOfVVgg4FOmM1X8U2SuFf_izOhFTw4VzSg%40mail.gmail.com.

Reply via email to