MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / CallWithDB

Method CallWithDB

db/functions/js_runner.go:120–147  ·  view source on GitHub ↗

Calls a javaScriptRunner's JavaScript function.

(db *db.Database, ctx context.Context, jsArgs ...any)

Source from the content-addressed store, hash-verified

118
119// Calls a javaScriptRunner's JavaScript function.
120func (runner *jsRunner) CallWithDB(db *db.Database, ctx context.Context, jsArgs ...any) (result any, err error) {
121 if ctx == nil {
122 panic("missing context to userJSRunner")
123 }
124
125 var timeout time.Duration
126 if deadline, exists := ctx.Deadline(); exists {
127 timeout = time.Until(deadline)
128 if timeout <= 0 {
129 return nil, sgbucket.ErrJSTimeout
130 }
131 }
132
133 var depth int
134 var ok bool
135 if depth, ok = ctx.Value(ctxJSCallDepthKey).(int); ok {
136 if depth >= kUserFunctionMaxCallDepth {
137 base.ErrorfCtx(ctx, "User function recursion too deep, calling %s", runner.name)
138 return nil, base.HTTPErrorf(http.StatusLoopDetected, "User function recursion too deep")
139 }
140 }
141 ctx = context.WithValue(ctx, ctxJSCallDepthKey, depth+1)
142
143 runner.SetTimeout(timeout)
144 runner.currentDB = db
145 runner.ctx = ctx
146 return runner.Call(ctx, jsArgs...)
147}
148
149// JavaScript error returned by a jsRunner
150type jsError struct {

Callers 1

callMethod · 0.80

Calls 3

ErrorfCtxFunction · 0.92
HTTPErrorfFunction · 0.92
ValueMethod · 0.45

Tested by

no test coverage detected