zed-industries/zed · error

failed to parse cpp semantic_token_rules.json

Error message

failed to parse cpp semantic_token_rules.json

What it means

Panics when parse_json_with_comments fails on the cpp semantic-token rules JSON: after the asset was found and decoded, the JSONC text did not deserialize into SemanticTokenRules. Since both the schema type and the file are vendored together, a parse failure means the file's structure and the Rust type have drifted (or the file was hand-edited incorrectly).

Source

Thrown at crates/languages/src/cpp.rs:8

use settings::SemanticTokenRules;

pub(crate) fn semantic_token_rules() -> SemanticTokenRules {
    let content = grammars::get_file("cpp/semantic_token_rules.json")
        .expect("missing cpp/semantic_token_rules.json");
    let json = std::str::from_utf8(&content.data).expect("invalid utf-8 in semantic_token_rules");
    settings::parse_json_with_comments::<SemanticTokenRules>(json)
        .expect("failed to parse cpp semantic_token_rules.json")
}

#[cfg(test)]
mod tests {
    use gpui::{AppContext as _, BorrowAppContext, TestAppContext};
    use language::{AutoindentMode, Buffer};
    use settings::SettingsStore;
    use std::num::NonZeroU32;
    use unindent::Unindent;

    #[gpui::test]
    async fn test_cpp_autoindent_switch_case(cx: &mut TestAppContext) {
        cx.update(|cx| {
            let test_settings = SettingsStore::test(cx);
            cx.set_global(test_settings);
            cx.update_global::<SettingsStore, _>(|store, cx| {
                store.update_user_settings(cx, |s| {
                    s.project.all_languages.defaults.tab_size = NonZeroU32::new(2);

View on GitHub (pinned to f4178619ac)

Solutions

  1. Run the deserialization in a test to see the exact serde error and fix either the JSON file or SemanticTokenRules
  2. Keep a round-trip test that serializes a sample SemanticTokenRules and re-parses the shipped file
  3. Log and fall back to default rules instead of panicking when parsing fails
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/languages/src/cpp.rs:8 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/54f1f7a2f3d643f6. Report an issue: GitHub.