{"record":{"id":"b3f43dfc8f6f0beb","repo":"xai-org/grok-build","slug":"failed-to-load-theme","errorCode":null,"errorMessage":"Failed to load theme","messagePattern":"Failed to load theme","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-markdown/src/syntax.rs","lineNumber":34,"sourceCode":"    /// The color theme for syntax highlighting.\n    pub theme: SyntectTheme,\n    /// The syntax definitions (supports 250+ languages via two-face).\n    pub syntax_set: SyntaxSet,\n}\n\nimpl Syntect {\n    /// Create a new Syntect instance from theme bytes.\n    ///\n    /// The theme bytes should be a TextMate `.tmTheme` file.\n    ///\n    /// # Example\n    ///\n    /// ```ignore\n    /// let syntect = Syntect::new(include_bytes!(\"assets/tokyo-night.tmTheme\"));\n    /// ```\n    pub fn new(theme_bytes: &[u8]) -> Self {\n        let mut cursor = Cursor::new(theme_bytes);\n        let theme = ThemeSet::load_from_reader(&mut cursor).expect(\"Failed to load theme\");\n        // Use two-face's extended syntax set which includes 250+ languages from bat\n        let syntax_set = two_face::syntax::extra_newlines();\n        Self { theme, syntax_set }\n    }\n\n    /// Find a syntax definition by file path extension.\n    pub fn find_syntax_by_file_path(&self, file_path: &Path) -> Option<&SyntaxReference> {\n        let ext = file_path.extension()?.to_str()?;\n        self.syntax_set.find_syntax_by_extension(ext)\n    }\n\n    /// Find a syntax definition by language token (e.g., \"rust\", \"python\").\n    pub fn find_syntax_by_token(&self, token: &str) -> Option<&SyntaxReference> {\n        self.syntax_set.find_syntax_by_token(token)\n    }\n\n    /// Create a highlighter for the given file path.\n    pub fn highlight_lines_by_file_path(&self, file_path: &Path) -> Option<HighlightLines<'_>> {","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-markdown/src/syntax.rs#L16-L52","documentation":"`Syntect::new` parses an embedded `.tmTheme` (TextMate theme) bytes with syntect's `ThemeSet::load_from_reader` and panics if parsing fails. Because the theme is compiled into the binary via `include_bytes!`, this normally fails only if the embedded asset is corrupt or in the wrong format. The library uses `.expect` because a bad theme makes syntax highlighting unusable.","triggerScenarios":"Passing theme bytes that are not a valid plist/XML tmTheme, truncated bytes, an empty slice, or a theme with unparseable color/scope entries to `Syntect::new`.","commonSituations":"Replaced tokyo-night.tmTheme with an editor-exported JSON theme (modern VS Code format) instead of the plist XML format syntect expects; build artifact corruption; hand-edited theme file with malformed XML.","solutions":["Verify the embedded theme file is plist XML tmTheme format, not VS Code JSON.","Open the .tmTheme and validate the XML (e.g. `plutil -lint tokyo-night.tmTheme`).","Replace with a known-good theme file, or convert the theme with a tool (e.g. `syntect`'s dump tool or a JSON→plist converter).","If themes are user-supplied at runtime, switch to a fallible constructor returning Result instead of expect."],"exampleFix":"// before\nlet theme = ThemeSet::load_from_reader(&mut cursor).expect(\"Failed to load theme\");\n// after\nlet theme = ThemeSet::load_from_reader(&mut cursor)\n    .expect(\"Failed to load theme: embedded .tmTheme must be valid plist XML\");","handlingStrategy":"validation","validationCode":"// validate theme bytes are plist XML before constructing Syntect\nfn is_plist_theme(bytes: &[u8]) -> bool {\n    bytes.starts_with(b\"<?xml\") || bytes.starts_with(b\"\\u{feff}<?xml\")\n}\nassert!(is_plist_theme(theme_bytes), \"theme must be plist XML tmTheme\");","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| Syntect::new(theme_bytes))\n    .map_err(|_| HighlightError::BadTheme)?","preventionTips":["Keep .tmTheme assets in plist XML format; never substitute VS Code JSON themes","Validate theme XML in CI (plutil -lint or an XML parse step)","Wrap Syntect::new in a fallible helper returning Result for user-supplied themes"],"tags":["rust","syntax-highlighting","syntect","panic","theme"],"backgroundTag":"theme-parsing-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}