Compare commits

..

3 commits

Author SHA1 Message Date
f63dbd95a7 Merge pull request 'Filter file dialog error log' (#145) from issue/133 into master
Reviewed-on: #145
2023-11-24 11:51:23 +01:00
6ab514c428
dtmm: Filter file dialog error log
All checks were successful
lint/clippy Checking for common mistakes and opportunities for code improvement
build/msvc Build for the target platform: msvc
build/linux Build for the target platform: linux
Druid's implementation makes it so that cancelling the file dialog
logs an error tracing event.

Closes #133.
2023-11-24 11:07:40 +01:00
6f0fdc5086
dtmm: Document error dialog 2023-11-24 10:13:59 +01:00
2 changed files with 24 additions and 2 deletions

View file

@ -7,11 +7,14 @@ use crate::ui::widget::button::Button;
const WINDOW_SIZE: (f64, f64) = (600., 250.); const WINDOW_SIZE: (f64, f64) = (600., 250.);
/// Show an error dialog.
/// The title and message are extracted from the error chain in the given `Report`.
pub fn error<T: Data>(err: Report, _parent: WindowHandle) -> WindowDesc<T> { pub fn error<T: Data>(err: Report, _parent: WindowHandle) -> WindowDesc<T> {
let (title, msg) = { let (title, msg) = {
let count = err.chain().count(); let count = err.chain().count();
if count == 1 { if count == 1 {
// If there is only one error, that's all we can show.
( (
String::from("An error occurred!"), String::from("An error occurred!"),
err.root_cause().to_string(), err.root_cause().to_string(),
@ -20,13 +23,20 @@ pub fn error<T: Data>(err: Report, _parent: WindowHandle) -> WindowDesc<T> {
let first = err.chain().next().unwrap(); let first = err.chain().next().unwrap();
let root = err.root_cause(); let root = err.root_cause();
// If there is more than one error in the chain we want to show
// - The first one: This will describe the overall operation that failed
// - The root cause: The actual thing that failed (e.g. 'No such file or directory')
// - The one before the root cause: With diligent `wrap_err` usage, this will provide
// context to the root cause (e.g. the file name we failed to access)
//
// If there are only two errors, the first one is also the context to the root cause.
if count > 2 { if count > 2 {
// The second to last one, the context to the root cause // The second to last one, the context to the root cause
let context = err.chain().nth(count - 2).unwrap(); let context = err.chain().nth(count - 2).unwrap();
(format!("{first}!"), format!("{}: {}", context, root)) (format!("{first}!"), format!("{}: {}", context, root))
} else { } else {
(format!("{first}!"), root.to_string()) ("An error occurred!".to_string(), format!("{}: {}", first, root))
} }
} }
}; };

View file

@ -56,7 +56,7 @@ impl std::io::Write for ChannelWriter {
} }
pub fn create_tracing_subscriber(tx: UnboundedSender<Vec<u8>>, level: Option<LogLevel>) { pub fn create_tracing_subscriber(tx: UnboundedSender<Vec<u8>>, level: Option<LogLevel>) {
let env_layer = if let Some(level) = level { let mut env_layer = if let Some(level) = level {
EnvFilter::from(level) EnvFilter::from(level)
} else if cfg!(debug_assertions) { } else if cfg!(debug_assertions) {
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")) EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"))
@ -64,6 +64,18 @@ pub fn create_tracing_subscriber(tx: UnboundedSender<Vec<u8>>, level: Option<Log
EnvFilter::new("error,dtmm=info") EnvFilter::new("error,dtmm=info")
}; };
// The internal implementation of Druid's GTK file dialog turns
// cancelling the dialog into an error. The, also internal, wrapper
// then logs and swallows the error.
// Therefore, as a consumer of the library, we don't have any way
// to customize this behavior, and instead have to filter out the
// tracing event.
env_layer = env_layer.add_directive(
"druid_shell::backend::gtk::window=off"
.parse()
.expect("Invalid env filter directive"),
);
let stdout_layer = fmt::layer().pretty(); let stdout_layer = fmt::layer().pretty();
let channel_layer = fmt::layer() let channel_layer = fmt::layer()