MCPcopy
hub / github.com/pocketbase/pocketbase / checkGojaValueForError

Function checkGojaValueForError

plugins/jsvm/binds.go:1046–1065  ·  view source on GitHub ↗

------------------------------------------------------------------- checkGojaValueForError resolves the provided goja.Value and tries to extract its underlying error value (if any).

(app core.App, value goja.Value)

Source from the content-addressed store, hash-verified

1044// checkGojaValueForError resolves the provided goja.Value and tries
1045// to extract its underlying error value (if any).
1046func checkGojaValueForError(app core.App, value goja.Value) error {
1047 if value == nil {
1048 return nil
1049 }
1050
1051 exported := value.Export()
1052 switch v := exported.(type) {
1053 case error:
1054 return v
1055 case *goja.Promise:
1056 // Promise as return result is not officially supported but try to
1057 // resolve any thrown exception to avoid silently ignoring it
1058 app.Logger().Warn("the handler must a non-async function and not return a Promise")
1059 if promiseErr, ok := v.Result().Export().(error); ok {
1060 return normalizeException(promiseErr)
1061 }
1062 }
1063
1064 return nil
1065}
1066
1067// normalizeException checks if the provided error is a goja.Exception
1068// and attempts to return its underlying Go error.

Callers 3

hooksBindsFunction · 0.85
wrapHandlerFuncFunction · 0.85
wrapMiddlewaresFunction · 0.85

Calls 2

normalizeExceptionFunction · 0.85
LoggerMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…