MpvError: add copy of command for better context
This commit is contained in:
+15
-3
@@ -8,8 +8,11 @@ use crate::{MpvDataType, Property};
|
||||
/// Any error that can occur when interacting with mpv.
|
||||
#[derive(Error, Debug)]
|
||||
pub enum MpvError {
|
||||
#[error("MpvError: {0}")]
|
||||
MpvError(String),
|
||||
#[error("Mpv returned error in response to command: {message}\nCommand: {command:#?}")]
|
||||
MpvError {
|
||||
command: Vec<Value>,
|
||||
message: String,
|
||||
},
|
||||
|
||||
#[error("Error communicating over mpv socket: {0}")]
|
||||
MpvSocketConnectionError(String),
|
||||
@@ -53,7 +56,16 @@ pub enum MpvError {
|
||||
impl PartialEq for MpvError {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Self::MpvError(l0), Self::MpvError(r0)) => l0 == r0,
|
||||
(
|
||||
Self::MpvError {
|
||||
command: l_command,
|
||||
message: l_message,
|
||||
},
|
||||
Self::MpvError {
|
||||
command: r_command,
|
||||
message: r_message,
|
||||
},
|
||||
) => l_command == r_command && l_message == r_message,
|
||||
(Self::MpvSocketConnectionError(l0), Self::MpvSocketConnectionError(r0)) => l0 == r0,
|
||||
(Self::InternalConnectionError(l0), Self::InternalConnectionError(r0)) => l0 == r0,
|
||||
(Self::JsonParseError(l0), Self::JsonParseError(r0)) => {
|
||||
|
||||
+6
-3
@@ -92,7 +92,7 @@ impl MpvIpc {
|
||||
|
||||
log::trace!("Received response: {:?}", response);
|
||||
|
||||
parse_mpv_response_data(response?)
|
||||
parse_mpv_response_data(response?, command)
|
||||
}
|
||||
|
||||
pub(crate) async fn get_mpv_property(
|
||||
@@ -197,7 +197,7 @@ impl MpvIpc {
|
||||
/// This function does the most basic JSON parsing and error handling
|
||||
/// for status codes and errors that all responses from mpv are
|
||||
/// expected to contain.
|
||||
fn parse_mpv_response_data(value: Value) -> Result<Option<Value>, MpvError> {
|
||||
fn parse_mpv_response_data(value: Value, command: &[Value]) -> Result<Option<Value>, MpvError> {
|
||||
log::trace!("Parsing mpv response data: {:?}", value);
|
||||
let result = value
|
||||
.as_object()
|
||||
@@ -225,7 +225,10 @@ fn parse_mpv_response_data(value: Value) -> Result<Option<Value>, MpvError> {
|
||||
.and_then(|(error, data)| match error {
|
||||
"success" => Ok(data),
|
||||
"property unavailable" => Ok(None),
|
||||
err => Err(MpvError::MpvError(err.to_string())),
|
||||
err => Err(MpvError::MpvError {
|
||||
command: command.to_owned(),
|
||||
message: err.to_string(),
|
||||
}),
|
||||
});
|
||||
|
||||
match &result {
|
||||
|
||||
Reference in New Issue
Block a user