{"record":{"id":"63c04f238d1454fc","repo":"DioxusLabs/dioxus","slug":"lazy-value-is-already-initialized","errorCode":null,"errorMessage":"Lazy value is already initialized.","messagePattern":"Lazy value is already initialized\\.","errorType":"exception","errorClass":"CapturedError","httpStatus":null,"severity":"error","filePath":"packages/fullstack/src/lazy.rs","lineNumber":66,"sourceCode":"        // Prevent the constructor from being optimized out\n        black_box(constructor);\n\n        Self {\n            _phantom: std::marker::PhantomData,\n            value: std::sync::OnceLock::new(),\n            started_initialization: AtomicBool::new(false),\n            constructor: Some(blocking_initialize::<T, F, G, E>),\n        }\n    }\n\n    /// Set the value of the `Lazy` instance.\n    ///\n    /// This should only be called once during the server setup phase, typically inside `dioxus::serve`.\n    /// Future calls to this method will return an error containing the provided value.\n    pub fn set(&self, pool: T) -> Result<(), CapturedError> {\n        let res = self.value.set(pool);\n        if res.is_err() {\n            return Err(anyhow::anyhow!(\"Lazy value is already initialized.\").into());\n        }\n\n        Ok(())\n    }\n\n    pub fn try_set(&self, pool: T) -> Result<(), T> {\n        self.value.set(pool)\n    }\n\n    /// Initialize the value of the `Lazy` instance if it hasn't been initialized yet.\n    pub fn initialize(&self) -> Result<(), CapturedError> {\n        if let Some(constructor) = self.constructor {\n            // If we're already initializing this value, wait on the receiver.\n            if self\n                .started_initialization\n                .swap(true, std::sync::atomic::Ordering::SeqCst)\n            {\n                self.value.wait();","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/fullstack/src/lazy.rs#L48-L84","documentation":"Guard in fullstack Lazy::set: fires when set is called on a Lazy whose OnceLock already holds a value or whose initialization has already started. The docs specify set is meant to run once during server setup (typically inside dioxus::serve); a second call reaches this error with the provided value dropped.","triggerScenarios":"Thrown at packages/fullstack/src/lazy.rs:66 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The lazy value was initialized twice. Initialize it only once."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"24f6a829df0dfa203961a98ea4cae21c2ff27e28","analyzedAt":"2026-08-23T07:10:14.078Z","contentChangedAt":"2026-08-23T07:10:14.078Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}