Impl more informative error messages

Bump version to 0.2.20, and regenerate Cargo.lock .
This commit is contained in:
Stephen Seo 2022-05-16 13:57:24 +09:00
parent 3299764ee1
commit 810e589efe
5 changed files with 388 additions and 327 deletions

684
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
[package] [package]
name = "mpd_info_screen" name = "mpd_info_screen"
version = "0.2.19" version = "0.2.20"
edition = "2018" edition = "2018"
description = "Displays info on currently playing music from an MPD daemon" description = "Displays info on currently playing music from an MPD daemon"
license = "MIT" license = "MIT"

View file

@ -13,7 +13,7 @@ counter, and the filename currently being played
# Usage # Usage
mpd_info_screen 0.2.19 mpd_info_screen 0.2.20
USAGE: USAGE:
mpd_info_screen [FLAGS] [OPTIONS] <host> [port] mpd_info_screen [FLAGS] [OPTIONS] <host> [port]

View file

@ -51,7 +51,7 @@ fn seconds_to_time(seconds: f64) -> String {
pub struct MPDDisplay { pub struct MPDDisplay {
opts: Opt, opts: Opt,
mpd_handler: Option<MPDHandler>, mpd_handler: Result<MPDHandler, String>,
is_valid: bool, is_valid: bool,
is_initialized: bool, is_initialized: bool,
is_authenticated: bool, is_authenticated: bool,
@ -84,7 +84,7 @@ impl MPDDisplay {
pub fn new(_ctx: &mut Context, opts: Opt) -> Self { pub fn new(_ctx: &mut Context, opts: Opt) -> Self {
Self { Self {
opts, opts,
mpd_handler: None, mpd_handler: Err(String::from("Uninitialized")),
is_valid: true, is_valid: true,
is_initialized: false, is_initialized: false,
is_authenticated: false, is_authenticated: false,
@ -120,9 +120,8 @@ impl MPDDisplay {
self.opts.port, self.opts.port,
self.opts.password.clone().map_or(String::new(), |s| s), self.opts.password.clone().map_or(String::new(), |s| s),
self.opts.log_level, self.opts.log_level,
) );
.ok(); if self.mpd_handler.is_ok() {
if self.mpd_handler.is_some() {
self.is_initialized = true; self.is_initialized = true;
loop { loop {
self.dirty_flag = self.mpd_handler.as_ref().unwrap().get_dirty_flag().ok(); self.dirty_flag = self.mpd_handler.as_ref().unwrap().get_dirty_flag().ok();
@ -232,7 +231,7 @@ impl MPDDisplay {
read_guard_opt: &mut Option< read_guard_opt: &mut Option<
RwLockReadGuard<'_, MPDHandlerState>, RwLockReadGuard<'_, MPDHandlerState>,
>, >,
mpd_handler: &Option<MPDHandler>| mpd_handler: &Result<MPDHandler, String>|
-> Result<(), String> { -> Result<(), String> {
*tried_in_dir = true; *tried_in_dir = true;
album_art.take(); album_art.take();
@ -505,9 +504,16 @@ impl MPDDisplay {
impl EventHandler for MPDDisplay { impl EventHandler for MPDDisplay {
fn update(&mut self, ctx: &mut ggez::Context) -> Result<(), GameError> { fn update(&mut self, ctx: &mut ggez::Context) -> Result<(), GameError> {
if !self.is_valid { if !self.is_valid {
return Err(GameError::EventLoopError( if let Err(mpd_handler_error) = &self.mpd_handler {
"Failed to initialize MPDHandler".into(), 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 { if !self.is_initialized {

View file

@ -243,7 +243,7 @@ impl MPDHandler {
&SocketAddr::new(IpAddr::V4(host), port), &SocketAddr::new(IpAddr::V4(host), port),
Duration::from_secs(5), 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 { let s = MPDHandler {
state: Arc::new(RwLock::new(MPDHandlerState { state: Arc::new(RwLock::new(MPDHandlerState {
@ -587,6 +587,7 @@ impl MPDHandler {
write_handle.error_text = "Failed to get MPD status".into(); write_handle.error_text = "Failed to get MPD status".into();
if line.contains("don't have permission") { if line.contains("don't have permission") {
write_handle.can_authenticate = false; write_handle.can_authenticate = false;
write_handle.error_text.push_str(" (not authenticated?)");
} }
} }
PollState::ReadPicture => { PollState::ReadPicture => {