{"record":{"id":"fd9ef63d1ab6aa65","repo":"stamparm/maltrail","slug":"create-harness-dir","errorCode":null,"errorMessage":"create harness dir","messagePattern":"create harness dir","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sensor/src/testkit.rs","lineNumber":91,"sourceCode":"    /// A harness whose events go to a CALLER-CHOSEN log directory, so several harnesses can be\n    /// pointed at one directory and made to race on the daily log file.\n    pub fn with_log_dir(log_dir: &std::path::Path, trails: &[(&str, &str, &str)]) -> Harness {\n        Harness::with_options_in(trails, HarnessOptions::quiet(), Some(log_dir))\n    }\n\n    pub fn with_options(trails: &[(&str, &str, &str)], options: HarnessOptions) -> Harness {\n        Harness::with_options_in(trails, options, None)\n    }\n\n    fn with_options_in(\n        trails: &[(&str, &str, &str)],\n        options: HarnessOptions,\n        shared_log_dir: Option<&std::path::Path>,\n    ) -> Harness {\n        let id = COUNTER.fetch_add(1, Ordering::Relaxed);\n        let dir = std::env::temp_dir().join(format!(\"maltrail-harness-{}-{}\", std::process::id(), id));\n        let _ = std::fs::remove_dir_all(&dir);\n        std::fs::create_dir_all(&dir).expect(\"create harness dir\");\n        let log_dir = match shared_log_dir {\n            Some(p) => p.to_path_buf(),\n            None => dir.join(\"logs\"),\n        };\n        std::fs::create_dir_all(&log_dir).expect(\"create log dir\");\n\n        let trails_file = dir.join(\"trails.csv\");\n        std::fs::write(&trails_file, \"\").expect(\"write trails\");\n\n        let root = repo_root();\n        let config_file = dir.join(\"harness.conf\");\n        let mut config_text = format!(\n            \"MONITOR_INTERFACE any\\n\\\n             CAPTURE_BUFFER 1MB\\n\\\n             PROCESS_COUNT 1\\n\\\n             UPDATE_PERIOD 999999999\\n\\\n             DISABLE_CHECK_SUDO true\\n\\\n             USE_CONDENSED_STORAGE false\\n\\","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/stamparm/maltrail/blob/77cfb06d7606506d101bbcec0786c77166c4255e/sensor/src/testkit.rs#L73-L109","documentation":"The test harness with_options_in() creates a unique temp directory per harness instance (maltrail-harness-{pid}-{id}) via std::fs::create_dir_all and panics with \"create harness dir\" on failure. Because the stale directory is removed first, failure generally means a filesystem/permission/environment problem, not a leftover directory.","triggerScenarios":"Calling Harness::with_options_in() when std::env::temp_dir() is unwritable, full, or on a read-only filesystem, so create_dir_all(dir) returns Err after the remove_dir_all cleanup.","commonSituations":"TMPDIR pointing to a non-existent or unwritable path; disk-full /tmp in CI; running tests as a user without write permission on the temp dir; stale harness dirs owned by another user (pid collision after container restart).","solutions":["Check TMPDIR/std::env::temp_dir() resolves to a writable existing directory","Free disk space on the temp filesystem if it is full","Remove stale maltrail-harness-* directories owned by other UIDs from the temp dir","Include the io::Error and dir path in the panic message for diagnosis"],"exampleFix":"// before\nstd::fs::create_dir_all(&dir).expect(\"create harness dir\");\n// after\nstd::fs::create_dir_all(&dir)\n    .unwrap_or_else(|e| panic!(\"create harness dir {}: {e}\", dir.display()));","handlingStrategy":"validation","validationCode":"let td = std::env::temp_dir(); assert!(td.is_dir() && td.metadata().map(|m| m.permissions().writable()).unwrap_or(false), \"temp dir {} not writable\", td.display());","typeGuard":"fn temp_dir_writable() -> bool { let td = std::env::temp_dir(); td.is_dir() && std::fs::create_dir_all(td.join(\".wprobe\")).is_ok() && std::fs::remove_dir(td.join(\".wprobe\")).is_ok() }","tryCatchPattern":"std::fs::create_dir_all(&dir).unwrap_or_else(|e| panic!(\"create harness dir {}: {e}\", dir.display()));","preventionTips":["Sanity-check TMPDIR at test start","Clean stale maltrail-harness-* dirs owned by other users","Monitor temp filesystem free space in CI"],"tags":["rust","filesystem","test-harness","tempdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"77cfb06d7606506d101bbcec0786c77166c4255e","analyzedAt":"2026-09-13T03:50:16.010Z","contentChangedAt":"2026-09-13T03:50:16.010Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}