emilk/egui · error
Failed to find {:?} in Style::text_styles. Available styles:
Error message
Failed to find {:?} in Style::text_styles. Available styles:
{:#?} What it means
`TextStyle::resolve` maps a logical text style (e.g. `TextStyle::Heading`) to a concrete `FontId` by looking it up in `Style::text_styles`. If the map doesn't contain that key — because a custom style replaced the default `text_styles` and omitted entries — the lookup fails and it panics, listing the styles that ARE available.
Source
Thrown at crates/egui/src/style.rs:114
impl core::fmt::Display for TextStyle {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Small => "Small".fmt(f),
Self::Body => "Body".fmt(f),
Self::Monospace => "Monospace".fmt(f),
Self::Button => "Button".fmt(f),
Self::Heading => "Heading".fmt(f),
Self::Name(name) => (*name).fmt(f),
}
}
}
impl TextStyle {
/// Look up this [`TextStyle`] in [`Style::text_styles`].
pub fn resolve(&self, style: &Style) -> FontId {
style.text_styles.get(self).cloned().unwrap_or_else(|| {
panic!(
"Failed to find {:?} in Style::text_styles. Available styles:\n{:#?}",
self,
style.text_styles()
)
})
}
}
// ----------------------------------------------------------------------------
/// A way to select [`FontId`], either by picking one directly or by using a [`TextStyle`].
#[derive(Debug, Clone)]
pub enum FontSelection {
/// Default text style - will use [`TextStyle::Body`], unless
/// [`Style::override_font_id`] or [`Style::override_text_style`] is set.
Default,
/// Directly select size and font familyView on GitHub (pinned to 441971a776)
Solutions
- Add the missing `TextStyle` variant to your `text_styles` map with a `FontId` (size/family) of your choice.
- Start from `Style::default()` or clone the current style and modify only what you need, instead of constructing `text_styles` from scratch.
- Read the panic's 'Available styles' list to see exactly which keys exist, then add the missing one.
- Check the egui changelog when upgrading: new variants may need entries in custom text_styles maps.
Example fix
// before style.text_styles = [(TextStyle::Body, FontId::proportional(14.0))].into(); // Heading/Monospace missing // after let mut ts = style.text_styles.clone(); ts.insert(TextStyle::Heading, FontId::proportional(20.0)); ts.insert(TextStyle::Monospace, FontId::monospace(13.0)); style.text_styles = ts;
Defensive patterns
Strategy: validation
Validate before calling
// before rendering, ensure all TextStyle variants are present
let required = [TextStyle::Small, TextStyle::Body, TextStyle::Button, TextStyle::Heading, TextStyle::Monospace];
for ts in required {
assert!(ctx.style(|s| s.text_styles.contains_key(&ts)), "text_styles missing {ts:?}");
} Type guard
fn has_all_text_styles(style: &egui::Style) -> bool {
use egui::TextStyle::*;
[Small, Body, Button, Heading, Monospace]
.iter().all(|t| style.text_styles.contains_key(t))
} Prevention
- Clone Style::default() and edit instead of building text_styles from an empty map.
- Include every TextStyle variant in custom theme definitions.
- After egui upgrades, diff TextStyle variants against your custom text_styles map.
- Use the panic's 'Available styles' list in dev to quickly spot missing keys.
When it happens
Trigger: Setting a custom style via `ctx.style_mut` / `Context::set_style` / `Visuals` customization where `text_styles` is replaced with a BTreeMap missing one of the `TextStyle` variants, then rendering text whose widget requests that missing style (e.g. `RichText::new(x).heading()` or `text_style_height`).
Common situations: Hand-building `text_styles` for a themed app and forgetting variants like Monospace or Small; upgrading egui where new TextStyle variants/keys were added while custom code still constructs the old map; copying style code that only defines Body and Heading.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Plugin of type {:?} not found
- A style should be set for {:?}
- Error parsing {:?} TTF/OTF font file: {err}
- No font data found for {name:?}. Configured fonts: {availabl
- No fonts available until first call to Context::run()
AI-assisted analysis of emilk/egui@441971a776 (2026-09-12).
Data as JSON: /api/errors/783ca0181b183478.
Report an issue: GitHub.