fix: resolve unreachable pattern warning in image paste PR #2823#2826
fix: resolve unreachable pattern warning in image paste PR #2823#2826Dhilan-Panjabi wants to merge 4 commits intoantinomyhq:mainfrom
Conversation
crates/forge_main/src/editor.rs
Outdated
| if let Ok(mut f) = std::fs::OpenOptions::new() | ||
| .create(true) | ||
| .append(true) | ||
| .open("/tmp/forge_paste.log") | ||
| { | ||
| let _ = writeln!(&mut f, "Received !forge_internal_paste_image"); | ||
| use std::io::Write; | ||
| } |
There was a problem hiding this comment.
Debug logging code appears to have been accidentally left in production code. This creates a file at /tmp/forge_paste.log on every paste attempt, which could fill up disk space over time and expose user activity. This block should be removed:
if let Ok(mut f) = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open("/tmp/forge_paste.log")
{
let _ = writeln!(&mut f, "Received !forge_internal_paste_image");
use std::io::Write;
}Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
crates/forge_main/src/image_paste.rs
Outdated
| let home_dir = std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()); | ||
| let images_dir = PathBuf::from(home_dir).join(".local/share/forge/images"); |
There was a problem hiding this comment.
Using HOME environment variable for cross-platform path resolution is unreliable. On Windows, HOME is typically not set, causing this to fall back to /tmp which also doesn't exist on Windows. This will cause directory creation to fail silently, and image pasting won't work on Windows. Should use dirs::data_local_dir() or similar platform-aware solution:
use dirs;
fn get_images_dir() -> Option<PathBuf> {
let base_dir = dirs::data_local_dir()?;
let images_dir = base_dir.join("forge/images");
std::fs::create_dir_all(&images_dir).ok()?;
Some(images_dir)
}Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
…chable pattern warning
…or cross-platform paths - Remove leftover debug logging to /tmp/forge_paste.log in editor.rs - Replace HOME env var with dirs::data_local_dir() for cross-platform image directory resolution in image_paste.rs - Add dirs workspace dependency to forge_main
c0ba32d to
30d78bf
Compare
Fixes the unreachable pattern warning introduced in #2823.
Problem
The
Pastevariant was incorrectly placed betweenAgentSwitch's#[strum(props(...))]" attribute and its variant declaration, causing two strum attributes to stack onPasteand leavingAgentSwitch` without its metadata.Fix
PasteandAgentSwitchinto their own properly annotated blocksBuilds clean with zero warnings.