@@ -16,59 +16,53 @@ use std::collections::{BTreeSet, HashMap, HashSet};
16
16
use std:: io:: ErrorKind ;
17
17
18
18
fn failure_reason ( err : & Error ) -> FailureReason {
19
- for cause in err. chain ( ) {
20
- if let Some ( command_error) = cause. downcast_ref :: < CommandError > ( ) {
21
- match command_error {
22
- CommandError :: NoOutputFor ( _)
23
- | CommandError :: Timeout ( _)
24
- | CommandError :: KillAfterTimeoutFailed ( _) => return FailureReason :: Timeout ,
25
- CommandError :: SandboxOOM => return FailureReason :: OOM ,
26
- CommandError :: SandboxImagePullFailed ( _)
27
- | CommandError :: SandboxImageMissing ( _)
28
- | CommandError :: SandboxContainerCreate ( _)
29
- | CommandError :: WorkspaceNotMountedCorrectly
30
- | CommandError :: InvalidDockerInspectOutput ( _) => return FailureReason :: Docker ,
31
-
32
- CommandError :: ExecutionFailed { .. } | CommandError :: IO ( _) | _ => { }
33
- }
34
- }
35
-
36
- if let Some ( reason) = cause. downcast_ref :: < FailureReason > ( ) {
37
- return reason. clone ( ) ;
38
- } else if let Some ( CommandError :: IO ( io) ) = cause. downcast_ref ( ) {
39
- match io. kind ( ) {
40
- ErrorKind :: OutOfMemory => {
41
- return FailureReason :: OOM ;
42
- }
43
- _ => {
44
- // FIXME use ErrorKind once #![feature(io_error_more)] is stable <https://github.com/rust-lang/rust/issues/86442>
45
- #[ cfg( target_os = "linux" ) ]
46
- match io. raw_os_error ( ) {
47
- // <https://mariadb.com/kb/en/operating-system-error-codes/#linux-error-codes>
48
- | Some ( 28 ) /* ErrorKind::StorageFull */
49
- | Some ( 122 ) /* ErrorKind::FilesystemQuotaExceeded */
50
- | Some ( 31 ) /* TooManyLinks */ => {
51
- return FailureReason :: NoSpace
52
- }
53
- _ => { }
54
- }
55
-
56
- #[ cfg( target_os = "windows" ) ]
57
- match io. raw_os_error ( ) {
58
- // <https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes>
59
- | Some ( 39 |112 ) /* ErrorKind::StorageFull */
60
- | Some ( 1295 ) /* ErrorKind::FilesystemQuotaExceeded */
61
- | Some ( 1142 ) /* TooManyLinks */ => {
62
- return FailureReason :: NoSpace
63
- }
64
- _ => { }
19
+ if let Some ( reason) = err. downcast_ref :: < FailureReason > ( ) {
20
+ reason. clone ( )
21
+ } else if let Some ( command_error) = err. downcast_ref :: < CommandError > ( ) {
22
+ match command_error {
23
+ CommandError :: NoOutputFor ( _)
24
+ | CommandError :: Timeout ( _)
25
+ | CommandError :: KillAfterTimeoutFailed ( _) => FailureReason :: Timeout ,
26
+ CommandError :: SandboxOOM => FailureReason :: OOM ,
27
+ CommandError :: SandboxImagePullFailed ( _)
28
+ | CommandError :: SandboxImageMissing ( _)
29
+ | CommandError :: SandboxContainerCreate ( _)
30
+ | CommandError :: WorkspaceNotMountedCorrectly
31
+ | CommandError :: InvalidDockerInspectOutput ( _) => FailureReason :: Docker ,
32
+ CommandError :: IO ( io) => {
33
+ match io. kind ( ) {
34
+ ErrorKind :: OutOfMemory => FailureReason :: OOM ,
35
+ _ => {
36
+ // FIXME use ErrorKind once #![feature(io_error_more)] is stable <https://github.com/rust-lang/rust/issues/86442>
37
+ #[ cfg( target_os = "linux" ) ]
38
+ match io. raw_os_error ( ) {
39
+ // <https://mariadb.com/kb/en/operating-system-error-codes/#linux-error-codes>
40
+ | Some ( 28 ) /* ErrorKind::StorageFull */
41
+ | Some ( 122 ) /* ErrorKind::FilesystemQuotaExceeded */
42
+ | Some ( 31 ) /* TooManyLinks */ => {
43
+ return FailureReason :: NoSpace
44
+ }
45
+ _ => FailureReason :: Unknown
46
+ }
47
+
48
+ #[ cfg( target_os = "windows" ) ]
49
+ match io. raw_os_error ( ) {
50
+ // <https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes>
51
+ | Some ( 39 |112 ) /* ErrorKind::StorageFull */
52
+ | Some ( 1295 ) /* ErrorKind::FilesystemQuotaExceeded */
53
+ | Some ( 1142 ) /* TooManyLinks */ => {
54
+ return FailureReason :: NoSpace
55
+ }
56
+ _ => FailureReason :: Unknown
57
+ }
65
58
}
66
59
}
67
60
}
61
+ CommandError :: ExecutionFailed { .. } | _ => FailureReason :: Unknown ,
68
62
}
63
+ } else {
64
+ FailureReason :: Unknown
69
65
}
70
-
71
- FailureReason :: Unknown
72
66
}
73
67
74
68
pub ( super ) fn detect_broken < T > ( res : Result < T , Error > ) -> Result < T , Error > {
@@ -467,10 +461,12 @@ fn is_library(target: &Target) -> bool {
467
461
. all ( |k| ![ "example" , "test" , "bench" ] . contains ( & k. as_str ( ) ) )
468
462
}
469
463
470
-
471
464
#[ test]
472
465
fn test_failure_reason ( ) {
473
- let error : anyhow:: Error = anyhow ! ( CommandError :: IO ( std:: io:: Error :: other( "Test" ) ) ) ;
466
+ let error: anyhow:: Error = anyhow ! ( CommandError :: IO ( std:: io:: Error :: other( "Test" ) ) ) ;
474
467
assert_eq ! ( failure_reason( & error) , FailureReason :: Unknown ) ;
475
- assert_eq ! ( failure_reason( & error. context( FailureReason :: ICE ) ) , FailureReason :: ICE ) ;
468
+ assert_eq ! (
469
+ failure_reason( & error. context( FailureReason :: ICE ) ) ,
470
+ FailureReason :: ICE
471
+ ) ;
476
472
}
0 commit comments