{"record":{"id":"26013edf7bbcbcca","repo":"valeriansaliou/sonic","slug":"syntax-error-in-config","errorCode":null,"errorMessage":"syntax error in config","messagePattern":"syntax error in config","errorType":"validation","errorClass":"panic","httpStatus":null,"severity":"critical","filePath":"server/src/config.rs","lineNumber":102,"sourceCode":"            .build()\n            .expect(\"error reading config\");\n\n        // `#[serde(flatten)]` breaks type coercion from the `config` crate,\n        // so we can’t have `crate::Config` define\n        // `#[serde(flatten)] sonic: sonic::Config`. It’s a bit dirty but at\n        // least we don’t have to manually add custom deserialization logic to\n        // all non-string fields (in the core!).\n        #[derive(serde::Deserialize)]\n        pub struct ServerConfigTemp {\n            pub channel: ConfigChannel,\n            pub server: ConfigServer,\n        }\n\n        // Parse configuration.\n        let mut server_config = raw_config\n            .clone()\n            .try_deserialize::<ServerConfigTemp>()\n            .expect(\"syntax error in config\");\n        let mut core_config = raw_config\n            .try_deserialize::<sonic::Config>()\n            .expect(\"syntax error in config\");\n\n        back_compat::migrate_channel_search(&mut server_config.channel, &mut core_config);\n\n        // Validate configuration.\n        core_config.validate();\n\n        Config {\n            channel: server_config.channel,\n            server: server_config.server,\n            sonic: Arc::new(core_config),\n        }\n    }\n}\n\npub fn read_config(custom_path: Option<&str>) -> Config {","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/valeriansaliou/sonic/blob/e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2/server/src/config.rs#L84-L120","documentation":"After loading the raw config, Config::parse deserializes it into ServerConfigTemp and panics with \"syntax error in config\" if the structure doesn't match the expected server configuration schema. This is a deserialization/type error: a required field is missing or has the wrong type, not a literal syntax failure.","triggerScenarios":"Calling Config::parse when the config value cannot be deserialized into ServerConfigTemp — missing required sections (e.g. [server]), wrong field types (string where int expected), unknown/misspelled keys under strict deserialization.","commonSituations":"Hand-edited config files after upgrades; config schemas changed between sonic versions; env vars injecting strings into numeric fields.","solutions":["Compare your config against the current ServerConfigTemp schema / example config for your sonic version","Check field types: numbers, booleans, and strings must match the Rust types","Ensure all required sections ([server], etc.) are present","Read the full panic message: the config crate error printed by expect includes the exact field that failed"],"exampleFix":"// before\n[server]\nport = \"1491\"        # string, expected integer\n// after\n[server]\nport = 1491","handlingStrategy":"validation","validationCode":"// Rust: deserialize a dry-run copy first to get a precise error message\nlet raw = load_raw_config()?;\nmatch raw.clone().try_deserialize::<ServerConfigTemp>() {\n    Ok(_) => (),\n    Err(e) => eprintln!(\"bad server config: {}\", e),\n}","typeGuard":null,"tryCatchPattern":"match raw.try_deserialize::<ServerConfigTemp>() {\n    Ok(cfg) => cfg,\n    Err(e) => { eprintln!(\"config field error: {}\", e); std::process::exit(1); }\n}","preventionTips":["Regenerate your config from the version-matched example after every sonic upgrade","Type-check numeric/boolean fields: no quoted numbers in typed fields","Keep required sections ([server]) present even if minimal","Run config validation in CI before deploying"],"tags":["rust","configuration","deserialization","schema"],"backgroundTag":"config-deserialization-failed","analyzedSha":"e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2","analyzedAt":"2026-09-01T14:10:00.384Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}