{"record":{"id":"bcc3ac78ae6c672c","repo":"siyuan-note/siyuan","slug":"runscript-v","errorCode":null,"errorMessage":"RunScript: %v","messagePattern":"RunScript: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/plugin.go","lineNumber":210,"sourceCode":"\t\t\t\terr = fmt.Errorf(\"goja panic during event loop run: %v\", r)\n\t\t\t}\n\t\t}()\n\n\t\t// Use JSON struct tags for field name mapping, with fallback to original names if \"json\" tag is absent.\n\t\trt.SetFieldNameMapper(goja.TagFieldNameMapper(\"json\", true))\n\n\t\tif enableErr := EnableExtendModules(p, rt); enableErr != nil {\n\t\t\terr = fmt.Errorf(\"EnableExtendModules: %v\", enableErr)\n\t\t\treturn\n\t\t}\n\n\t\tif enableErr := EnableSiyuanModule(p, rt); enableErr != nil {\n\t\t\terr = fmt.Errorf(\"EnableSiyuanModule: %v\", enableErr)\n\t\t\treturn\n\t\t}\n\n\t\tif _, runErr := rt.RunScript(p.file, p.Kernel.JS); runErr != nil {\n\t\t\terr = fmt.Errorf(\"RunScript: %v\", runErr)\n\t\t\treturn\n\t\t}\n\t})\n\tp.runtime.Start()\n\treturn\n}\n\n// Eval evaluates JavaScript code in the plugin's goja runtime, returning the result or error.\nfunc (p *KernelPlugin) Eval(rt *goja.Runtime, code string) (goja.Value, error) {\n\treturn rt.RunScript(p.file, code)\n}\n\n// close interrupts the goja runtime and clears the pointer.\nfunc (p *KernelPlugin) close() (err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"goja panic during close runtime: %v\", r)\n\t\t}","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/plugin.go#L192-L228","documentation":"The final step of plugin runtime initialization is `rt.RunScript(p.file, p.Kernel.JS)`, which evaluates the plugin's bundled kernel.js. Any JavaScript syntax error, thrown top-level exception, or Go-side evaluation error is wrapped as `RunScript: %v`. This is the most common plugin startup failure: the plugin's own code failed to execute.","triggerScenarios":"Evaluating the plugin's kernel.js that contains ES syntax goja does not support (e.g. some optional chaining patterns in older versions), a top-level `throw`, or a top-level access to an undefined global.","commonSituations":"A plugin built for the frontend bundled incorrectly for the kernel (uses browser APIs like `window`/`document` at top level), a corrupted download of the plugin package, or a plugin targeting a newer goja/ES feature than the kernel supports.","solutions":["Read the wrapped goja exception message — it names the line/position in kernel.js that failed","Check the plugin's kernel.js does not reference browser-only globals at top level","Reinstall/update the plugin to get an intact, kernel-compatible bundle","If the inner error mentions unsupported syntax, downgrade the plugin or wait for a kernel goja upgrade"],"exampleFix":"// before (plugin kernel.js)\nconst name = window.location.hostname;\n// after\nconst name = typeof window !== 'undefined' ? window.location.hostname : '';","handlingStrategy":"try-catch","validationCode":"// sanity check the bundle before enabling\nif (!kernelJs || kernelJs.trim().length === 0) throw new Error('kernel.js is empty; reinstall the plugin');","typeGuard":null,"tryCatchPattern":"try { rt.RunScript(p.file, p.Kernel.JS); } catch (e) { console.error('plugin kernel.js failed:', e.message); }","preventionTips":["Bundle kernel.js without browser-only globals at top level","Test the plugin in a SiYuan kernel environment before release","Avoid ES features newer than the kernel's goja supports","Reinstall the plugin if the error appears after a partial download"],"tags":["goja","javascript","plugin-lifecycle","script-evaluation"],"backgroundTag":"script-evaluation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}