Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
robsonsmartins opened this issue Aug 17, 2023 · 3 comments
Open

Comments

@robsonsmartins
Copy link

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
Copy link
Owner

cholcombe973 commented Aug 17, 2023

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

@robsonsmartins
Copy link
Author

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
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants