{"record":{"id":"7f27fdce76be32e2","repo":"stamparm/maltrail","slug":"create-log-dir","errorCode":null,"errorMessage":"create log dir","messagePattern":"create log dir","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sensor/src/testkit.rs","lineNumber":96,"sourceCode":"\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\\\n             SENSOR_NAME harness\\n\\\n             SCAN_WINDOW 30\\n\\\n             USE_HEURISTICS {}\\n\\\n             CHECK_HOST_DOMAINS {}\\n\\\n             CHECK_MISSING_HOST {}\\n\\","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/stamparm/maltrail/blob/77cfb06d7606506d101bbcec0786c77166c4255e/sensor/src/testkit.rs#L78-L114","documentation":"Right after creating the harness directory, with_options_in() creates the logs subdirectory (or uses the shared log dir) with std::fs::create_dir_all and panics with \"create log dir\" on failure. When a shared_log_dir is supplied, that pre-existing path must be writable; otherwise the fresh harness dir's logs/ must be creatable.","triggerScenarios":"Calling Harness::with_options_in() where dir.join(\"logs\") cannot be created (filesystem error), or the provided shared_log_dir path does not exist and cannot be created (bad path, permissions, disk full).","commonSituations":"Passing a shared_log_dir pointing at a file instead of a directory or an unwritable path; read-only test volume; race where another process deleted the shared log dir between calls.","solutions":["Verify the shared_log_dir path exists, is a directory, and is writable before calling with_options_in","Pass None to let the harness manage its own logs subdirectory if the shared path is unreliable","Check disk space and permissions on the temp filesystem","Include the log_dir path and io::Error in the panic message"],"exampleFix":"// before\nstd::fs::create_dir_all(&log_dir).expect(\"create log dir\");\n// after\nstd::fs::create_dir_all(&log_dir)\n    .unwrap_or_else(|e| panic!(\"create log dir {}: {e}\", log_dir.display()));","handlingStrategy":"validation","validationCode":"if let Some(p) = shared_log_dir { assert!(p.is_dir() && p.metadata().map(|m| m.permissions().writable()).unwrap_or(false), \"shared_log_dir {} not a writable dir\", p.display()); }","typeGuard":"fn usable_log_dir(p: &std::path::Path) -> bool { p.is_dir() && p.metadata().map(|m| m.permissions().writable()).unwrap_or(false) }","tryCatchPattern":"std::fs::create_dir_all(&log_dir).unwrap_or_else(|e| panic!(\"create log dir {}: {e}\", log_dir.display()));","preventionTips":["Pass only existing writable directories as shared_log_dir","Prefer harness-managed logs (None) unless sharing is required","Verify the shared dir survives the whole test run"],"tags":["rust","filesystem","test-harness","logging"],"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"}