{"record":{"id":"f2e7bb9e0acc335b","repo":"unicity-aos/capsule-identity","slug":"failed-to-parse-spark-config-path-during-auto-detect-e","errorCode":null,"errorMessage":"Failed to parse {SPARK_CONFIG_PATH} during auto-detect: {e}","messagePattern":"Failed to parse (.+?) during auto-detect: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lib.rs","lineNumber":189,"sourceCode":"        );\n\n        // Auto-detect an existing spark.toml when KV state says not yet onboarded.\n        // This makes the capsule resilient to KV resets: if the file exists and\n        // parses successfully we treat the user as onboarded without requiring\n        // an explicit `identity-import`.\n        if !self.onboarded\n            && let Some(content) = load_spark()\n        {\n            // Parse directly instead of going through parse_spark_toml (which\n            // falls back to a default with a non-empty callsign on error).\n            match toml::from_str::<SparkConfig>(&content) {\n                Ok(config) if !config.callsign.is_empty() => {\n                    self.spark = config;\n                    self.onboarded = true;\n                }\n                Ok(_) => {} // Empty callsign — treat as stub, don't onboard.\n                Err(e) => {\n                    log::warn(format!(\n                        \"Failed to parse {SPARK_CONFIG_PATH} during auto-detect: {e}\"\n                    ));\n                }\n            }\n        }\n\n        if self.onboarded {\n            // Prepend the established identity preamble.\n            let opening = self.spark.build_preamble();\n            prompt = format!(\"{opening}\\n\\n{prompt}\");\n        } else {\n            // No preamble — don't anchor the model to a name before onboarding.\n            prompt.push_str(\"\\n\\n\");\n            prompt.push_str(ONBOARDING_PROMPT);\n        }\n\n        prompt\n    }","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/unicity-aos/capsule-identity/blob/1364a437f30122558a70ad703acc23d48f144ee6/src/lib.rs#L171-L207","documentation":"This is a warning logged during automatic identity detection in build_prompt_text_with_spark_loader when the spark.toml config file at SPARK_CONFIG_PATH exists but cannot be parsed as valid TOML (toml::from_str returned Err). The loader treats the failure as non-fatal: it logs the parse error and continues without loading the saved identity, so the user goes through onboarding again. The error message interpolates the underlying TOML parse error `e` describing the exact syntax or type problem.","triggerScenarios":"Calling build_prompt_text (directly or via the prompt-building paths) when a spark.toml file exists at SPARK_CONFIG_PATH but toml::from_str fails on its contents — e.g. malformed TOML syntax, a field with the wrong type (callsign defined as a non-string), or a schema/type mismatch against SparkConfig's serde definitions.","commonSituations":"A user hand-edited spark.toml and introduced a syntax error (missing quote, bad section header); a config file written by an older/newer version with fields whose types changed; the file was corrupted or truncated on disk; a tools-generated config wrote invalid TOML.","solutions":["Open the file at SPARK_CONFIG_PATH and fix the TOML syntax error reported in the message (line/column are included in `e`).","Verify each field matches SparkConfig's expected types (e.g. callsign must be a string) and that unknown/renamed fields are removed or allowed.","Regenerate the config by letting the app run onboarding again (delete the corrupt file; it will be re-created on identity save).","If you control writes to spark.toml, serialize with toml::to_string from SparkConfig instead of hand-writing the file, and validate after writing."],"exampleFix":"# before (spark.toml with broken syntax)\n[callsign]\nname = \"Nova\"\n\n# after (valid for SparkConfig)\ncallsign = \"Nova\"","handlingStrategy":"validation","validationCode":"// Before relying on auto-detect, pre-validate the config file.\nlet raw = std::fs::read_to_string(SPARK_CONFIG_PATH).ok()?;\nmatch toml::from_str::<SparkConfig>(&raw) {\n    Ok(cfg) if !cfg.callsign.is_empty() => Some(cfg),\n    _ => None, // fall back to onboarding instead of a silent skip\n}","typeGuard":"fn is_valid_spark_config(raw: &str) -> bool {\n    toml::from_str::<SparkConfig>(raw)\n        .map(|c| !c.callsign.is_empty())\n        .unwrap_or(false)\n}","tryCatchPattern":"// Rust has no try/catch; handle the Result explicitly\nmatch toml::from_str::<SparkConfig>(&content) {\n    Ok(config) if !config.callsign.is_empty() => { /* use config */ }\n    Ok(_) => { /* empty callsign: stub, run onboarding */ }\n    Err(e) => log::warn(format!(\"Bad spark.toml: {e}; running onboarding\")),\n}","preventionTips":["Always generate spark.toml via toml::to_string(SparkConfig) rather than hand-editing.","After writing the config, round-trip parse it once to verify validity.","Validate the config at app startup and surface the parse error to the user, not just a log.","Keep SparkConfig serde fields #[serde(default)] where possible so minor schema drift doesn't hard-fail."],"tags":["toml","config","parsing","rust"],"backgroundTag":"toml-parse-error","analyzedSha":"1364a437f30122558a70ad703acc23d48f144ee6","analyzedAt":"2026-09-13T03:17:48.802Z","contentChangedAt":"2026-09-13T03:17:48.802Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}