Skip to content

Commit cb96c2d

Browse files
committed
Rename TEdgeConfig::new as try_new
as this might fail. Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
1 parent 6027b34 commit cb96c2d

File tree

16 files changed

+18
-18
lines changed

16 files changed

+18
-18
lines changed

crates/common/tedge_config/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ pub use tedge_config_macros::all_or_nothing;
1414
pub use tedge_config_macros::OptionalConfig;
1515

1616
impl TEdgeConfig {
17-
pub fn new(config_location: TEdgeConfigLocation) -> Result<Self, TEdgeConfigError> {
17+
pub fn try_new(config_location: TEdgeConfigLocation) -> Result<Self, TEdgeConfigError> {
1818
config_location.load()
1919
}
2020

2121
pub fn load(config_dir: &Path) -> Result<TEdgeConfig, TEdgeConfigError> {
2222
let config_location = TEdgeConfigLocation::from_custom_root(config_dir);
23-
TEdgeConfig::new(config_location)
23+
TEdgeConfig::try_new(config_location)
2424
}
2525

2626
#[cfg(feature = "test")]

crates/core/plugin_sm/src/plugin_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl ExternalPlugins {
147147
self.plugin_map.clear();
148148

149149
let config =
150-
tedge_config::TEdgeConfig::new(self.config_location.clone()).map_err(|err| {
150+
tedge_config::TEdgeConfig::try_new(self.config_location.clone()).map_err(|err| {
151151
io::Error::new(
152152
ErrorKind::Other,
153153
format!("Failed to load tedge config: {}", err),

crates/core/plugin_sm/tests/plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod tests {
5959
let tmpfile = make_config(100)?;
6060
let config_location =
6161
TEdgeConfigLocation::from_custom_root(tmpfile.path().to_str().unwrap());
62-
let config = tedge_config::TEdgeConfig::new(config_location)?;
62+
let config = tedge_config::TEdgeConfig::try_new(config_location)?;
6363

6464
let plugin = ExternalPluginCommand::new(
6565
"test",

crates/core/tedge/src/cli/certificate/upload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl UploadCertCmd {
5151
Err(_) => rpassword::read_password_from_tty(Some("Enter password: "))?,
5252
};
5353

54-
let config = TEdgeConfig::new(TEdgeConfigLocation::default())?;
54+
let config = TEdgeConfig::try_new(TEdgeConfigLocation::default())?;
5555
let root_cert = &config.c8y.root_cert_path;
5656
let client_builder = reqwest::blocking::Client::builder();
5757
let res = match std::fs::metadata(root_cert) {

crates/core/tedge/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,6 @@ impl BuildContext {
159159
}
160160

161161
pub fn load_config(&self) -> Result<tedge_config::TEdgeConfig, tedge_config::TEdgeConfigError> {
162-
tedge_config::TEdgeConfig::new(self.config_location.clone())
162+
tedge_config::TEdgeConfig::try_new(self.config_location.clone())
163163
}
164164
}

crates/core/tedge_agent/src/agent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl AgentConfig {
9090
tedge_config_location: &tedge_config::TEdgeConfigLocation,
9191
cliopts: AgentOpt,
9292
) -> Result<Self, anyhow::Error> {
93-
let tedge_config = tedge_config::TEdgeConfig::new(tedge_config_location.clone())?;
93+
let tedge_config = tedge_config::TEdgeConfig::try_new(tedge_config_location.clone())?;
9494

9595
let config_dir = tedge_config_location.tedge_config_root_path.clone();
9696
let tmp_dir = Arc::from(tedge_config.tmp.path.as_path());

crates/core/tedge_agent/src/restart_manager/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl RestartManagerConfig {
1414
device_topic_id: &EntityTopicId,
1515
tedge_config_location: &tedge_config::TEdgeConfigLocation,
1616
) -> Result<RestartManagerConfig, tedge_config::TEdgeConfigError> {
17-
let tedge_config = tedge_config::TEdgeConfig::new(tedge_config_location.clone())?;
17+
let tedge_config = tedge_config::TEdgeConfig::try_new(tedge_config_location.clone())?;
1818

1919
Ok(RestartManagerConfig {
2020
device_topic_id: device_topic_id.clone(),

crates/core/tedge_agent/src/software_manager/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl SoftwareManagerActor {
325325
fn get_default_plugin(
326326
config_location: &tedge_config::TEdgeConfigLocation,
327327
) -> Result<Option<SoftwareType>, TEdgeConfigError> {
328-
let tedge_config = tedge_config::TEdgeConfig::new(config_location.clone())?;
328+
let tedge_config = tedge_config::TEdgeConfig::try_new(config_location.clone())?;
329329

330330
Ok(tedge_config
331331
.software

crates/core/tedge_agent/src/software_manager/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl SoftwareManagerConfig {
1717
pub fn from_tedge_config(
1818
tedge_config_location: &TEdgeConfigLocation,
1919
) -> Result<SoftwareManagerConfig, tedge_config::TEdgeConfigError> {
20-
let tedge_config = tedge_config::TEdgeConfig::new(tedge_config_location.clone())?;
20+
let tedge_config = tedge_config::TEdgeConfig::try_new(tedge_config_location.clone())?;
2121
let config_dir = &tedge_config_location.tedge_config_root_path;
2222

2323
let default_plugin_type = tedge_config

crates/core/tedge_agent/src/tedge_operation_converter/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl OperationConfig {
1616
device_topic_id: &EntityTopicId,
1717
tedge_config_location: &tedge_config::TEdgeConfigLocation,
1818
) -> Result<OperationConfig, tedge_config::TEdgeConfigError> {
19-
let tedge_config = tedge_config::TEdgeConfig::new(tedge_config_location.clone())?;
19+
let tedge_config = tedge_config::TEdgeConfig::try_new(tedge_config_location.clone())?;
2020

2121
Ok(OperationConfig {
2222
mqtt_schema: MqttSchema::with_root(tedge_config.mqtt.topic_root.clone()),

0 commit comments

Comments
 (0)