siyuan-note/siyuan · error

ObjectSetDataMethods

Error message

ObjectSetDataMethods: %v

What it means

ObjectSetDataMethods attaches text(), json(), buffer() and arrayBuffer() promise-returning helpers to a JS object. A panic while setting these methods or building their promises in goja is recovered and wrapped into this error.

Solutions

  1. Inspect the wrapped panic message for the failing Set/promise operation
  2. Ensure object and rt come from the same, live goja runtime
  3. Verify object is non-nil before calling
  4. Call this during sandbox setup, not after the runtime has been interrupted
  5. Handle the returned error and skip attaching data methods rather than proceeding

Example fix

// before
var obj *goja.Object
err := ObjectSetDataMethods(p, rt, obj, data)
// after
obj, _ := rt.NewObject(), error(nil)
if obj != nil {
    err = ObjectSetDataMethods(p, rt, obj, data)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if object == nil || rt == nil {
    return fmt.Errorf("object and runtime required for ObjectSetDataMethods")
}

Try / catch

if err := ObjectSetDataMethods(p, rt, obj, data); err != nil {
    log.Errorf("data method attach failed: %v", err)
    return err
}

Prevention

When it happens

Trigger: Calling ObjectSetDataMethods with a nil *goja.Object, a runtime that is interrupted or closed, or when constructing the promise closures panics (e.g. rt.NewPromise or object.Set failing via panic in goja).

Common situations: Attaching data methods to a binding object after the runtime was torn down; passing an object created by a different goja runtime; nil plugin or runtime pointer during asset/blob binding.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/7bde2e7a1d7a935d. Report an issue: GitHub.

Appendix: source

Thrown at kernel/plugin/sandbox.go:160

	if Object == nil {
		return fmt.Errorf("globalThis.Object is not an object")
	}

	seal, ok := goja.AssertFunction(Object.Get("seal"))
	if !ok {
		return fmt.Errorf("globalThis.Object.seal is not a function")
	}

	_, err := seal(Object, obj)
	return err
}

// ObjectSetDataMethods attaches text(), json(), buffer() and arrayBuffer() methods to a JS object,
// each returning a Promise that resolves with the corresponding representation of data.
func ObjectSetDataMethods(p *KernelPlugin, rt *goja.Runtime, object *goja.Object, data []byte) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("ObjectSetDataMethods: %v", r)
		}
	}()

	lo.Must0(object.Set("text", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
		promise, resolve, reject := rt.NewPromise()

		runErr := p.worker.Run(func(rt *goja.Runtime) (result any, err error) {
			result = string(data)
			return
		}, func(rt *goja.Runtime, result any, err error) {
			if lo.IsNil(err) {
				if resolveErr := resolve(result); resolveErr != nil {
					logging.LogErrorf("[plugin:%s] data.text() resolve: %v", p.Name, resolveErr)
				}
			} else {
				if rejectErr := reject(rt.NewGoError(err)); rejectErr != nil {
					logging.LogErrorf("[plugin:%s] data.text() reject: %v", p.Name, rejectErr)
				}

View on GitHub (pinned to 9f775e8a12)