siyuan-note/siyuan · error
failed to enable extend modules
Error message
failed to enable extend modules: %v
What it means
EnableExtendModules registers extended CommonJS modules (url, buffer, etc.) into a plugin's goja runtime. Registration can panic inside goja (bad module definition, runtime in a bad state); the deferred recover converts that panic into this wrapped error so the kernel does not crash.
Solutions
- Check the wrapped panic message (%v) to find the root cause inside the registry setup
- Ensure the goja runtime is freshly created and not interrupted before calling EnableExtendModules
- Verify no custom module registration code panics (nil maps, invalid exports)
- Catch this error at plugin-load time and fail the plugin load gracefully instead of retrying on a poisoned runtime
- Upgrade/review goja usage if the panic stems from a goja-internal bug
Defensive patterns
Strategy: try-catch
Validate before calling
if rt == nil || p == nil {
return fmt.Errorf("runtime and plugin must be initialized before EnableExtendModules")
} Try / catch
if err := EnableExtendModules(p, rt); err != nil {
log.Errorf("plugin %s sandbox init failed: %v", p.Name, err)
return fmt.Errorf("plugin load aborted")
} Prevention
- Create a fresh goja.Runtime per plugin and never reuse interrupted runtimes
- Check the wrapped panic text for the root cause before retrying
- Fail plugin load cleanly instead of reusing a half-initialized runtime
- Keep custom module registrations panic-free
When it happens
Trigger: Calling EnableExtendModules (directly or during plugin loading) when the goja require registry setup panics — e.g. a nil *goja.Runtime, a runtime already interrupted/interrupted by timeout, or a module registrar that panics.
Common situations: Loading a plugin against a runtime that was previously interrupted by a script timeout; goja runtime misconfiguration during sandbox bootstrap; panicking custom module registrations added to the registry.
Related errors
- failed to inject global context
- ObjectSetDataMethods
- expected promise object, got %T
- globalThis.Object.freeze is not a function
- globalThis.Object is not an object
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/5f80bb8b51c4d48d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/plugin/sandbox.go:79
type FunctionResult[T any] struct {
Value T
Error error
}
type CallResult FunctionResult[goja.Value]
func (r *CallResult) TaskResult() *TaskResult {
if r.Error != nil {
return &TaskResult{err: r.Error}
}
return &TaskResult{value: r.Value.Export()}
}
// EnableExtendModules registers extended modules (e.g. url, buffer) to the plugin's goja runtime.
func EnableExtendModules(p *KernelPlugin, rt *goja.Runtime) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("failed to enable extend modules: %v", r)
}
}()
registry := require.NewRegistry()
registry.Enable(rt)
registry.RegisterNativeModule(
console.ModuleName,
console.RequireWithPrinter(&Printer{name: p.Name}),
)
url.Enable(rt)
buffer.Enable(rt)
console.Enable(rt)
return
}
// EnableSiyuanModule injects all siyuan.* APIs into the plugin's goja global context.View on GitHub (pinned to 9f775e8a12)