From 00a3332d9a986f650283416dccf25aa9f2d32aa6 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Sat, 1 May 2021 17:01:17 +0200 Subject: Fix error messages if library could not be loaded. Previously rather useless memory addresses were written in user-visible error messages. Now it's the actual file path. --- swaystatus/src/plugin_database/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/swaystatus/src/plugin_database/mod.rs b/swaystatus/src/plugin_database/mod.rs index a4693ed..872f645 100644 --- a/swaystatus/src/plugin_database/mod.rs +++ b/swaystatus/src/plugin_database/mod.rs @@ -16,11 +16,11 @@ impl<'a> PluginDatabase<'a> { } pub fn new<'b : 'a>(libs : &'b Libraries) -> PluginDatabase<'a> { PluginDatabase { - plugins : libs.libs.iter().filter_map(|lib| { + plugins : libs.libs.iter().filter_map(|(path, lib)| { match get_plugin_from_library(lib) { Ok(x) => Some((String::from(x.get_name()), x)), Err(y) => { - let lib_name = format!("{:?}", lib); + let lib_name = path.to_string_lossy(); match y { PluginLoadingError::MissingVersionInformation => { eprintln!("{}", gettext!("Failed to load library {}, no version information found.", lib_name)); @@ -46,7 +46,7 @@ impl<'a> PluginDatabase<'a> { } pub struct Libraries { - libs : Vec + libs : Vec<(std::path::PathBuf,Library)> } impl Libraries { pub fn load_from_folder(path : &std::path::Path) -> Result { @@ -58,8 +58,9 @@ impl Libraries { None }, Ok(d) => unsafe { - match libloading::Library::new(d.path()) { - Ok(x) => Some(x), + let p = d.path(); + match libloading::Library::new(&p) { + Ok(x) => Some((p,x)), Err(_) => { eprintln!("{}", gettext!("Failed to load as library: {}", d.path().display())); None -- cgit v1.2.3