cholcombe973 / block-utils

Rust utilities for working with block devices
MIT License
22 stars 17 forks source link

Error handling serde_json::from_str() return in nvme.rs functions #42

Open robsonsmartins opened 1 year ago

robsonsmartins commented 1 year ago

There is a bug in handling the return of serde_json::from_str() in the nvme.rs functions (get_error_log, get_firmware_log and get_smart_log):

let deserialized: String = serde_json::from_str(&stdout)?;

The serde_json::from_str() function returns a Value and not a String.

Perhaps the best thing is that the get_error_log, get_firmware_log and get_smart_log functions were rewritten to return BlockResult<Value> instead of BlockResult<String>, so the user could call, for example:

let log = get_firmware_log(&device_path).expect("error getting log");
println!("temp: {:.2} ºC", log.get("temperature").and_then(Value::as_f64).unwrap_or_default() - 273.15);
cholcombe973 commented 1 year ago

I think someone else raised a similar issue. I agree it should return a Result instead. Would you like to make the change?

robsonsmartins commented 1 year ago

I think someone else raised a similar issue. I agree it should return a Result instead. Would you like to make the change?

I submitted this pull request: #43

cholcombe973 commented 1 year ago

Thanks!