{"record":{"id":"ed94db1d86dfcba6","repo":"zed-industries/zed","slug":"invalid-utf-8-in-semantic-token-rules","errorCode":null,"errorMessage":"invalid utf-8 in semantic_token_rules","messagePattern":"invalid utf-8 in semantic_token_rules","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/languages/src/cpp.rs","lineNumber":6,"sourceCode":"use settings::SemanticTokenRules;\n\npub(crate) fn semantic_token_rules() -> SemanticTokenRules {\n    let content = grammars::get_file(\"cpp/semantic_token_rules.json\")\n        .expect(\"missing cpp/semantic_token_rules.json\");\n    let json = std::str::from_utf8(&content.data).expect(\"invalid utf-8 in semantic_token_rules\");\n    settings::parse_json_with_comments::<SemanticTokenRules>(json)\n        .expect(\"failed to parse cpp semantic_token_rules.json\")\n}\n\n#[cfg(test)]\nmod tests {\n    use gpui::{AppContext as _, BorrowAppContext, TestAppContext};\n    use language::{AutoindentMode, Buffer};\n    use settings::SettingsStore;\n    use std::num::NonZeroU32;\n    use unindent::Unindent;\n\n    #[gpui::test]\n    async fn test_cpp_autoindent_switch_case(cx: &mut TestAppContext) {\n        cx.update(|cx| {\n            let test_settings = SettingsStore::test(cx);\n            cx.set_global(test_settings);\n            cx.update_global::<SettingsStore, _>(|store, cx| {","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/languages/src/cpp.rs#L1-L24","documentation":"Panics because the embedded cpp/semantic_token_rules.json bytes are not valid UTF-8 during std::str::from_utf8. A vendored JSON file should always be UTF-8; failure means the embedded asset is corrupt or was stored with a BOM/binary encoding at packaging time.","triggerScenarios":"Thrown at crates/languages/src/cpp.rs:6 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the vendored cpp/semantic_token_rules.json for non-UTF-8 bytes and re-save it as UTF-8","Validate all embedded JSON assets with a build-time test asserting from_utf8 succeeds","Use from_utf8_lossy to degrade instead of panicking on a corrupt asset"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}