normalizeException checks if the provided error is a goja.Exception and attempts to return its underlying Go error. note: using just goja.Exception.Unwrap() is insufficient and may falsely result in nil.
(err error)
| 1069 | // |
| 1070 | // note: using just goja.Exception.Unwrap() is insufficient and may falsely result in nil. |
| 1071 | func normalizeException(err error) error { |
| 1072 | if err == nil { |
| 1073 | return nil |
| 1074 | } |
| 1075 | |
| 1076 | jsException, ok := err.(*goja.Exception) |
| 1077 | if !ok { |
| 1078 | return err // no exception |
| 1079 | } |
| 1080 | |
| 1081 | switch v := jsException.Value().Export().(type) { |
| 1082 | case error: |
| 1083 | err = v |
| 1084 | case map[string]any: // goja.GoError |
| 1085 | if vErr, ok := v["value"].(error); ok { |
| 1086 | err = vErr |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | return err |
| 1091 | } |
| 1092 | |
| 1093 | var cachedFactoryFuncTypes = store.New[string, reflect.Type](nil) |
| 1094 |
no test coverage detected
searching dependent graphs…