{"record":{"id":"f6182b3e511bfd26","repo":"stamparm/maltrail","slug":"write-trails","errorCode":null,"errorMessage":"write trails","messagePattern":"write trails","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sensor/src/testkit.rs","lineNumber":99,"sourceCode":"    }\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\\\n             LOG_DIR {}\\n\\\n             TRAILS_FILE {}\\n\",\n            options.use_heuristics,","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/stamparm/maltrail/blob/77cfb06d7606506d101bbcec0786c77166c4255e/sensor/src/testkit.rs#L81-L117","documentation":"with_options_in() seeds the harness with an empty trails.csv using std::fs::write and panics with \"write trails\" on failure. The directory was just created by the harness, so failure points to filesystem-level problems (permissions, disk full, path issues) rather than a missing parent directory.","triggerScenarios":"Calling Harness::with_options_in() when writing dir/trails.csv fails — read-only filesystem, disk quota exceeded, or the harness dir was concurrently deleted.","commonSituations":"Disk-full CI runners; tests executing on a read-only mount; security software deleting/quarantining files in temp dirs; pid-collision harness dirs owned by another user.","solutions":["Check free space and writability of std::env::temp_dir()","Remove stale maltrail-harness-* directories and rerun","Avoid external processes cleaning temp files mid-test; use a dedicated TMPDIR for the test run","Include the file path and io::Error in the panic message"],"exampleFix":"// before\nstd::fs::write(&trails_file, \"\").expect(\"write trails\");\n// after\nstd::fs::write(&trails_file, \"\")\n    .unwrap_or_else(|e| panic!(\"write trails {}: {e}\", trails_file.display()));","handlingStrategy":"try-catch","validationCode":"assert!(dir.metadata().map(|m| m.permissions().writable()).unwrap_or(false), \"harness dir {} not writable\", dir.display());","typeGuard":null,"tryCatchPattern":"std::fs::write(&trails_file, \"\").unwrap_or_else(|e| panic!(\"write trails {}: {e}\", trails_file.display()));","preventionTips":["Check temp filesystem free space before large test runs","Prevent external temp cleaners from racing tests","Use a dedicated TMPDIR per CI job"],"tags":["rust","filesystem","test-harness","file-write"],"backgroundTag":"file-write-failed","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"}