{"record":{"id":"43aeb882d69bd18c","repo":"Hmbown/CodeWhale","slug":"write-config","errorCode":null,"errorMessage":"write config","messagePattern":"write config","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/config/src/tests.rs","lineNumber":4218,"sourceCode":"        &backup_path,\n        \"api_key = \\\"old-test-credential\\\"\\nmodel = \\\"old-model\\\"\\n\",\n    )\n    .expect(\"seed backup\");\n\n    scrub_plaintext_api_keys_from_config_backup(&path).expect(\"scrub backup\");\n\n    let backup = fs::read_to_string(backup_path).expect(\"read backup\");\n    assert!(!backup.contains(\"old-test-credential\"), \"{backup}\");\n    assert!(!backup.contains(\"api_key\"), \"{backup}\");\n    assert!(backup.contains(\"model = \\\"old-model\\\"\"));\n}\n\n#[test]\nfn config_store_save_preserves_comments() {\n    let dir = tempfile::tempdir().expect(\"tempdir\");\n    let config_path = dir.path().join(CONFIG_FILE_NAME);\n    let original = \"# my model\\nmodel = \\\"deepseek-v4-flash\\\"\\n# end comment\\n\";\n    fs::write(&config_path, original).expect(\"write config\");\n\n    let mut store = ConfigStore::load(Some(config_path.clone())).expect(\"load config store\");\n    store.config.model = Some(\"deepseek-v4-pro\".to_string());\n    store.save().expect(\"save\");\n\n    let body = fs::read_to_string(&config_path).expect(\"read config\");\n    assert!(body.contains(\"# my model\"), \"prefix comment preserved\");\n    assert!(body.contains(\"# end comment\"), \"suffix comment preserved\");\n    assert!(body.contains(\"model = \\\"deepseek-v4-pro\\\"\"));\n}\n\n#[test]\nfn config_store_save_preserves_disabled_keys() {\n    let dir = tempfile::tempdir().expect(\"tempdir\");\n    let config_path = dir.path().join(CONFIG_FILE_NAME);\n    fs::write(\n        &config_path,\n        \"# my note\\nmodel = \\\"deepseek-v4-flash\\\"\\n# base_url = \\\"http://localhost:11434/v1\\\"\\n\",","sourceCodeStart":4200,"sourceCodeEnd":4236,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/config/src/tests.rs#L4200-L4236","documentation":"fs::write(&config_path, original).expect(\"write config\") in config_store_save_preserves_comments panics when seeding the test's config.toml fails. The fixture writes a commented TOML file to verify ConfigStore::save preserves comments; failure is purely environmental or path-related.","triggerScenarios":"The parent directory (from tempdir) was already dropped; config_path points at an existing directory; permissions or a full disk block the write.","commonSituations":"Refactoring the test so dir is dropped (tempdir deletes on drop) before writes; typos joining the path; read-only CI filesystem.","solutions":["Keep the TempDir binding alive for the whole test (tempdir removes the tree when dropped).","Inspect the io::Error kind: NotFound -> missing dir, IsADirectory -> wrong target, PermissionDenied -> perms.","Run the single test in isolation to rule out cross-test interference."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert!(config_path.parent().map(|p| p.is_dir()).unwrap_or(false), \"fixture dir missing\");","typeGuard":null,"tryCatchPattern":"fs::write(&config_path, original)\n    .unwrap_or_else(|e| panic!(\"write config failed ({e:?}); is the tempdir alive?\"));","preventionTips":["Bind the TempDir to a variable and keep it alive for the whole test","Write fixtures immediately after creating the tempdir","Confirm the target is a file path, not a directory"],"tags":["test","filesystem","io","fixture"],"backgroundTag":"file-write-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}