{"record":{"id":"cb6fa1110463fd6d","repo":"linebender/druid","slug":"error","errorCode":null,"errorMessage":"{}","messagePattern":"\\{\\}","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"druid/src/env.rs","lineNumber":230,"sourceCode":"    /// }\n    /// ```\n    ///\n    /// [`WidgetExt::debug_widget`]: crate::WidgetExt::debug_widget\n    pub const DEBUG_WIDGET: Key<bool> = Key::new(\"org.linebender.druid.built-in.debug-widget\");\n\n    /// Gets a value from the environment, expecting it to be present.\n    ///\n    /// Note that the return value is a reference for \"expensive\" types such\n    /// as strings, but an ordinary value for \"cheap\" types such as numbers\n    /// and colors.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the key is not found, or if it is present with the wrong type.\n    pub fn get<V: ValueType>(&self, key: impl Borrow<Key<V>>) -> V {\n        match self.try_get(key) {\n            Ok(value) => value,\n            Err(err) => panic!(\"{}\", err),\n        }\n    }\n\n    /// Tries to get a value from the environment.\n    ///\n    /// If the value is not found, the raw key is returned as the error.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the value for the key is found, but has the wrong type.\n    pub fn try_get<V: ValueType>(&self, key: impl Borrow<Key<V>>) -> Result<V, MissingKeyError> {\n        self.0\n            .map\n            .get(key.borrow().key)\n            .map(|value| value.to_inner_unchecked())\n            .ok_or(MissingKeyError {\n                key: key.borrow().key.into(),\n            })","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/linebender/druid/blob/0f8b1195e4e073f9597f2865299c3d18f8e4005f/druid/src/env.rs#L212-L248","documentation":"Env::get<V> panics when the requested key is either absent from the environment or present with the wrong Value type; try_get returns Err whose Display message becomes the panic payload. It exists as the infallible convenience accessor for required theme keys, so the library deliberately crashes loudly instead of substituting a default. Widgets calling env.get(KEY) during paint/layout assume the key was set up in theme setup or by an ancestor.","triggerScenarios":"A custom widget calls env.get(MY_KEY) but nothing ever inserted the key via env.set / Env::with (e.g. the key isn't part of druid's default theme and the app never sets it). Calling env.get with a Key typed as one Value variant (e.g. Key<Color>) when the stored value is another (e.g. a f64 was set under the same key). Resetting or replacing the Env and dropping a key that descendants still require. Reading a key in paint_raw/resolve before the value has been provided by a parent widget.","commonSituations":"Custom theme keys referenced by widgets but never defined in the app's main Env setup. Renaming a Key or its type parameter in one place: Key<K> identity includes the type, and a stale setter inserts the wrong type. Copying an example that relied on druid's built-in theme (TEXT_COLOR, BUTTON_DARK, etc.) into code with a custom-built Env that omits them.","solutions":["Set the key before first use: env.set(KEY, value) in app startup (AppDelegate / main) or in the parent widget's lifecycle/init hook.","Switch to env.try_get(KEY) and handle Err (missing/wrong type) with a fallback value instead of panicking.","Verify the Key's type parameter matches what was stored — set with Key<Color> and read with Key<Color>, not a different variant.","If the key should have a default, use the-or pattern: env.get(KEY) after env.try_get(...).unwrap_or(default), or add the key to your theme setup function all widgets share."],"exampleFix":"// before\nlet color = env.get(MY_BG_COLOR); // panics if unset\n// after\nlet color = env.try_get(MY_BG_COLOR)\n    .unwrap_or(Color::WHITE);","handlingStrategy":"fallback","validationCode":"// before calling env.get(KEY):\nif env.try_get(KEY).is_err() {\n    env.set(KEY, default_value);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register all custom theme keys in a single setup function invoked at app startup.","Use try_get with unwrap_or(default) for anything not guaranteed by druid's default theme.","Keep Key<T> declarations and their set() call sites in one module so the type parameter cannot drift."],"tags":["rust","druid","env","panic","missing-key"],"backgroundTag":"missing-env-var","analyzedSha":"0f8b1195e4e073f9597f2865299c3d18f8e4005f","analyzedAt":"2026-09-10T14:27:34.582Z","contentChangedAt":"2026-09-10T14:27:34.582Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}