{"record":{"id":"9fbddb4bf48b3f5c","repo":"Hmbown/CodeWhale","slug":"tempdir","errorCode":null,"errorMessage":"tempdir","messagePattern":"tempdir","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/config/src/tests.rs","lineNumber":4215,"sourceCode":"    fs::write(&path, \"model = \\\"new-model\\\"\\n\").expect(\"seed config\");\n    let backup_path = config_backup_path(&path);\n    fs::write(\n        &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);","sourceCodeStart":4197,"sourceCodeEnd":4233,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/config/src/tests.rs#L4197-L4233","documentation":"tempfile::tempdir().expect(\"tempdir\") in config_store_save_preserves_comments (crates/config/src/tests.rs:4215) panics if a temporary directory cannot be created. Similar tempdir expects appear across the codebase (e.g. crates/agent/src/lib.rs:2237). tempfile fails when it cannot find a writable temp location or lacks permission.","triggerScenarios":"TMPDIR points to a nonexistent or read-only directory; TMPDIR unset with /tmp unwritable (sandboxed/locked-down CI runner); disk full.","commonSituations":"Containerized CI with read-only /tmp; setting TMPDIR to a path that does not exist; running tests as a restricted user.","solutions":["Ensure TMPDIR is set to an existing writable directory (or unset it to fall back to /tmp).","Check disk space and mount flags on the temp filesystem.","In restricted environments, set tempfile's env override to a directory inside the workspace before running cargo test."],"exampleFix":"// before\ncargo test -p codewhale-config   # TMPDIR=/nonexistent\n// after\nexport TMPDIR=$(mktemp -d)\ncargo test -p codewhale-config","handlingStrategy":"fallback","validationCode":"let tmp = std::env::var(\"TMPDIR\").unwrap_or_else(|_| \"/tmp\".into());\nassert!(std::path::Path::new(&tmp).is_dir(), \"TMPDIR {tmp} is not a directory\");","typeGuard":null,"tryCatchPattern":"let dir = tempfile::tempdir()\n    .unwrap_or_else(|e| panic!(\"tempdir unavailable ({e}); check TMPDIR and /tmp permissions\"));","preventionTips":["Keep TMPDIR pointed at an existing writable directory in CI","Check disk space on the temp filesystem","In sandboxes, create a workspace-local temp dir and export TMPDIR before cargo test"],"tags":["test","tempdir","filesystem","environment"],"backgroundTag":"missing-env-var","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"}