Impl more informative error messages
Bump version to 0.2.20, and regenerate Cargo.lock .
This commit is contained in:
parent
3299764ee1
commit
810e589efe
5 changed files with 388 additions and 327 deletions
684
Cargo.lock
generated
684
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "mpd_info_screen"
|
||||
version = "0.2.19"
|
||||
version = "0.2.20"
|
||||
edition = "2018"
|
||||
description = "Displays info on currently playing music from an MPD daemon"
|
||||
license = "MIT"
|
||||
|
|
|
@ -13,7 +13,7 @@ counter, and the filename currently being played
|
|||
|
||||
# Usage
|
||||
|
||||
mpd_info_screen 0.2.19
|
||||
mpd_info_screen 0.2.20
|
||||
|
||||
USAGE:
|
||||
mpd_info_screen [FLAGS] [OPTIONS] <host> [port]
|
||||
|
|
|
@ -51,7 +51,7 @@ fn seconds_to_time(seconds: f64) -> String {
|
|||
|
||||
pub struct MPDDisplay {
|
||||
opts: Opt,
|
||||
mpd_handler: Option<MPDHandler>,
|
||||
mpd_handler: Result<MPDHandler, String>,
|
||||
is_valid: bool,
|
||||
is_initialized: bool,
|
||||
is_authenticated: bool,
|
||||
|
@ -84,7 +84,7 @@ impl MPDDisplay {
|
|||
pub fn new(_ctx: &mut Context, opts: Opt) -> Self {
|
||||
Self {
|
||||
opts,
|
||||
mpd_handler: None,
|
||||
mpd_handler: Err(String::from("Uninitialized")),
|
||||
is_valid: true,
|
||||
is_initialized: false,
|
||||
is_authenticated: false,
|
||||
|
@ -120,9 +120,8 @@ impl MPDDisplay {
|
|||
self.opts.port,
|
||||
self.opts.password.clone().map_or(String::new(), |s| s),
|
||||
self.opts.log_level,
|
||||
)
|
||||
.ok();
|
||||
if self.mpd_handler.is_some() {
|
||||
);
|
||||
if self.mpd_handler.is_ok() {
|
||||
self.is_initialized = true;
|
||||
loop {
|
||||
self.dirty_flag = self.mpd_handler.as_ref().unwrap().get_dirty_flag().ok();
|
||||
|
@ -232,7 +231,7 @@ impl MPDDisplay {
|
|||
read_guard_opt: &mut Option<
|
||||
RwLockReadGuard<'_, MPDHandlerState>,
|
||||
>,
|
||||
mpd_handler: &Option<MPDHandler>|
|
||||
mpd_handler: &Result<MPDHandler, String>|
|
||||
-> Result<(), String> {
|
||||
*tried_in_dir = true;
|
||||
album_art.take();
|
||||
|
@ -505,9 +504,16 @@ impl MPDDisplay {
|
|||
impl EventHandler for MPDDisplay {
|
||||
fn update(&mut self, ctx: &mut ggez::Context) -> Result<(), GameError> {
|
||||
if !self.is_valid {
|
||||
return Err(GameError::EventLoopError(
|
||||
"Failed to initialize MPDHandler".into(),
|
||||
));
|
||||
if let Err(mpd_handler_error) = &self.mpd_handler {
|
||||
return Err(GameError::EventLoopError(format!(
|
||||
"Failed to initialize MPDHandler: {}",
|
||||
mpd_handler_error
|
||||
)));
|
||||
} else {
|
||||
return Err(GameError::EventLoopError(
|
||||
"Failed to initialize MPDHandler".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if !self.is_initialized {
|
||||
|
|
|
@ -243,7 +243,7 @@ impl MPDHandler {
|
|||
&SocketAddr::new(IpAddr::V4(host), port),
|
||||
Duration::from_secs(5),
|
||||
)
|
||||
.map_err(|_| String::from("Failed to get TCP connection"))?;
|
||||
.map_err(|_| String::from("Failed to get TCP connection (is MPD running?)"))?;
|
||||
|
||||
let s = MPDHandler {
|
||||
state: Arc::new(RwLock::new(MPDHandlerState {
|
||||
|
@ -587,6 +587,7 @@ impl MPDHandler {
|
|||
write_handle.error_text = "Failed to get MPD status".into();
|
||||
if line.contains("don't have permission") {
|
||||
write_handle.can_authenticate = false;
|
||||
write_handle.error_text.push_str(" (not authenticated?)");
|
||||
}
|
||||
}
|
||||
PollState::ReadPicture => {
|
||||
|
|
Loading…
Reference in a new issue