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))
|
Err(Error(ErrorCode::UnexpectedValue))
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
if error == "success" && map.contains_key("data") {
|
let data = if error == "success" {
|
||||||
match map["data"] {
|
Ok(&map["data"])
|
||||||
|
} else {
|
||||||
|
Err(Error(ErrorCode::MpvError(error.to_string())))
|
||||||
|
}?;
|
||||||
|
|
||||||
|
match data {
|
||||||
Value::Bool(b) => Ok(b.to_string()),
|
Value::Bool(b) => Ok(b.to_string()),
|
||||||
Value::Number(ref n) => Ok(n.to_string()),
|
Value::Number(ref n) => Ok(n.to_string()),
|
||||||
Value::String(ref s) => Ok(s.to_string()),
|
Value::String(ref s) => Ok(s.to_string()),
|
||||||
Value::Array(ref array) => Ok(format!("{:?}", array)),
|
Value::Array(ref array) => Ok(format!("{:?}", array)),
|
||||||
Value::Object(ref map) => Ok(format!("{:?}", map)),
|
Value::Object(ref map) => Ok(format!("{:?}", map)),
|
||||||
_ => Err(Error(ErrorCode::UnsupportedType)),
|
Value::Null => Err(Error(ErrorCode::MissingValue)),
|
||||||
}
|
|
||||||
} 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())))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ pub enum ErrorCode {
|
||||||
JsonContainsUnexptectedType,
|
JsonContainsUnexptectedType,
|
||||||
UnexpectedResult,
|
UnexpectedResult,
|
||||||
UnexpectedValue,
|
UnexpectedValue,
|
||||||
|
MissingValue,
|
||||||
UnsupportedType,
|
UnsupportedType,
|
||||||
ValueDoesNotContainBool,
|
ValueDoesNotContainBool,
|
||||||
ValueDoesNotContainF64,
|
ValueDoesNotContainF64,
|
||||||
|
@ -190,6 +191,7 @@ impl Display for ErrorCode {
|
||||||
}
|
}
|
||||||
ErrorCode::UnexpectedResult => f.write_str("Unexpected result received"),
|
ErrorCode::UnexpectedResult => f.write_str("Unexpected result received"),
|
||||||
ErrorCode::UnexpectedValue => f.write_str("Unexpected value 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::UnsupportedType => f.write_str("Unsupported type received"),
|
||||||
ErrorCode::ValueDoesNotContainBool => {
|
ErrorCode::ValueDoesNotContainBool => {
|
||||||
f.write_str("The received value is not of type \'std::bool\'")
|
f.write_str("The received value is not of type \'std::bool\'")
|
||||||
|
|
Loading…
Reference in New Issue