MCPcopy
hub / github.com/pocketbase/pocketbase / normalizeException

Function normalizeException

plugins/jsvm/binds.go:1071–1091  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1069//
1070// note: using just goja.Exception.Unwrap() is insufficient and may falsely result in nil.
1071func 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
1093var cachedFactoryFuncTypes = store.New[string, reflect.Type](nil)
1094

Callers 5

hooksBindsFunction · 0.85
wrapHandlerFuncFunction · 0.85
wrapMiddlewaresFunction · 0.85
checkGojaValueForErrorFunction · 0.85

Calls 1

ValueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…