{"record":{"id":"93f1dda2e27eb889","repo":"herdrdev/herdr","slug":"failed-to-allocate-unique-clipboard-image-staging","errorCode":null,"errorMessage":"failed to allocate unique clipboard image staging path","messagePattern":"failed to allocate unique clipboard image staging path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/server/clipboard_image.rs","lineNumber":46,"sourceCode":"        let path = dir.join(format!(\n            \"client-{client_id}-clipboard-{unique}-{attempt}.{extension}\"\n        ));\n        let mut options = fs::OpenOptions::new();\n        options.write(true).create_new(true);\n        restrict_file_options(&mut options);\n        let mut file = match options.open(&path) {\n            Ok(file) => file,\n            Err(err) if err.kind() == io::ErrorKind::AlreadyExists => continue,\n            Err(err) => return Err(err),\n        };\n        file.write_all(data)?;\n        return Ok(StagedClipboardImage {\n            paste_text: path.to_string_lossy().into_owned(),\n            path,\n        });\n    }\n\n    Err(io::Error::new(\n        io::ErrorKind::AlreadyExists,\n        \"failed to allocate unique clipboard image staging path\",\n    ))\n}\n\npub(crate) fn remove_files(paths: Vec<PathBuf>) {\n    for path in paths {\n        let _ = fs::remove_file(path);\n    }\n}\n\nfn sanitize_extension(extension: &str) -> &'static str {\n    if extension.eq_ignore_ascii_case(\"png\") {\n        \"png\"\n    } else if extension.eq_ignore_ascii_case(\"jpg\") || extension.eq_ignore_ascii_case(\"jpeg\") {\n        \"jpg\"\n    } else if extension.eq_ignore_ascii_case(\"gif\") {\n        \"gif\"","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/herdrdev/herdr/blob/f457cff4f2648eee85d176f8a41861241d4e8428/src/server/clipboard_image.rs#L28-L64","documentation":"stage() tried to generate a unique temporary filename for a clipboard image by probing candidate paths, and every candidate already existed, so it gives up with ErrorKind::AlreadyExists. In practice collisions are near-impossible unless the staging directory is being flooded or the random source is deterministic.","triggerScenarios":"Repeated staging attempts where generated filenames collide with existing files in the staging dir, e.g. extremely high paste volume, a seeded/deterministic RNG, or a stale staging directory full of files with the same naming pattern.","commonSituations":"Bulk automated clipboard paste testing, staging dir shared across many concurrent processes, or tests reusing the same temp dir without cleanup.","solutions":["Retry the stage call; a fresh filename will almost certainly succeed","Clear stale files from the clipboard image staging directory","Ensure nothing is pre-creating files with the same naming scheme","If reproducible, check the uniqueness source used for filename generation"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"Err(e) if e.kind() == io::ErrorKind::AlreadyExists => retry stage()","preventionTips":["Clean stale staging files periodically","Use unique staging dirs per process in tests"],"tags":["clipboard","temp-file","name-collision","already-exists"],"backgroundTag":"temp-file-collision","analyzedSha":"f457cff4f2648eee85d176f8a41861241d4e8428","analyzedAt":"2026-08-28T15:41:09.197Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}