Skip to content

Commit 19db159

Browse files
committed
fix: refine codes
1 parent 270f7d5 commit 19db159

File tree

21 files changed

+124
-121
lines changed

21 files changed

+124
-121
lines changed

core/src/ten_rust/src/build.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ fn auto_gen_schema_bindings_from_c() {
2222
schema_header
2323
.push("include_internal/ten_utils/schema/bindings/rust/schema_proxy.h");
2424
if !schema_header.exists() {
25-
println!(
26-
"Path of schema_proxy.h: {}",
27-
schema_header.to_str().unwrap()
25+
println!("Path of schema_proxy.h: {}", schema_header.to_str().unwrap());
26+
panic!(
27+
"The //include_internal/ten_utils/schema/bindings/rust/\
28+
schema_proxy.h does not exist."
2829
);
29-
panic!("The //include_internal/ten_utils/schema/bindings/rust/schema_proxy.h does not exist.");
3030
}
3131

3232
println!("cargo:rerun-if-changed={}", schema_header.to_str().unwrap());
@@ -121,7 +121,8 @@ fn auto_gen_schema_bindings_from_c() {
121121
}
122122
Err(e) => {
123123
panic!(
124-
"Unable to move temporary bindings to final destination after {} attempts: {}",
124+
"Unable to move temporary bindings to final destination \
125+
after {} attempts: {}",
125126
max_retries, e
126127
);
127128
}

core/src/ten_rust/src/constants/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ pub const TELEMETRY_SERVER_START_RETRY_MAX_ATTEMPTS: u32 = 3;
1111
pub const TELEMETRY_SERVER_START_RETRY_INTERVAL: u64 = 1; // seconds
1212

1313
pub const ERR_MSG_GRAPH_LOCALHOST_FORBIDDEN_IN_SINGLE_APP_MODE: &str =
14-
"'localhost' is not allowed in graph definition, and the graph seems to be a single-app graph, just remove the 'app' field";
14+
"'localhost' is not allowed in graph definition, and the graph seems to \
15+
be a single-app graph, just remove the 'app' field";
1516

1617
pub const ERR_MSG_GRAPH_LOCALHOST_FORBIDDEN_IN_MULTI_APP_MODE: &str =
17-
"'localhost' is not allowed in graph definition, change the content of 'app' field to be consistent with 'ten::uri'";
18+
"'localhost' is not allowed in graph definition, change the content of \
19+
'app' field to be consistent with 'ten::uri'";
1820

19-
pub const ERR_MSG_GRAPH_MIXED_APP_DECLARATIONS: &str = "Either all nodes should have 'app' declared, or none should, but not a mix of both.";
21+
pub const ERR_MSG_GRAPH_MIXED_APP_DECLARATIONS: &str =
22+
"Either all nodes should have 'app' declared, or none should, but not a \
23+
mix of both.";
2024

21-
pub const ERR_MSG_GRAPH_APP_FIELD_EMPTY: &str = "the 'app' field can not be empty, remove the field if the graph is a single-app graph";
25+
pub const ERR_MSG_GRAPH_APP_FIELD_EMPTY: &str =
26+
"the 'app' field can not be empty, remove the field if the graph is a \
27+
single-app graph";
2228

2329
pub const ERR_MSG_GRAPH_APP_FIELD_SHOULD_NOT_BE_DECLARED: &str =
2430
"the 'app' field should not be declared, as not any node has declared it";

core/src/ten_rust/src/crypto/algorithm/aes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ pub struct AesCtrCipher {
2929
pub fn new_aes_ctr_cipher(params: &str) -> Result<AesCtrCipher> {
3030
let config: AesCtrConfig = serde_json::from_str(params)?;
3131
let cipher = Aes128Ctr128BE::new(&config.key.into(), &config.nonce.into());
32-
Ok(AesCtrCipher {
33-
cipher: Mutex::new(cipher),
34-
})
32+
Ok(AesCtrCipher { cipher: Mutex::new(cipher) })
3533
}
3634

3735
impl<'de> Deserialize<'de> for AesCtrConfig {

core/src/ten_rust/src/endpoint/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ pub extern "C" fn ten_endpoint_system_create(
103103
}
104104

105105
eprintln!(
106-
"Failed to bind to address: {}. Attempt {} of {}. Retrying in {} second...",
107-
endpoint_str, attempts, max_attempts, TELEMETRY_SERVER_START_RETRY_INTERVAL
108-
);
106+
"Failed to bind to address: {}. Attempt {} of {}. \
107+
Retrying in {} second...",
108+
endpoint_str,
109+
attempts,
110+
max_attempts,
111+
TELEMETRY_SERVER_START_RETRY_INTERVAL
112+
);
109113
std::thread::sleep(wait_duration);
110114
}
111115
}

core/src/ten_rust/src/env.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ pub fn get_env() -> Result<EnvInfo> {
2222
let current_arch = Arch::from_str(std::env::consts::ARCH)?;
2323

2424
// Create response object
25-
let env_info = EnvInfo {
26-
os: current_os,
27-
arch: current_arch,
28-
};
25+
let env_info = EnvInfo { os: current_os, arch: current_arch };
2926

3027
Ok(env_info)
3128
}

core/src/ten_rust/src/graph/check/connection_extensions_exist.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ impl Graph {
2828

2929
if !all_extensions.contains(&dest_extension) {
3030
return Err(anyhow::anyhow!(
31-
"The extension declared in connections[{}].{}[{}] is not defined in nodes, extension: {}.",
31+
"The extension declared in connections[{}].{}[{}] is \
32+
not defined in nodes, extension: {}.",
3233
conn_idx,
3334
msg_type,
3435
flow_idx,
@@ -83,7 +84,8 @@ impl Graph {
8384
);
8485
if !all_extensions.contains(&src_extension) {
8586
return Err(anyhow::anyhow!(
86-
"The extension declared in connections[{}] is not defined in nodes, extension: {}.",
87+
"The extension declared in connections[{}] is not defined \
88+
in nodes, extension: {}.",
8789
conn_idx,
8890
connection.extension
8991
));

core/src/ten_rust/src/graph/check/connections_compatibility.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl Graph {
5454
None if ignore_missing_apps => continue,
5555
None => {
5656
return Err(anyhow::anyhow!(
57-
"Extension addon [{}] is not found in the pkgs map, should not happen.",
57+
"Extension addon [{}] is not found in the pkgs map, \
58+
should not happen.",
5859
dest_addon
5960
))
6061
}
@@ -102,19 +103,20 @@ impl Graph {
102103
.get_addon_name_of_extension(src_app_uri, &connection.extension)?;
103104

104105
let extension_pkg_info = match get_pkg_info_for_extension_addon(
105-
pkgs_cache,
106-
graph_app_base_dir,
107-
&src_app_uri.as_ref().map(|s| s.to_string()),
108-
src_addon,
106+
pkgs_cache,
107+
graph_app_base_dir,
108+
&src_app_uri.as_ref().map(|s| s.to_string()),
109+
src_addon,
109110
) {
110-
Some(pkg_info) => pkg_info,
111-
None if ignore_missing_apps => return Ok(()),
112-
None => {
113-
return Err(anyhow::anyhow!(
114-
"Extension addon [{}] is not found in the pkgs map, should not happen.",
115-
src_addon
116-
))
117-
}
111+
Some(pkg_info) => pkg_info,
112+
None if ignore_missing_apps => return Ok(()),
113+
None => {
114+
return Err(anyhow::anyhow!(
115+
"Extension addon [{}] is not found in the pkgs map, \
116+
should not happen.",
117+
src_addon
118+
))
119+
}
118120
};
119121

120122
// Check command flows.

core/src/ten_rust/src/graph/check/extension_uniqueness.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ impl Graph {
3737
// Check if this extension already exists in our tracking list
3838
if all_extensions.contains(&unique_ext_name) {
3939
return Err(anyhow::anyhow!(
40-
"Duplicated extension was found in nodes[{}], addon: {}, name: {}.",
41-
node_idx, node.addon, node.type_and_name.name
42-
));
40+
"Duplicated extension was found in nodes[{}], addon: \
41+
{}, name: {}.",
42+
node_idx,
43+
node.addon,
44+
node.type_and_name.name
45+
));
4346
}
4447

4548
// Add this extension to our tracking list

core/src/ten_rust/src/graph/check/extension_uniqueness_in_connections.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ impl Graph {
6363
// Check if we've seen this extension before.
6464
if let Some(idx) = extensions.get(&extension) {
6565
errors.push(format!(
66-
"extension '{}' is defined in connection[{}] and connection[{}], merge them into one section.",
66+
"extension '{}' is defined in connection[{}] and \
67+
connection[{}], merge them into one section.",
6768
connection.extension, idx, conn_idx
6869
));
6970
} else {

core/src/ten_rust/src/graph/check/nodes_installation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ impl Graph {
9090
// Return error if there are any non-exempted missing packages.
9191
if !not_installed_pkgs.is_empty() {
9292
return Err(anyhow::anyhow!(
93-
"The following packages are declared in nodes but not installed: {:?}.",
93+
"The following packages are declared in nodes but not \
94+
installed: {:?}.",
9495
not_installed_pkgs
9596
));
9697
}

0 commit comments

Comments
 (0)