{"record":{"id":"d5964a92597c03d6","repo":"emilk/egui","slug":"failed-to-save-screenshot-to-path-err","errorCode":null,"errorMessage":"Failed to save screenshot to {path:?}: {err}","messagePattern":"Failed to save screenshot to (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/native/glow_integration.rs","lineNumber":1773,"sourceCode":"fn save_screenshot_and_exit(\n    path: &str,\n    painter: &egui_glow::Painter,\n    screen_size_in_pixels: [u32; 2],\n) {\n    assert!(\n        egui::load::has_extension(path, \"png\"),\n        \"Expected EFRAME_SCREENSHOT_TO to end with '.png', got {path:?}\"\n    );\n    let screenshot = painter.read_screen_rgba(screen_size_in_pixels);\n    image::save_buffer(\n        path,\n        screenshot.as_raw(),\n        screenshot.width() as u32,\n        screenshot.height() as u32,\n        image::ColorType::Rgba8,\n    )\n    .unwrap_or_else(|err| {\n        panic!(\"Failed to save screenshot to {path:?}: {err}\");\n    });\n    log::info!(\"Screenshot saved to {path:?}.\");\n\n    #[expect(clippy::exit)]\n    std::process::exit(0);\n}\n","sourceCodeStart":1755,"sourceCodeEnd":1780,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/eframe/src/native/glow_integration.rs#L1755-L1780","documentation":"In eframe's glow integration, when the app exits with `screenshot_on_save`/`--screenshot` behavior, `save_screenshot_and_exit` writes the captured framebuffer to disk with the `image` crate. If `image::save_buffer` fails (bad path, unwritable directory, I/O error), the code panics with this message before calling `std::process::exit(0)`.","triggerScenarios":"Running an eframe app in screenshot mode (e.g. `NativeOptions { screenshot_on_save: true }` or CLI screenshot flag) where the target `path` is invalid, the parent directory doesn't exist, the process lacks write permission, or the disk is full so `image::save_buffer` returns Err.","commonSituations":"CI pipelines running headless screenshot tests with a relative output path that resolves to a non-existent directory; read-only containers passing an unwritable path; typos in the screenshot file path or unsupported extension.","solutions":["Ensure the parent directory of the screenshot path exists (create it with `std::fs::create_dir_all` before running).","Verify the path is writable by the user running the app (fix permissions or choose another output location).","Check the embedded `err` in the panic message for the underlying I/O cause (e.g. NotFound, PermissionDenied) and address it.","If path is constructed at runtime, log/validate it before the run; use an absolute path to avoid CWD surprises in CI."],"exampleFix":"// before\nstd::fs::create_dir(\"screenshots\")?; // fails if exists, or wrong dir\n// after\nstd::fs::create_dir_all(\"screenshots/shots\")?; // ensure full path exists before screenshot mode writes there","handlingStrategy":"validation","validationCode":"let path = std::path::Path::new(\"shots/app.png\");\nif let Some(dir) = path.parent() {\n    std::fs::create_dir_all(dir).expect(\"create screenshot dir\");\n}\nassert!(!dir_is_readonly(dir), \"screenshot dir must be writable\");","typeGuard":null,"tryCatchPattern":"// if writing screenshots yourself:\nif let Err(err) = image::save_buffer(path, data, w, h, image::ColorType::Rgba8) {\n    log::error!(\"screenshot save failed: {err}\");\n    // fallback path or exit non-zero without panic\n}","preventionTips":["Always create the output directory (create_dir_all) before enabling screenshot mode.","Use absolute paths for screenshot output so CI/daemon CWD differences can't break writes.","Check disk space and permissions in CI before screenshot tests.","Pick a widely-supported extension (.png) so the image encoder is available."],"tags":["io","screenshot","file-write-failed","panic"],"backgroundTag":"file-write-failed","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}