11use crate :: compute:: dataset:: Dataset ;
22use crate :: compute:: errors:: ReplicateStatusCause ;
33use crate :: compute:: utils:: env_utils:: { TeeSessionEnvironmentVariable , get_env_var_or_error} ;
4+ use log:: { error, info} ;
45
56/// Represents parameters required for pre-compute tasks in a Trusted Execution Environment (TEE).
67///
@@ -59,52 +60,89 @@ impl PreComputeArgs {
5960 /// let args = PreComputeArgs::read_args();
6061 /// ```
6162 pub fn read_args ( ) -> ( PreComputeArgs , Vec < ReplicateStatusCause > ) {
63+ info ! ( "Starting to read pre-compute arguments from environment variables" ) ;
6264 let mut exit_causes: Vec < ReplicateStatusCause > = vec ! [ ] ;
6365
6466 let output_dir = match get_env_var_or_error (
6567 TeeSessionEnvironmentVariable :: IexecPreComputeOut ,
6668 ReplicateStatusCause :: PreComputeOutputPathMissing ,
6769 ) {
68- Ok ( output_dir) => output_dir,
69- Err ( exit_cause) => return ( PreComputeArgs :: default ( ) , vec ! [ exit_cause] ) ,
70+ Ok ( output_dir) => {
71+ info ! ( "Successfully read output directory: {output_dir}" ) ;
72+ output_dir
73+ }
74+ Err ( e) => {
75+ error ! ( "Failed to read output directory: {e:?}" ) ;
76+ return ( PreComputeArgs :: default ( ) , vec ! [ e] ) ;
77+ }
7078 } ;
7179
72- let is_dataset_required = get_env_var_or_error (
80+ let is_dataset_required = match get_env_var_or_error (
7381 TeeSessionEnvironmentVariable :: IsDatasetRequired ,
7482 ReplicateStatusCause :: PreComputeIsDatasetRequiredMissing ,
75- )
76- . and_then ( |s| {
77- s. to_lowercase ( )
78- . parse :: < bool > ( )
79- . map_err ( |_| ReplicateStatusCause :: PreComputeIsDatasetRequiredMissing )
80- } )
81- . unwrap_or_else ( |e| {
82- exit_causes. push ( e) ;
83- false
84- } ) ;
83+ ) {
84+ Ok ( s) => match s. to_lowercase ( ) . parse :: < bool > ( ) {
85+ Ok ( value) => {
86+ info ! ( "Dataset required: {value}" ) ;
87+ value
88+ }
89+ Err ( _) => {
90+ error ! ( "Invalid boolean format for IS_DATASET_REQUIRED: {s}" ) ;
91+ exit_causes. push ( ReplicateStatusCause :: PreComputeIsDatasetRequiredMissing ) ;
92+ false
93+ }
94+ } ,
95+ Err ( e) => {
96+ error ! ( "Failed to read IS_DATASET_REQUIRED: {e:?}" ) ;
97+ exit_causes. push ( e) ;
98+ false
99+ }
100+ } ;
85101
86- let iexec_bulk_slice_size =
87- std:: env:: var ( TeeSessionEnvironmentVariable :: IexecBulkSliceSize . name ( ) )
88- . map ( |s| {
89- s. parse :: < usize > ( ) . unwrap_or_else ( |_| {
90- exit_causes. push ( ReplicateStatusCause :: PreComputeFailedUnknownIssue ) ;
91- 0
92- } )
93- } )
94- . unwrap_or ( 0 ) ; // TODO: replace with a more specific error
102+ let iexec_bulk_slice_size = match get_env_var_or_error (
103+ TeeSessionEnvironmentVariable :: IexecBulkSliceSize ,
104+ ReplicateStatusCause :: PreComputeFailedUnknownIssue ,
105+ ) {
106+ Ok ( s) => match s. parse :: < usize > ( ) {
107+ Ok ( value) => {
108+ info ! ( "Bulk slice size: {value}" ) ;
109+ value
110+ }
111+ Err ( _) => {
112+ error ! ( "Invalid numeric format for IEXEC_BULK_SLICE_SIZE: {s}" ) ;
113+ exit_causes. push ( ReplicateStatusCause :: PreComputeFailedUnknownIssue ) ;
114+ 0
115+ }
116+ } ,
117+ Err ( e) => {
118+ error ! ( "Failed to read IEXEC_BULK_SLICE_SIZE: {e:?}" ) ;
119+ exit_causes. push ( e) ;
120+ 0
121+ }
122+ } ; // TODO: replace with a more specific error
95123
96124 let mut datasets = Vec :: with_capacity ( iexec_bulk_slice_size + 1 ) ;
97125
98126 // Read datasets
99127 let start_index = if is_dataset_required { 0 } else { 1 } ;
128+ info ! (
129+ "Reading datasets from index {start_index} to {iexec_bulk_slice_size} (is_dataset_required: {is_dataset_required})"
130+ ) ;
131+
100132 for i in start_index..=iexec_bulk_slice_size {
133+ info ! ( "Processing dataset at index {i}" ) ;
134+
101135 let filename = match get_env_var_or_error (
102136 TeeSessionEnvironmentVariable :: IexecDatasetFilename ( i) ,
103137 ReplicateStatusCause :: PreComputeDatasetFilenameMissing ( format ! ( "dataset_{i}" ) ) ,
104138 ) {
105- Ok ( filename) => filename,
106- Err ( exit_cause) => {
107- exit_causes. push ( exit_cause) ;
139+ Ok ( filename) => {
140+ info ! ( "Dataset {i} filename: {filename}" ) ;
141+ filename
142+ }
143+ Err ( e) => {
144+ error ! ( "Failed to read dataset {i} filename: {e:?}" ) ;
145+ exit_causes. push ( e) ;
108146 continue ;
109147 }
110148 } ;
@@ -113,9 +151,13 @@ impl PreComputeArgs {
113151 TeeSessionEnvironmentVariable :: IexecDatasetUrl ( i) ,
114152 ReplicateStatusCause :: PreComputeDatasetUrlMissing ( filename. clone ( ) ) ,
115153 ) {
116- Ok ( url) => url,
117- Err ( exit_cause) => {
118- exit_causes. push ( exit_cause) ;
154+ Ok ( url) => {
155+ info ! ( "Dataset {i} URL: {url}" ) ;
156+ url
157+ }
158+ Err ( e) => {
159+ error ! ( "Failed to read dataset {i} URL: {e:?}" ) ;
160+ exit_causes. push ( e) ;
119161 continue ;
120162 }
121163 } ;
@@ -124,9 +166,13 @@ impl PreComputeArgs {
124166 TeeSessionEnvironmentVariable :: IexecDatasetChecksum ( i) ,
125167 ReplicateStatusCause :: PreComputeDatasetChecksumMissing ( filename. clone ( ) ) ,
126168 ) {
127- Ok ( checksum) => checksum,
128- Err ( exit_cause) => {
129- exit_causes. push ( exit_cause) ;
169+ Ok ( checksum) => {
170+ info ! ( "Dataset {i} checksum: {checksum}" ) ;
171+ checksum
172+ }
173+ Err ( e) => {
174+ error ! ( "Failed to read dataset {i} checksum: {e:?}" ) ;
175+ exit_causes. push ( e) ;
130176 continue ;
131177 }
132178 } ;
@@ -135,39 +181,75 @@ impl PreComputeArgs {
135181 TeeSessionEnvironmentVariable :: IexecDatasetKey ( i) ,
136182 ReplicateStatusCause :: PreComputeDatasetKeyMissing ( filename. clone ( ) ) ,
137183 ) {
138- Ok ( key) => key,
139- Err ( exit_cause) => {
140- exit_causes. push ( exit_cause) ;
184+ Ok ( key) => {
185+ info ! ( "Dataset {i} key successfully read" ) ;
186+ key
187+ }
188+ Err ( e) => {
189+ error ! ( "Failed to read dataset {i} key: {e:?}" ) ;
190+ exit_causes. push ( e) ;
141191 continue ;
142192 }
143193 } ;
144194
195+ info ! ( "Successfully loaded dataset {i} ({filename})" ) ;
145196 datasets. push ( Dataset :: new ( url, checksum, filename, key) ) ;
146197 }
198+
199+ info ! ( "Successfully loaded {} datasets" , datasets. len( ) ) ;
147200
148- let input_files_nb = get_env_var_or_error (
201+ let input_files_nb = match get_env_var_or_error (
149202 TeeSessionEnvironmentVariable :: IexecInputFilesNumber ,
150203 ReplicateStatusCause :: PreComputeInputFilesNumberMissing ,
151- )
152- . and_then ( |s| {
153- s. parse :: < usize > ( )
154- . map_err ( |_| ReplicateStatusCause :: PreComputeInputFilesNumberMissing )
155- } )
156- . unwrap_or_else ( |e| {
157- exit_causes. push ( e) ;
158- 0
159- } ) ;
204+ ) {
205+ Ok ( s) => match s. parse :: < usize > ( ) {
206+ Ok ( value) => {
207+ info ! ( "Number of input files: {value}" ) ;
208+ value
209+ }
210+ Err ( _) => {
211+ error ! ( "Invalid numeric format for IEXEC_INPUT_FILES_NUMBER: {s}" ) ;
212+ exit_causes. push ( ReplicateStatusCause :: PreComputeInputFilesNumberMissing ) ;
213+ 0
214+ }
215+ } ,
216+ Err ( e) => {
217+ error ! ( "Failed to read IEXEC_INPUT_FILES_NUMBER: {e:?}" ) ;
218+ exit_causes. push ( e) ;
219+ 0
220+ }
221+ } ;
160222
223+ info ! ( "Reading {input_files_nb} input file URLs" ) ;
161224 let input_files: Vec < String > = ( 1 ..=input_files_nb)
162225 . filter_map ( |i| {
163226 get_env_var_or_error (
164227 TeeSessionEnvironmentVariable :: IexecInputFileUrlPrefix ( i) ,
165228 ReplicateStatusCause :: PreComputeAtLeastOneInputFileUrlMissing ( i) ,
166229 )
167- . map_err ( |e| exit_causes. push ( e) )
230+ . map_err ( |e| {
231+ error ! ( "Failed to read input file {i} URL: {e:?}" ) ;
232+ exit_causes. push ( e)
233+ } )
168234 . ok ( )
235+ . map ( |url| {
236+ info ! ( "Input file {i} URL: {url}" ) ;
237+ url
238+ } )
169239 } )
170240 . collect ( ) ;
241+
242+ info ! ( "Successfully loaded {} input files" , input_files. len( ) ) ;
243+
244+ if !exit_causes. is_empty ( ) {
245+ error ! (
246+ "Encountered {} error(s) while reading pre-compute arguments" ,
247+ exit_causes. len( )
248+ ) ;
249+ } else {
250+ info ! ( "Successfully read all pre-compute arguments without errors" ) ;
251+ }
252+
171253 (
172254 PreComputeArgs {
173255 output_dir,
0 commit comments