{"record":{"id":"7bde2e7a1d7a935d","repo":"siyuan-note/siyuan","slug":"objectsetdatamethods-v","errorCode":null,"errorMessage":"ObjectSetDataMethods: %v","messagePattern":"ObjectSetDataMethods: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/sandbox.go","lineNumber":160,"sourceCode":"\tif Object == nil {\n\t\treturn fmt.Errorf(\"globalThis.Object is not an object\")\n\t}\n\n\tseal, ok := goja.AssertFunction(Object.Get(\"seal\"))\n\tif !ok {\n\t\treturn fmt.Errorf(\"globalThis.Object.seal is not a function\")\n\t}\n\n\t_, err := seal(Object, obj)\n\treturn err\n}\n\n// ObjectSetDataMethods attaches text(), json(), buffer() and arrayBuffer() methods to a JS object,\n// each returning a Promise that resolves with the corresponding representation of data.\nfunc ObjectSetDataMethods(p *KernelPlugin, rt *goja.Runtime, object *goja.Object, data []byte) (err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"ObjectSetDataMethods: %v\", r)\n\t\t}\n\t}()\n\n\tlo.Must0(object.Set(\"text\", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {\n\t\tpromise, resolve, reject := rt.NewPromise()\n\n\t\trunErr := p.worker.Run(func(rt *goja.Runtime) (result any, err error) {\n\t\t\tresult = string(data)\n\t\t\treturn\n\t\t}, func(rt *goja.Runtime, result any, err error) {\n\t\t\tif lo.IsNil(err) {\n\t\t\t\tif resolveErr := resolve(result); resolveErr != nil {\n\t\t\t\t\tlogging.LogErrorf(\"[plugin:%s] data.text() resolve: %v\", p.Name, resolveErr)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif rejectErr := reject(rt.NewGoError(err)); rejectErr != nil {\n\t\t\t\t\tlogging.LogErrorf(\"[plugin:%s] data.text() reject: %v\", p.Name, rejectErr)\n\t\t\t\t}","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/sandbox.go#L142-L178","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Inspect the wrapped panic message for the failing Set/promise operation","Ensure object and rt come from the same, live goja runtime","Verify object is non-nil before calling","Call this during sandbox setup, not after the runtime has been interrupted","Handle the returned error and skip attaching data methods rather than proceeding"],"exampleFix":"// before\nvar obj *goja.Object\nerr := ObjectSetDataMethods(p, rt, obj, data)\n// after\nobj, _ := rt.NewObject(), error(nil)\nif obj != nil {\n    err = ObjectSetDataMethods(p, rt, obj, data)\n}","handlingStrategy":"try-catch","validationCode":"if object == nil || rt == nil {\n    return fmt.Errorf(\"object and runtime required for ObjectSetDataMethods\")\n}","typeGuard":null,"tryCatchPattern":"if err := ObjectSetDataMethods(p, rt, obj, data); err != nil {\n    log.Errorf(\"data method attach failed: %v\", err)\n    return err\n}","preventionTips":["Use objects and runtimes from the same goja instance","Attach data methods during sandbox setup, never after interrupt/close","Check for nil object before calling","Keep promise-building closures free of panicking operations"],"tags":["goja","javascript","plugin-sandbox","panic-recovery"],"backgroundTag":"module-init-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}