Unverified Commit f4490d90 authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Improve js runtime custom error rpc response payload (#717)

If 'message' field is set and non-empty in js runtime thrown error object, set it in the returned json payload response.

Resolves #689
parent 419be0da
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -13,6 +13,9 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Fix handling of leaderboard record writes that do not need to update the database.
- Fix parsing edge case in TypeScript/JavaScript runtime storage delete operations.

### Changed
- Set JS runtime custom error message as the returned payload message in RPC requests.

## [3.9.0] - 2021-10-29
### Added
- Allow creation of relayed matches with a name. Names will be mapped to match identifiers.
+7 −19
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ func (r *RuntimeJS) GetCallback(e RuntimeExecutionMode, key string) string {

type jsError struct {
	StackTrace string `json:"stackTrace,omitempty"`
	Type       string `json:"type,omitempty"`
	custom     bool
	error      error
}
@@ -83,22 +82,11 @@ func (e *jsError) Error() string {
	return e.error.Error()
}

func newJsUncaughtExceptionError(error error, st string, custom bool) *jsError {
	jsErr := &jsError{
		Type:   "uncaughtExceptionError",
func newJsError(error error, stackTrace string, custom bool) *jsError {
	return &jsError{
		error:      error,
		custom:     custom,
	}
	if !custom {
		jsErr.StackTrace = st
	}
	return jsErr
}

func newJsRuntimeError(err error) *jsError {
	return &jsError{
		Type:  "runtimeError",
		error: err,
		StackTrace: stackTrace,
	}
}

@@ -512,10 +500,10 @@ func (r *RuntimeJS) invokeFunction(execMode RuntimeExecutionMode, id string, fn
			if !custom {
				r.logger.Error("JavaScript runtime function raised an uncaught exception", zap.String("mode", execMode.String()), zap.String("id", id), zap.Error(err))
			}
			return nil, newJsUncaughtExceptionError(errors.New(errMsg), exErr.String(), custom), errCode
			return nil, newJsError(errors.New(errMsg), exErr.String(), custom), errCode
		}
		r.logger.Error("JavaScript runtime function caused an error", zap.String("mode", execMode.String()), zap.String("id", id), zap.Error(err))
		return nil, newJsRuntimeError(err), codes.Internal
		r.logger.Error("JavaScript runtime error", zap.String("mode", execMode.String()), zap.String("id", id), zap.Error(err))
		return nil, err, codes.Internal
	}
	if retVal == nil || retVal == goja.Undefined() || retVal == goja.Null() {
		return nil, nil, codes.OK