1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// yt - A fully featured command line YouTube client
//
// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of Yt.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
use std::{ffi::NulError, os::raw as ctype, str::Utf8Error};
use thiserror::Error;
use super::mpv_error;
#[allow(missing_docs)]
pub type Result<T> = ::std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("loading file failed: {error}")]
Loadfile { error: String },
#[error("version mismatch detected! Linked version ({linked}) is unequal to the loaded version ({loaded})")]
VersionMismatch {
linked: ctype::c_ulong,
loaded: ctype::c_ulong,
},
#[error("invalid utf8 returned")]
InvalidUtf8,
#[error("null pointer returned")]
Null,
#[error("raw error returned: {}", to_string_mpv_error(*(.0)))]
Raw(crate::MpvError),
}
impl From<NulError> for Error {
fn from(_other: NulError) -> Error {
Error::Null
}
}
impl From<Utf8Error> for Error {
fn from(_other: Utf8Error) -> Error {
Error::InvalidUtf8
}
}
impl From<crate::MpvError> for Error {
fn from(other: crate::MpvError) -> Error {
Error::Raw(other)
}
}
pub(crate) fn to_string_mpv_error(num: crate::MpvError) -> String {
let (error, help) = to_string_mpv_error_raw(num);
if help.is_empty() {
error.to_owned()
} else {
format!("{} ({})", error, help)
}
}
fn to_string_mpv_error_raw(num: crate::MpvError) -> (&'static str, &'static str) {
// debug!("Turning error num '{}' to a string.", num);
match num {
mpv_error::EventQueueFull => (
"The event ringbuffer is full.",
"This means the client is choked, and can't receive any events. This can happen when too many asynchronous requests have been made, but not answered. Probably never happens in practice, unless the mpv core is frozen for some reason, and the client keeps making asynchronous requests. (Bugs in the client API implementation could also trigger this, e.g. if events become \"lost\".)",
),
mpv_error::NoMem => ("Memory allocation failed.", ""),
mpv_error::Uninitialized => ("The mpv core wasn't configured and initialized yet", " See the notes in mpv_create()."),
mpv_error::InvalidParameter => ("Generic catch-all error if a parameter is set to an invalid or unsupported value.", "This is used if there is no better error code."),
mpv_error::OptionNotFound => ("Trying to set an option that doesn't exist.", ""),
mpv_error::OptionFormat => ("Trying to set an option using an unsupported MPV_FORMAT.", ""),
mpv_error::OptionError => ("Setting the option failed", " Typically this happens if the provided option value could not be parsed."),
mpv_error::PropertyNotFound => ("The accessed property doesn't exist.", ""),
mpv_error::PropertyFormat => ("Trying to set or get a property using an unsupported MPV_FORMAT.", ""),
mpv_error::PropertyUnavailable => ("The property exists, but is not available", "This usually happens when the associated subsystem is not active, e.g. querying audio parameters while audio is disabled."),
mpv_error::PropertyError => ("Error setting or getting a property.", ""),
mpv_error::Command => ("General error when running a command with mpv_command and similar.", ""),
mpv_error::LoadingFailed => ("Generic error on loading (usually used with mpv_event_end_file.error).", ""),
mpv_error::AoInitFailed => ("Initializing the audio output failed.", ""),
mpv_error::VoInitFailed => ("Initializing the video output failed.", ""),
mpv_error::NothingToPlay => ("There was no audio or video data to play", "This also happens if the file was recognized, but did not contain any audio or video streams, or no streams were selected."),
mpv_error::UnknownFormat => (" * When trying to load the file, the file format could not be determined, or the file was too broken to open it.", ""),
mpv_error::Generic => ("Generic error for signaling that certain system requirements are not fulfilled.", ""),
mpv_error::NotImplemented => ("The API function which was called is a stub only", ""),
mpv_error::Unsupported => ("Unspecified error.", ""),
mpv_error::Success => unreachable!("This is not an error. It's just here, to ensure that the 0 case marks an success'"),
_ => unreachable!("Mpv seems to have changed it's constants."),
}
}
|