{"record":{"id":"674a0948d0113eb9","repo":"sinelaw/fresh","slug":"failed-to-create-quickjs-runtime","errorCode":null,"errorMessage":"Failed to create QuickJS runtime: {}","messagePattern":"Failed to create QuickJS runtime: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/fresh-plugin-runtime/src/backend/quickjs_backend.rs","lineNumber":8890,"sourceCode":"            event_handlers,\n        )\n    }\n\n    /// Create a new QuickJS backend with editor state, shared pending responses,\n    /// and a shared async resource owner map\n    pub fn with_state_responses_and_resources(\n        state_snapshot: Arc<RwLock<EditorStateSnapshot>>,\n        command_sender: mpsc::Sender<PluginCommand>,\n        pending_responses: PendingResponses,\n        services: Arc<dyn fresh_core::services::PluginServiceBridge>,\n        async_resource_owners: AsyncResourceOwners,\n        search_handles: SearchHandleRegistry,\n        event_handlers: EventHandlerRegistry,\n    ) -> Result<Self> {\n        tracing::debug!(\"QuickJsBackend::new: creating QuickJS runtime\");\n\n        let runtime =\n            Runtime::new().map_err(|e| anyhow!(\"Failed to create QuickJS runtime: {}\", e))?;\n\n        // Set up promise rejection tracker to catch unhandled rejections\n        let rejection_sender = command_sender.clone();\n        runtime.set_host_promise_rejection_tracker(Some(Box::new(\n            move |ctx, _promise, reason, is_handled| {\n                if !is_handled {\n                    // Format the rejection reason\n                    let error_msg = if let Some(exc) = reason.as_exception() {\n                        format!(\n                            \"{}: {}\",\n                            exc.message().unwrap_or_default(),\n                            exc.stack().unwrap_or_default()\n                        )\n                    } else {\n                        format!(\"{:?}\", reason)\n                    };\n\n                    tracing::error!(\"Unhandled Promise rejection: {}\", error_msg);","sourceCodeStart":8872,"sourceCodeEnd":8908,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-plugin-runtime/src/backend/quickjs_backend.rs#L8872-L8908","documentation":"Constructor failure of the QuickJS backend: rquickjs's Runtime::new() failed, meaning the underlying QuickJS engine could not be initialized (typically allocation/limit setup failure or memory pressure in the embedded engine). No plugin can run in this process state, so with_state_responses_and_resources propagates the wrapped engine error to the plugin thread instead of returning a backend instance.","triggerScenarios":"Runtime::new() returns an error — typically resource exhaustion (cannot allocate/initialize the QuickJS engine), unsupported platform build, or repeated runtime creation hitting OS limits (threads/memory).","commonSituations":"Embedded hosts running in memory-constrained containers; low ulimit environments; broken or mismatched rquickjs native build; platform without required QuickJS support.","solutions":["Check memory limits (ulimit -v, container memory caps) and raise them","Verify the build includes a working rquickjs/QuickJS native library for the platform","Reduce concurrent backend instances","Capture and inspect the wrapped inner error for the root cause"],"exampleFix":"// before\ndocker run -m 32m my-host   # too small for QuickJS init\n// after\ndocker run -m 512m my-host","handlingStrategy":"try-catch","validationCode":"// check available memory before initializing the backend\nlet mem = mem_info();\nif mem.available < 256 * 1024 * 1024 { return Err(\"insufficient memory for plugin backend\"); }","typeGuard":null,"tryCatchPattern":"match QuickJsBackend::new(sender, handles, handlers) {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"Failed to create QuickJS runtime\") => {\n        eprintln!(\"cannot start plugin engine: {e:#}\");\n        run_without_plugins()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Set container/ulimit memory limits with headroom for QuickJS","Limit concurrent backend instances","Verify the target platform is supported by the rquickjs build","Health-check backend construction at startup, not on first use"],"tags":["quickjs","runtime-init","memory"],"backgroundTag":"module-init-failed","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}