Skip to content

Commit 274dc59

Browse files
handle error while adding fsnotify events
Check if the config directory exists or not. Signed-off-by: Pradeep Kumar K J <[email protected]>
1 parent b70bf9f commit 274dc59

File tree

6 files changed

+20
-4
lines changed

6 files changed

+20
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common/tedge_config/src/tedge_config_cli/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub enum TEdgeConfigError {
2626

2727
#[error(transparent)]
2828
Multi(#[from] Multi),
29+
30+
#[error(transparent)]
31+
DirNotFound(#[from] tedge_utils::paths::PathsError),
2932
}
3033

3134
impl TEdgeConfigError {

crates/extensions/c8y_config_manager/src/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use c8y_api::smartrest::topic::C8yTopic;
2+
use tedge_utils::paths::validate_parent_dir_exists;
23

34
use std::path::Path;
45
use std::path::PathBuf;
@@ -86,7 +87,7 @@ impl ConfigManagerConfig {
8687
let tedge_http_address = tedge_config.query(HttpBindAddressSetting)?;
8788
let tedge_http_port: u16 = tedge_config.query(HttpPortSetting)?.into();
8889

89-
Ok(ConfigManagerConfig::new(
90+
let config = ConfigManagerConfig::new(
9091
config_dir,
9192
tmp_dir,
9293
data_dir,
@@ -95,6 +96,8 @@ impl ConfigManagerConfig {
9596
mqtt_port,
9697
tedge_http_address,
9798
tedge_http_port,
98-
))
99+
);
100+
validate_parent_dir_exists(config.plugin_config_path.as_path())?;
101+
Ok(config)
99102
}
100103
}

crates/extensions/c8y_log_manager/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use tedge_config::TEdgeConfig;
1818
use tedge_config::TEdgeConfigError;
1919
use tedge_config::TmpPathSetting;
2020
use tedge_mqtt_ext::MqttMessage;
21+
use tedge_utils::paths::validate_parent_dir_exists;
2122

2223
pub const DEFAULT_PLUGIN_CONFIG_FILE_NAME: &str = "c8y-log-plugin.toml";
2324
pub const DEFAULT_OPERATION_DIR_NAME: &str = "c8y/";
@@ -54,6 +55,7 @@ impl LogManagerConfig {
5455
let plugin_config_path = config_dir
5556
.join(DEFAULT_OPERATION_DIR_NAME)
5657
.join(DEFAULT_PLUGIN_CONFIG_FILE_NAME);
58+
validate_parent_dir_exists(&plugin_config_path)?;
5759

5860
let plugin_config = LogPluginConfig::new(&plugin_config_path);
5961

crates/extensions/tedge_file_system_ext/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repository = { workspace = true }
1111

1212
[dependencies]
1313
async-trait = "0.1"
14+
log = "0.4"
1415
tedge_actors = { path = "../../core/tedge_actors" }
1516
tedge_utils = { path = "../../common/tedge_utils", features = ["fs-notify"] }
1617
tokio = { version = "1.23", features = ["macros"] }

crates/extensions/tedge_file_system_ext/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use async_trait::async_trait;
2+
use log::error;
23
use std::path::PathBuf;
34
use tedge_actors::futures::channel::mpsc;
45
use tedge_actors::futures::StreamExt;
@@ -121,9 +122,14 @@ impl Actor for FsWatchActor {
121122
}
122123

123124
async fn run(&mut self) -> Result<(), RuntimeError> {
124-
let mut fs_notify = NotifyStream::try_default().unwrap();
125+
let mut fs_notify = NotifyStream::try_default().map_err(Box::new)?;
125126
for (watch_path, _) in self.messages.get_watch_dirs().iter() {
126-
fs_notify.add_watcher(watch_path).unwrap();
127+
if let Err(err) = fs_notify.add_watcher(watch_path) {
128+
error!(
129+
"Failed to add file watcher to the {} due to: {err}",
130+
watch_path.display()
131+
);
132+
}
127133
}
128134

129135
loop {

0 commit comments

Comments
 (0)