1
//! Library specific error messages.
2

            
3
use serde_json::{Map, Value};
4
use thiserror::Error;
5

            
6
use crate::MpvDataType;
7

            
8
/// Any error that can occur when interacting with mpv.
9
#[derive(Error, Debug)]
10
pub enum MpvError {
11
    #[error("MpvError: {0}")]
12
    MpvError(String),
13

            
14
    #[error("Error communicating over mpv socket: {0}")]
15
    MpvSocketConnectionError(String),
16

            
17
    #[error("Internal connection error: {0}")]
18
    InternalConnectionError(String),
19

            
20
    #[error("JsonParseError: {0}")]
21
    JsonParseError(#[from] serde_json::Error),
22

            
23
    #[error("Mpv sent a value with an unexpected type:\nExpected {expected_type}, received {received:#?}")]
24
    ValueContainsUnexpectedType {
25
        expected_type: String,
26
        received: Value,
27
    },
28

            
29
    #[error(
30
        "Mpv sent data with an unexpected type:\nExpected {expected_type}, received {received:#?}"
31
    )]
32
    DataContainsUnexpectedType {
33
        expected_type: String,
34
        received: MpvDataType,
35
    },
36

            
37
    #[error("Missing expected 'data' field in mpv message")]
38
    MissingMpvData,
39

            
40
    #[error("Missing key in object:\nExpected {key} in {map:#?}")]
41
    MissingKeyInObject {
42
        key: String,
43
        map: Map<String, Value>,
44
    },
45

            
46
    #[error("Unknown error: {0}")]
47
    Other(String),
48
}