fix potential bug
could potentially return MpvError("success")
This commit is contained in:
parent
fde2bce07d
commit
cc9f2cae53
17
src/ipc.rs
17
src/ipc.rs
|
@ -204,20 +204,19 @@ pub fn get_mpv_property_string(instance: &Mpv, property: &str) -> Result<String,
|
|||
Err(Error(ErrorCode::UnexpectedValue))
|
||||
}?;
|
||||
|
||||
if error == "success" && map.contains_key("data") {
|
||||
match map["data"] {
|
||||
let data = if error == "success" {
|
||||
Ok(&map["data"])
|
||||
} else {
|
||||
Err(Error(ErrorCode::MpvError(error.to_string())))
|
||||
}?;
|
||||
|
||||
match data {
|
||||
Value::Bool(b) => Ok(b.to_string()),
|
||||
Value::Number(ref n) => Ok(n.to_string()),
|
||||
Value::String(ref s) => Ok(s.to_string()),
|
||||
Value::Array(ref array) => Ok(format!("{:?}", array)),
|
||||
Value::Object(ref map) => Ok(format!("{:?}", map)),
|
||||
_ => Err(Error(ErrorCode::UnsupportedType)),
|
||||
}
|
||||
} else {
|
||||
// TODO: there is a bug here
|
||||
// this could return MpvError("success") if error == "success" but the map doesn't contain
|
||||
// data
|
||||
Err(Error(ErrorCode::MpvError(error.to_string())))
|
||||
Value::Null => Err(Error(ErrorCode::MissingValue)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ pub enum ErrorCode {
|
|||
JsonContainsUnexptectedType,
|
||||
UnexpectedResult,
|
||||
UnexpectedValue,
|
||||
MissingValue,
|
||||
UnsupportedType,
|
||||
ValueDoesNotContainBool,
|
||||
ValueDoesNotContainF64,
|
||||
|
@ -190,6 +191,7 @@ impl Display for ErrorCode {
|
|||
}
|
||||
ErrorCode::UnexpectedResult => f.write_str("Unexpected result received"),
|
||||
ErrorCode::UnexpectedValue => f.write_str("Unexpected value received"),
|
||||
ErrorCode::MissingValue => f.write_str("Missing value"),
|
||||
ErrorCode::UnsupportedType => f.write_str("Unsupported type received"),
|
||||
ErrorCode::ValueDoesNotContainBool => {
|
||||
f.write_str("The received value is not of type \'std::bool\'")
|
||||
|
|
Loading…
Reference in New Issue