Skip to content

Commit a93ec8f

Browse files
refacto: simplify vector initialization and Bulk Slice parsing
1 parent 83b9d01 commit a93ec8f

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

pre-compute/src/compute/pre_compute_app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl PreComputeAppTrait for PreComputeApp {
136136
/// - `pre_compute_args` is `None`.
137137
/// - `chain_task_id` is `None`.
138138
fn download_input_files(&self) -> Result<(), Vec<ReplicateStatusCause>> {
139-
let mut exit_causes: Vec<ReplicateStatusCause> = vec![];
139+
let mut exit_causes: Vec<ReplicateStatusCause> = Vec::new();
140140
let args = &self.pre_compute_args;
141141
let chain_task_id: &str = &self.chain_task_id;
142142

pre-compute/src/compute/pre_compute_args.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl PreComputeArgs {
6161
/// ```
6262
pub fn read_args() -> (PreComputeArgs, Vec<ReplicateStatusCause>) {
6363
info!("Starting to read pre-compute arguments from environment variables");
64-
let mut exit_causes: Vec<ReplicateStatusCause> = vec![];
64+
let mut exit_causes: Vec<ReplicateStatusCause> = Vec::new();
6565

6666
let is_dataset_required = match get_env_var_or_error(
6767
TeeSessionEnvironmentVariable::IsDatasetRequired,
@@ -86,19 +86,12 @@ impl PreComputeArgs {
8686
TeeSessionEnvironmentVariable::IexecBulkSliceSize,
8787
ReplicateStatusCause::PreComputeFailedUnknownIssue,
8888
) {
89-
Ok(s) => match s.parse::<usize>() {
90-
Ok(value) => value,
91-
Err(_) => {
92-
error!("Invalid numeric format for IEXEC_BULK_SLICE_SIZE: {s}");
93-
exit_causes.push(ReplicateStatusCause::PreComputeFailedUnknownIssue);
94-
0
95-
}
96-
},
97-
Err(e) => {
98-
error!("Failed to read IEXEC_BULK_SLICE_SIZE: {e:?}");
99-
exit_causes.push(e);
89+
Ok(s) => s.parse::<usize>().unwrap_or_else(|_| {
90+
error!("Invalid numeric format for IEXEC_BULK_SLICE_SIZE: {s}");
91+
exit_causes.push(ReplicateStatusCause::PreComputeFailedUnknownIssue);
10092
0
101-
}
93+
}),
94+
Err(_) => 0,
10295
}; // TODO: replace with a more specific error
10396

10497
let mut datasets = Vec::with_capacity(iexec_bulk_slice_size + 1);

0 commit comments

Comments
 (0)