From 4399a770312d0d4db42f1d93ab586ecb5e626175 Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 26 Mar 2024 14:36:16 +0800 Subject: [PATCH] add path for FileWatch snafu Signed-off-by: tison --- src/auth/src/error.rs | 3 ++- .../user_provider/watch_file_user_provider.rs | 10 +++++---- src/servers/src/error.rs | 3 ++- src/servers/src/tls.rs | 22 +++++++++---------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/auth/src/error.rs b/src/auth/src/error.rs index 88351694e7..bc484d25b7 100644 --- a/src/auth/src/error.rs +++ b/src/auth/src/error.rs @@ -64,8 +64,9 @@ pub enum Error { username: String, }, - #[snafu(display("Failed to initialize a watcher for file"))] + #[snafu(display("Failed to initialize a watcher for file {}", path))] FileWatch { + path: Option, #[snafu(source)] error: notify::Error, }, diff --git a/src/auth/src/user_provider/watch_file_user_provider.rs b/src/auth/src/user_provider/watch_file_user_provider.rs index 6a2aec1c26..6e67603597 100644 --- a/src/auth/src/user_provider/watch_file_user_provider.rs +++ b/src/auth/src/user_provider/watch_file_user_provider.rs @@ -43,13 +43,15 @@ impl WatchFileUserProvider { }; let (tx, rx) = channel::(); - - let mut debouncer = - new_debouncer(Duration::from_secs(1), None, tx).context(FileWatchSnafu)?; + let mut debouncer = new_debouncer(Duration::from_secs(1), None, tx) + .context(FileWatchSnafu { path: None })?; debouncer .watcher() .watch(Path::new(filepath), RecursiveMode::NonRecursive) - .context(FileWatchSnafu)?; + .context(FileWatchSnafu { + path: Some(filepath), + })?; + let filepath = filepath.to_string(); std::thread::spawn(move || { let _hold = debouncer; diff --git a/src/servers/src/error.rs b/src/servers/src/error.rs index 0546d2a262..18a9f68c9a 100644 --- a/src/servers/src/error.rs +++ b/src/servers/src/error.rs @@ -449,8 +449,9 @@ pub enum Error { ))] UnexpectedPhysicalTable { location: Location }, - #[snafu(display("Failed to initialize a watcher for file"))] + #[snafu(display("Failed to initialize a watcher for file {}", path))] FileWatch { + path: Option, #[snafu(source)] error: notify::Error, }, diff --git a/src/servers/src/tls.rs b/src/servers/src/tls.rs index f36970a42b..bd6a96e8c1 100644 --- a/src/servers/src/tls.rs +++ b/src/servers/src/tls.rs @@ -200,21 +200,21 @@ pub fn maybe_watch_tls_config(tls_server_config: Arc) let tls_server_config_for_watcher = tls_server_config.clone(); let (tx, rx) = channel::>(); - let mut watcher = notify::recommended_watcher(tx).context(FileWatchSnafu)?; + let mut watcher = notify::recommended_watcher(tx).context(FileWatchSnafu { path: None })?; + let cert_path = tls_server_config.get_tls_option().cert_path(); watcher - .watch( - tls_server_config.get_tls_option().cert_path(), - RecursiveMode::NonRecursive, - ) - .context(FileWatchSnafu)?; + .watch(cert_path, RecursiveMode::NonRecursive) + .context(FileWatchSnafu { + path: Some(cert_path), + })?; + let key_path = tls_server_config.get_tls_option().key_path(); watcher - .watch( - tls_server_config.get_tls_option().key_path(), - RecursiveMode::NonRecursive, - ) - .context(FileWatchSnafu)?; + .watch(key_path, RecursiveMode::NonRecursive) + .context(FileWatchSnafu { + path: Some(key_path), + })?; std::thread::spawn(move || { let _watcher = watcher;