{"record":{"id":"9c934bac67724e23","repo":"Schniz/fnm","slug":"can-t-get-a-temporary-file","errorCode":null,"errorMessage":"Can't get a temporary file","messagePattern":"Can't get a temporary file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/archive/zip.rs","lineNumber":22,"sourceCode":"use std::io::{self, Read};\nuse std::path::Path;\nuse tempfile::tempfile;\nuse zip::read::ZipArchive;\n\npub struct Zip<R: Read> {\n    response: R,\n}\n\nimpl<R: Read> Zip<R> {\n    #[allow(dead_code)]\n    pub fn new(response: R) -> Self {\n        Self { response }\n    }\n}\n\nimpl<R: Read> Extract for Zip<R> {\n    fn extract_into(mut self: Box<Self>, path: &Path) -> Result<(), Error> {\n        let mut tmp_zip_file = tempfile().expect(\"Can't get a temporary file\");\n\n        debug!(\"Created a temporary zip file\");\n        io::copy(&mut self.response, &mut tmp_zip_file)?;\n        debug!(\n            \"Wrote zipfile successfully. Now extracting into {}.\",\n            path.display()\n        );\n\n        let mut archive = ZipArchive::new(&mut tmp_zip_file)?;\n\n        for i in 0..archive.len() {\n            let mut file = archive.by_index(i)?;\n            let outpath = path.join(file.mangled_name());\n\n            {\n                let comment = file.comment();\n                if !comment.is_empty() {\n                    debug!(\"File {i} comment: {comment}\");","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/Schniz/fnm/blob/86adc9676ceb2a509b21e75e74048b93c89f097d/src/archive/zip.rs#L4-L40","documentation":"When a Node install artifact is a zip (the Windows distribution path), `Zip::extract_into` first streams the download into an unnamed temp file created by `tempfile::tempfile()` in the OS temp dir (TMPDIR/TEMP/TMP, else the system temp). Any io::Error from creating that file hits `.expect(\"Can't get a temporary file\")` and panics, aborting the install mid-flight.","triggerScenarios":"`fnm install <version>` (zip-based artifact, typically Windows) when the temp dir is missing, unwritable, full, or the process exhausted its file-descriptor quota — e.g. TMPDIR=/nonexistent, a full tmpfs /tmp, or a sandbox (Snap/Flatpak) denying writes to the default temp location.","commonSituations":"Docker/CI overriding TMPDIR to a path that was never created; small tmpfs /tmp filling during large downloads; TEMP pointing to a deleted per-user temp folder after cleanup tools ran; disk quota exhaustion on multi-tenant runners.","solutions":["Point temp at a writable dir and retry: Windows `set TEMP=C:\\Users\\me\\AppData\\Local\\Temp` / Unix `TMPDIR=/var/tmp fnm install 20`.","Create the configured temp dir if missing: `mkdir -p \"$TMPDIR\"` (or recreate %TEMP%).","Free space on the temp volume and raise tmpfs size or relocate it (`tmpfs` in /etc/fstab).","If patching fnm: replace `.expect(...)` with `.map_err(|e| anyhow::anyhow!(\"can't create temp file: {e}\"))?` so it reports instead of panicking."],"exampleFix":"// before (src/archive/zip.rs)\nlet mut tmp_zip_file = tempfile().expect(\"Can't get a temporary file\");\n\n// after\nlet mut tmp_zip_file = tempfile()\n    .map_err(|e| anyhow::anyhow!(\"Can't get a temporary file: {e}\"))?;","handlingStrategy":"validation","validationCode":"fn temp_dir_writable() -> bool {\n    let dir = std::env::temp_dir();\n    std::fs::create_dir_all(&dir).is_ok()\n        && tempfile::tempfile().is_ok()\n};\n// also check free space: statvfs / GetDiskFreeSpaceEx before large installs","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(|| fnm_install(version)) // or invoke the binary\n    .unwrap_or_else(|_| {\n        eprintln!(\"install failed — check TMPDIR/TEMP writability and disk space\");\n        std::process::exit(1);\n    });","preventionTips":["Pin TMPDIR/TEMP to a known writable directory in CI and containers.","Ensure the temp volume has headroom larger than the Node zip before installing.","Monitor disk space on tmpfs mounts; prefer disk-backed /var/tmp for big downloads."],"tags":["rust","zip","temp-file","install","windows","disk-space","panic"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"86adc9676ceb2a509b21e75e74048b93c89f097d","analyzedAt":"2026-08-16T21:43:05.725Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}