fix(#12): human-readable libraw error messages

This commit is contained in:
opencode 2026-07-05 14:50:40 +00:00
parent 2d1a157f33
commit 35d5dc6b2d

View File

@ -55,6 +55,22 @@ fn sanitize_path(
}
}
/// Map libraw error codes to human-readable strings.
fn libraw_error_string(code: c_int) -> &'static str {
match code {
0 => "Success",
-1 => "General failure (LIBRAW_ERROR_UNSUCCESSFUL)",
-2 => "Unsupported file format",
-3 => "File open failed (LIBRAW_ERROR_FILE_OPEN_FAIL)",
-4 => "File is not recognized as RAW",
-5 => "Out of memory",
-6 => "File read failed",
-7 => "Internal error",
-8 => "Unsupported operation",
_ => "Unknown error code",
}
}
/// Photo Editor - A Rust-based photo editor with RAW image processing capabilities using libraw
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
@ -223,7 +239,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let ret = unsafe { libraw_open_file(lr, input_cstr.as_ptr()) };
if ret != LIBRAW_SUCCESS {
eprintln!("Error: Failed to open file. Error code: {}", ret);
eprintln!("Error: Failed to open file: {}", libraw_error_string(ret));
unsafe { libraw_close(lr) };
return Err("Failed to open file".into());
}
@ -233,7 +249,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Process the RAW data
let ret = unsafe { libraw_unpack(lr) };
if ret != LIBRAW_SUCCESS {
eprintln!("Error: Failed to unpack RAW data. Error code: {}", ret);
eprintln!("Error: Failed to unpack RAW data: {}", libraw_error_string(ret));
unsafe { libraw_close(lr) };
return Err("Failed to unpack RAW data".into());
}
@ -248,7 +264,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Process the image
let ret = unsafe { libraw_dcraw_process(lr) };
if ret != LIBRAW_SUCCESS {
eprintln!("Error: Failed to process image. Error code: {}", ret);
eprintln!("Error: Failed to process image: {}", libraw_error_string(ret));
unsafe { libraw_close(lr) };
return Err("Failed to process image".into());
}
@ -300,7 +316,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
};
if ret != LIBRAW_SUCCESS {
eprintln!("Error: Failed to write output file. Error code: {}", ret);
eprintln!("Error: Failed to write output file: {}", libraw_error_string(ret));
unsafe { libraw_close(lr) };
return Err("Failed to write output file".into());
}