mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-04 15:49:49 +00:00
25 lines
388 B
Go
25 lines
388 B
Go
package util
|
|
|
|
import (
|
|
"github.com/dop251/goja"
|
|
)
|
|
|
|
func ThrowTypeError(vm *goja.Runtime, msg string) {
|
|
panic(vm.NewTypeError(msg))
|
|
}
|
|
|
|
func AssertError[T error](err error) (t T, r bool) {
|
|
if err == nil {
|
|
return
|
|
}
|
|
if e, ok := err.(T); ok {
|
|
return e, true
|
|
}
|
|
if e, ok := err.(*goja.Exception); ok {
|
|
if ee, okk := e.Value().Export().(T); okk {
|
|
return ee, true
|
|
}
|
|
}
|
|
return
|
|
}
|