{"record":{"id":"dfcc8dd48e90b592","repo":"sinelaw/fresh","slug":"sudosaverequired","errorCode":null,"errorMessage":"SudoSaveRequired","messagePattern":"SudoSaveRequired","errorType":"error_code","errorClass":"SudoSaveRequired","httpStatus":null,"severity":"error","filePath":"crates/fresh-editor-core/src/model/buffer/save.rs","lineNumber":569,"sourceCode":"    #[cfg(unix)]\n    let (uid, gid, mode) = if let Some(ref meta) = original_metadata {\n        (\n            meta.uid.unwrap_or(0),\n            meta.gid.unwrap_or(0),\n            meta.permissions\n                .as_ref()\n                .map(|p| p.mode() & 0o7777)\n                .unwrap_or(0),\n        )\n    } else {\n        (0, 0, 0)\n    };\n    #[cfg(not(unix))]\n    let (uid, gid, mode) = (0u32, 0u32, 0u32);\n\n    let _ = original_metadata; // suppress unused warning on non-Unix\n\n    anyhow::anyhow!(SudoSaveRequired {\n        temp_path,\n        dest_path: dest_path.to_path_buf(),\n        uid,\n        gid,\n        mode,\n    })\n}\n","sourceCodeStart":551,"sourceCodeEnd":577,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor-core/src/model/buffer/save.rs#L551-L577","documentation":"An in-place save could not write the destination file directly because the process lacks the file owner's privileges (uid/gid/mode mismatch). save.rs:569 raises the structured SudoSaveRequired error (via make_sudo_error, from save_with_inplace_write or write_data_inplace) carrying temp_path, dest_path, uid, gid, and mode so the caller can retry the save with elevated (sudo) privileges.","triggerScenarios":"Editing a file owned by root (or another user) as a non-root process and saving in place — the write requires the file's uid/gid/mode to be preserved but the process isn't the owner.","commonSituations":"Editing /etc config files or root-owned project files in a normal user session; files created by a container as root then edited by the host user; NFS/ACL setups where the effective uid differs from the file owner.","solutions":["Handle the SudoSaveRequired payload: complete the save using the provided temp_path and elevate (e.g. sudo install -m mode -o uid -g gid temp_path dest_path)","Reopen the editor with elevated privileges (sudo fresh file) for system-owned files","Change ownership/permissions of the file (sudo chown) so your user can write it in place","Save to a writable copy instead of the privileged original"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Unix: check write ownership before attempting in-place save\nlet meta = std::fs::metadata(&dest_path)?;\nlet i_am_owner = unsafe { libc::geteuid() } == meta.uid();\nif !i_am_owner { prepare_sudo_save_flow(&dest_path); }","typeGuard":null,"tryCatchPattern":"// downcast to the structured error\nmatch editor.save(buffer_id) {\n    Err(e) if e.downcast_ref::<SudoSaveRequired>().is_some() => {\n        let s = e.downcast_ref::<SudoSaveRequired>().unwrap();\n        sudo_complete_save(&s.temp_path, &s.dest_path, s.uid, s.gid, s.mode);\n    }\n    other => other?,\n}","preventionTips":["Check file ownership/permissions before opening system files for editing","Run the editor with adequate privileges (sudo) when editing root-owned files","Detect the SudoSaveRequired error type and implement the elevated-save handoff in your integration"],"tags":["file-save","permissions","sudo","rust"],"backgroundTag":"permission-denied","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}