You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying to create custom error types from Go.
Looking at the implementation of NewTypeError:
func (r *Runtime) NewTypeError(args ...interface{}) *Object {
msg := ""
if len(args) > 0 {
f, _ := args[0].(string)
msg = fmt.Sprintf(f, args[1:]...)
}
return r.builtin_new(r.getTypeError(), []Value{newStringValue(msg)})
}
func (r *Runtime) getTypeError() *Object {
ret := r.global.TypeError
if ret == nil {
ret = &Object{runtime: r}
r.global.TypeError = ret
r.newNativeFuncConstructProto(ret, r.builtin_Error, "TypeError", r.createErrorPrototype(stringTypeError, ret), r.getError(), 1)
}
return ret
}
It seems like I could create a custom error type using builtin_new and newNativeFuncConstructProto, similar to how TypeError is constructed. However, both of these methods are unexported, so I can't access them from outside the package.
Is there a recommended way to define custom error constructors (like MyCustomError), or would this require changes to the Goja ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm trying to create custom error types from Go.
Looking at the implementation of NewTypeError:
It seems like I could create a custom error type using builtin_new and newNativeFuncConstructProto, similar to how TypeError is constructed. However, both of these methods are unexported, so I can't access them from outside the package.
Is there a recommended way to define custom error constructors (like MyCustomError), or would this require changes to the Goja ?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions