You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error handling could use a rework. There's many places in the Rust code where we call unwrap() for things like file system access or downloading stuff, which means Cultivation will crash if any of those operations fail. I think if such an operation fails, we should display that error on the frontend such as with a pop up message. The Rust code will need refactoring first though, so we return Results to the frontend instead of crashing.
The text was updated successfully, but these errors were encountered:
I came up with a really simple way to handle errors on the Rust side: https://github.com/Seeker14491/anyhow-tauri. It's just a fork of the popular error handling library anyhow, but with a tiny tweak that lets you return its error type from Tauri commands. As an example, we can rewrite a function like this one in file_helpers.rs:
#[tauri::command]pubfnread_file(path:String) -> String{let path_buf = std::path::PathBuf::from(&path);letmut file = match fs::File::open(path_buf){Ok(file) => file,Err(e) => {println!("Failed to open file: {}", e);returnString::new();}};letmut contents = String::new();
file.read_to_string(&mut contents).unwrap();
contents
}
If the function errors, on the TypeScript side we can read the error and any context it might have. We can also optionally get a backtrace that shows where the error occurred, at least for debug builds.
Also, for file operations specifically, we can use the fs_err crate to get better error messages.
Error handling could use a rework. There's many places in the Rust code where we call
unwrap()
for things like file system access or downloading stuff, which means Cultivation will crash if any of those operations fail. I think if such an operation fails, we should display that error on the frontend such as with a pop up message. The Rust code will need refactoring first though, so we returnResult
s to the frontend instead of crashing.The text was updated successfully, but these errors were encountered: