@@ -73,43 +73,43 @@ pub struct Sandbox {
73
73
#[ derive( Debug , Snafu ) ]
74
74
pub enum Error {
75
75
#[ snafu( display( "Unable to create temporary directory: {}" , source) ) ]
76
- UnableToCreateTempDir { source : io:: Error } ,
76
+ UnableToCreateTempDirSnafu { source : io:: Error } ,
77
77
78
78
#[ snafu( display( "Unable to create output directory: {}" , source) ) ]
79
- UnableToCreateOutputDir { source : io:: Error } ,
79
+ UnableToCreateOutputDirSnafu { source : io:: Error } ,
80
80
81
81
#[ snafu( display( "Unable to set permissions for output directory: {}" , source) ) ]
82
- UnableToSetOutputPermissions { source : io:: Error } ,
82
+ UnableToSetOutputPermissionsSnafu { source : io:: Error } ,
83
83
84
84
#[ snafu( display( "Unable to create source file: {}" , source) ) ]
85
- UnableToCreateSourceFile { source : io:: Error } ,
85
+ UnableToCreateSourceFileSnafu { source : io:: Error } ,
86
86
87
87
#[ snafu( display( "Unable to set permissions for source file: {}" , source) ) ]
88
- UnableToSetSourcePermissions { source : io:: Error } ,
88
+ UnableToSetSourcePermissionsSnafu { source : io:: Error } ,
89
89
90
90
#[ snafu( display( "Output was not valid UTF-8: {}" , source) ) ]
91
91
OutputNotUtf8 { source : string:: FromUtf8Error } ,
92
92
93
93
#[ snafu( display( "Unable to read output file: {}" , source) ) ]
94
- UnableToReadOutput { source : io:: Error } ,
94
+ UnableToReadOutputSnafu { source : io:: Error } ,
95
95
96
96
#[ snafu( display( "Unable to start the compiler: {}" , source) ) ]
97
- UnableToStartCompiler { source : io:: Error } ,
97
+ UnableToStartCompilerSnafu { source : io:: Error } ,
98
98
99
99
#[ snafu( display( "Unable to find the compiler ID" ) ) ]
100
- MissingCompilerId ,
100
+ MissingCompilerIdSnafu ,
101
101
102
102
#[ snafu( display( "Unable to wait for the compiler: {}" , source) ) ]
103
- UnableToWaitForCompiler { source : io:: Error } ,
103
+ UnableToWaitForCompilerSnafu { source : io:: Error } ,
104
104
105
105
#[ snafu( display( "Unable to get output from the compiler: {}" , source) ) ]
106
- UnableToGetOutputFromCompiler { source : io:: Error } ,
106
+ UnableToGetOutputFromCompilerSnafu { source : io:: Error } ,
107
107
108
108
#[ snafu( display( "Unable to remove the compiler: {}" , source) ) ]
109
- UnableToRemoveCompiler { source : io:: Error } ,
109
+ UnableToRemoveCompilerSnafu { source : io:: Error } ,
110
110
111
111
#[ snafu( display( "Compiler execution took longer than {} ms" , timeout. as_millis( ) ) ) ]
112
- CompilerExecutionTimedOut {
112
+ CompilerExecutionTimedOutSnafu {
113
113
source : tokio:: time:: error:: Elapsed ,
114
114
timeout : Duration ,
115
115
} ,
@@ -172,13 +172,13 @@ const DOCKER_PROCESS_TIMEOUT_HARD: Duration = Duration::from_secs(60);
172
172
173
173
impl Sandbox {
174
174
pub fn new ( ) -> Result < Self > {
175
- let scratch = TempDir :: new ( "playground" ) . context ( UnableToCreateTempDir ) ?;
175
+ let scratch = TempDir :: new ( "playground" ) . context ( UnableToCreateTempDirSnafuSnafu ) ?;
176
176
let input_file = scratch. path ( ) . join ( "input.rs" ) ;
177
177
let output_dir = scratch. path ( ) . join ( "output" ) ;
178
- fs:: create_dir ( & output_dir) . context ( UnableToCreateOutputDir ) ?;
178
+ fs:: create_dir ( & output_dir) . context ( UnableToCreateOutputDirSnafuSnafu ) ?;
179
179
180
180
fs:: set_permissions ( & output_dir, wide_open_permissions ( ) )
181
- . context ( UnableToSetOutputPermissions ) ?;
181
+ . context ( UnableToSetOutputPermissionsSnafuSnafu ) ?;
182
182
183
183
Ok ( Sandbox {
184
184
scratch,
@@ -196,7 +196,7 @@ impl Sandbox {
196
196
197
197
let output = run_command_with_timeout ( command) ?;
198
198
let file = fs:: read_dir ( & self . output_dir )
199
- . context ( UnableToReadOutput ) ?
199
+ . context ( UnableToReadOutputSnafuSnafu ) ?
200
200
. flatten ( )
201
201
. map ( |entry| entry. path ( ) )
202
202
. find ( |path| path. extension ( ) == Some ( OsStr :: new ( "contract" ) ) ) ;
@@ -262,9 +262,9 @@ impl Sandbox {
262
262
}
263
263
264
264
fn write_source_code ( & self , code : & str ) -> Result < ( ) > {
265
- fs:: write ( & self . input_file , code) . context ( UnableToCreateSourceFile ) ?;
265
+ fs:: write ( & self . input_file , code) . context ( UnableToCreateSourceFileSnafuSnafu ) ?;
266
266
fs:: set_permissions ( & self . input_file , wide_open_permissions ( ) )
267
- . context ( UnableToSetSourcePermissions ) ?;
267
+ . context ( UnableToSetSourcePermissionsSnafuSnafu ) ?;
268
268
269
269
println ! (
270
270
"Wrote {} bytes of source to {}" ,
@@ -283,7 +283,7 @@ fn read(path: &Path) -> Result<Option<Vec<u8>>> {
283
283
let f = match File :: open ( path) {
284
284
Ok ( f) => f,
285
285
Err ( ref e) if e. kind ( ) == ErrorKind :: NotFound => return Ok ( None ) ,
286
- e => e. context ( UnableToReadOutput ) ?,
286
+ e => e. context ( UnableToReadOutputSnafuSnafu ) ?,
287
287
} ;
288
288
let mut f = BufReader :: new ( f) ;
289
289
let metadata = fs:: metadata ( path) . expect ( "unable to read metadata" ) ;
@@ -299,7 +299,7 @@ async fn run_command_with_timeout(mut command: Command) -> Result<std::process::
299
299
300
300
let timeout = DOCKER_PROCESS_TIMEOUT_HARD ;
301
301
println ! ( "executing command!" ) ;
302
- let output = command. output ( ) . await . context ( UnableToStartCompiler ) ?;
302
+ let output = command. output ( ) . await . context ( UnableToStartCompilerSnafuSnafu ) ?;
303
303
println ! ( "Done! {:?}" , output) ;
304
304
// Exit early, in case we don't have the container
305
305
// if !output.status.success() {
@@ -308,7 +308,7 @@ async fn run_command_with_timeout(mut command: Command) -> Result<std::process::
308
308
// let response = &output.stdout;
309
309
let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
310
310
311
- let id = stdout. lines ( ) . next ( ) . context ( MissingCompilerId ) ?. trim ( ) ;
311
+ let id = stdout. lines ( ) . next ( ) . context ( MissingCompilerIdSnafuSnafu ) ?. trim ( ) ;
312
312
let stderr = & output. stderr ;
313
313
314
314
// ----------
@@ -328,7 +328,7 @@ async fn run_command_with_timeout(mut command: Command) -> Result<std::process::
328
328
. unwrap_or ( i32:: MAX ) ;
329
329
Ok ( ExitStatusExt :: from_raw ( code) )
330
330
}
331
- Ok ( e) => return e. context ( UnableToWaitForCompiler ) , // Failed to run
331
+ Ok ( e) => return e. context ( UnableToWaitForCompilerSnafuSnafu ) , // Failed to run
332
332
Err ( e) => Err ( e) , // Timed out
333
333
} ;
334
334
@@ -338,7 +338,7 @@ async fn run_command_with_timeout(mut command: Command) -> Result<std::process::
338
338
let mut output = command
339
339
. output ( )
340
340
. await
341
- . context ( UnableToGetOutputFromCompiler ) ?;
341
+ . context ( UnableToGetOutputFromCompilerSnafuSnafu ) ?;
342
342
343
343
// ----------
344
344
@@ -347,9 +347,9 @@ async fn run_command_with_timeout(mut command: Command) -> Result<std::process::
347
347
"--force" , id
348
348
) ;
349
349
command. stdout ( std:: process:: Stdio :: null ( ) ) ;
350
- command. status ( ) . await . context ( UnableToRemoveCompiler ) ?;
350
+ command. status ( ) . await . context ( UnableToRemoveCompilerSnafuSnafu ) ?;
351
351
352
- let code = timed_out. context ( CompilerExecutionTimedOut { timeout } ) ?;
352
+ let code = timed_out. context ( CompilerExecutionTimedOutSnafuSnafu { timeout } ) ?;
353
353
354
354
output. status = code;
355
355
output. stderr = stderr. to_owned ( ) ;
@@ -368,7 +368,7 @@ fn wide_open_permissions() -> std::fs::Permissions {
368
368
}
369
369
370
370
fn vec_to_str ( v : Vec < u8 > ) -> Result < String > {
371
- String :: from_utf8 ( v) . context ( OutputNotUtf8 )
371
+ String :: from_utf8 ( v) . context ( OutputNotUtf8Snafu )
372
372
}
373
373
374
374
#[ cfg( test) ]
0 commit comments