Merge pull request 'fix(#12): map libraw error codes to human-readable strings' (#25) from fix/issue-12 into master
This commit is contained in:
commit
761f16bbea
24
src/main.rs
24
src/main.rs
@ -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
|
/// Photo Editor - A Rust-based photo editor with RAW image processing capabilities using libraw
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[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()) };
|
let ret = unsafe { libraw_open_file(lr, input_cstr.as_ptr()) };
|
||||||
|
|
||||||
if ret != LIBRAW_SUCCESS {
|
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) };
|
unsafe { libraw_close(lr) };
|
||||||
return Err("Failed to open file".into());
|
return Err("Failed to open file".into());
|
||||||
}
|
}
|
||||||
@ -233,7 +249,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Process the RAW data
|
// Process the RAW data
|
||||||
let ret = unsafe { libraw_unpack(lr) };
|
let ret = unsafe { libraw_unpack(lr) };
|
||||||
if ret != LIBRAW_SUCCESS {
|
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) };
|
unsafe { libraw_close(lr) };
|
||||||
return Err("Failed to unpack RAW data".into());
|
return Err("Failed to unpack RAW data".into());
|
||||||
}
|
}
|
||||||
@ -248,7 +264,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Process the image
|
// Process the image
|
||||||
let ret = unsafe { libraw_dcraw_process(lr) };
|
let ret = unsafe { libraw_dcraw_process(lr) };
|
||||||
if ret != LIBRAW_SUCCESS {
|
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) };
|
unsafe { libraw_close(lr) };
|
||||||
return Err("Failed to process image".into());
|
return Err("Failed to process image".into());
|
||||||
}
|
}
|
||||||
@ -300,7 +316,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if ret != LIBRAW_SUCCESS {
|
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) };
|
unsafe { libraw_close(lr) };
|
||||||
return Err("Failed to write output file".into());
|
return Err("Failed to write output file".into());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user