Skip to content

Commit

Permalink
turn some CommandError::IO(_) into a more appropriate FailureReason
Browse files Browse the repository at this point in the history
  • Loading branch information
Skgland committed May 31, 2024
1 parent 83726b8 commit 8dd7383
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/runner/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rustwide::cmd::{CommandError, ProcessLinesActions, SandboxBuilder};
use rustwide::logging::LogStorage;
use rustwide::{Build, PrepareError};
use std::collections::{BTreeSet, HashMap, HashSet};
use std::io::ErrorKind;

fn failure_reason(err: &Error) -> FailureReason {
for cause in err.iter_chain() {
Expand All @@ -24,6 +25,36 @@ fn failure_reason(err: &Error) -> FailureReason {
return FailureReason::Timeout;
} else if let Some(reason) = cause.downcast_ctx::<FailureReason>() {
return reason.clone();
} else if let Some(CommandError::IO(io)) = cause.downcast_ctx() {
match io.kind() {
ErrorKind::OutOfMemory => {
return FailureReason::OOM;
}
_ => {
// FIXME use ErrorKind once #![feature(io_error_more)] is stable <https://github.com/rust-lang/rust/issues/86442>
#[cfg(target_os = "linux")]
match io.raw_os_error() {
// <https://mariadb.com/kb/en/operating-system-error-codes/#linux-error-codes>
| Some(28) /* ErrorKind::StorageFull */
| Some(122) /* ErrorKind::FilesystemQuotaExceeded */
| Some(31) /* TooManyLinks */=> {
return FailureReason::NoSpace
}
_ => {}
}

#[cfg(target_os = "windows")]
match io.raw_os_error() {
// <https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes>
| Some(39|112) /* ErrorKind::StorageFull */
| Some(1295) /* ErrorKind::FilesystemQuotaExceeded */
| Some(1142) /* TooManyLinks */=> {
return FailureReason::NoSpace
}
_ => {}
}
}
}
}
}

Expand Down

0 comments on commit 8dd7383

Please sign in to comment.