------------------------------------------------------------------- checkGojaValueForError resolves the provided goja.Value and tries to extract its underlying error value (if any).
(app core.App, value goja.Value)
| 1044 | // checkGojaValueForError resolves the provided goja.Value and tries |
| 1045 | // to extract its underlying error value (if any). |
| 1046 | func 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. |
no test coverage detected
searching dependent graphs…