Skip to content

Commit 7e3e9fb

Browse files
authored
Merge pull request #760 from Skgland/categorize-container-creation-failure
Categorize container creation failure and other docker errors
2 parents 9f7d5cd + 8b03dc9 commit 7e3e9fb

38 files changed

+302
-437
lines changed

Cargo.lock

Lines changed: 114 additions & 175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,57 @@ opt-level = 0
1212
strip = false
1313

1414
[dependencies]
15+
anyhow = "1.0.95"
16+
aws-config = { version = "1", features = ["behavior-version-latest"] }
17+
aws-sdk-s3 = "1.7"
1518
base64 = "0.21.5"
1619
bytes = "1"
20+
cargo_metadata = "0.18.1"
1721
chrono = { version = "0.4", features = ["serde"] }
22+
clap = { version = "4", features = ["derive"] }
1823
crates-index = { version = "2.2.0", default-features = false, features = ["git-performance", "git-https"] }
1924
crossbeam-channel = "0.5"
2025
csv = "1.0.2"
26+
ctrlc = "3.1.3"
2127
docsrs-metadata = { git = "https://github.com/rust-lang/docs.rs/" }
2228
dotenv = "0.15"
23-
failure = "0.1.3"
29+
env_logger = "0.10.0"
2430
flate2 = "1"
25-
zstd = "0.13.0"
31+
hmac = "0.12"
2632
http = "0.2"
2733
hyper = "0.14"
34+
indexmap = { version = "2.0.2", features = ["serde"] }
2835
lazy_static = "1.0"
36+
log = "0.4.6"
2937
mime = "0.3.1"
3038
minifier = { version = "0.3", features = ["html"] }
39+
nix = { version = "0.27.1", features = ["mman", "resource"] }
40+
percent-encoding = "2.1.0"
41+
prometheus = "0.13.3"
3142
r2d2 = "0.8.2"
32-
rusqlite = { version = "0.32.1", features = ["chrono", "functions", "bundled"] }
3343
rand = "0.8"
3444
regex = "1.0"
45+
remove_dir_all = "0.7"
3546
reqwest = { version = "0.11", features = ["blocking", "json"] }
47+
rusqlite = { version = "0.32.1", features = ["chrono", "functions", "bundled"] }
48+
rust_team_data = { git = "https://github.com/rust-lang/team" }
49+
rustwide = { version = "0.19.0", features = ["unstable", "unstable-toolchain-ci"] }
3650
serde = "1.0"
3751
serde_derive = "1.0"
3852
serde_json = "1.0"
3953
serde_regex = "1.1.0"
40-
clap = { version = "4", features = ["derive"] }
54+
sha-1 = "0.10"
55+
systemstat = "0.1.11"
4156
tar = "0.4.36"
4257
tempfile = "3.0.0"
4358
tera = "1.19.1"
59+
thiserror = "1.0.38"
60+
tokio = "1.24"
4461
toml = "0.8.6"
4562
url = "2"
4663
walkdir = "2"
4764
warp = "0.3"
48-
log = "0.4.6"
49-
env_logger = "0.10.0"
50-
hmac = "0.12"
51-
sha-1 = "0.10"
52-
rust_team_data = { git = "https://github.com/rust-lang/team" }
53-
systemstat = "0.1.11"
54-
rustwide = { version = "0.16.0", features = ["unstable", "unstable-toolchain-ci"] }
55-
percent-encoding = "2.1.0"
56-
remove_dir_all = "0.7"
57-
ctrlc = "3.1.3"
58-
prometheus = "0.13.3"
59-
cargo_metadata = "0.18.1"
60-
indexmap = { version = "2.0.2", features = ["serde"] }
61-
tokio = "1.24"
62-
aws-sdk-s3 = "1.7"
63-
aws-config = { version = "1", features = ["behavior-version-latest"] }
64-
thiserror = "1.0.38"
65-
nix = { version = "0.27.1", features = ["mman", "resource"] }
65+
zstd = "0.13.0"
6666

6767
[dev-dependencies]
6868
assert_cmd = "2.0.4"

src/agent/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ResponseExt for ::reqwest::blocking::Response {
5252
let status = self.status();
5353
let result: ApiResponse<T> = self
5454
.json()
55-
.with_context(|_| format!("failed to parse API response (status code {status})",))?;
55+
.with_context(|| format!("failed to parse API response (status code {status})",))?;
5656
match result {
5757
ApiResponse::Success { result } => Ok(result),
5858
ApiResponse::SlowDown => Err(AgentApiError::ServerUnavailable.into()),
@@ -139,7 +139,7 @@ impl AgentApi {
139139
})
140140
}
141141

142-
pub fn next_experiment(&self) -> Fallible<Experiment> {
142+
pub fn next_experiment(&self) -> Result<Experiment> {
143143
self.retry(|this| loop {
144144
let resp: Option<_> = this
145145
.build_request(Method::POST, "next-experiment")

src/agent/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::experiments::Experiment;
88
use crate::prelude::*;
99
use crate::utils;
1010
use crate::utils::disk_usage::DiskUsage;
11-
use failure::Error;
11+
use anyhow::{Error, Result};
1212
use rustwide::Workspace;
1313
use std::collections::BTreeSet;
1414
use std::ops;
@@ -87,7 +87,7 @@ impl Agent {
8787
})
8888
}
8989

90-
fn experiment(&self) -> Fallible<Experiment> {
90+
fn experiment(&self) -> Result<Experiment> {
9191
info!("asking the server for a new experiment...");
9292
Ok(self.api.next_experiment()?)
9393
}
@@ -137,7 +137,7 @@ fn run_heartbeat(url: &str, token: &str) {
137137
let api = AgentApi::new(url, token);
138138

139139
thread::spawn(move || loop {
140-
if let Err(e) = api.heartbeat().with_context(|_| "failed to send heartbeat") {
140+
if let Err(e) = api.heartbeat().with_context(|| "failed to send heartbeat") {
141141
utils::report_failure(&e);
142142
}
143143
thread::sleep(Duration::from_secs(60));
@@ -203,8 +203,8 @@ pub fn run(
203203
if let Some(ex) = ex {
204204
if let Err(e) = agent
205205
.api
206-
.report_error(&ex, format!("{}", err.find_root_cause()))
207-
.with_context(|_| "error encountered")
206+
.report_error(&ex, format!("{}", err.root_cause()))
207+
.with_context(|| "error encountered")
208208
{
209209
utils::report_failure(&e);
210210
}

src/assets.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl FileContent {
9494
Ok(match *self {
9595
FileContent::Static(content) => Cow::Borrowed(content),
9696
FileContent::Dynamic(ref path) => {
97-
Cow::Owned(::std::fs::read(path).with_context(|_| {
97+
Cow::Owned(::std::fs::read(path).with_context(|| {
9898
format!("failed to load dynamic asset: {}", path.to_string_lossy())
9999
})?)
100100
}
@@ -140,7 +140,8 @@ fn build_tera_cache() -> Fallible<Tera> {
140140
.collect::<Vec<_>>();
141141

142142
let mut tera = Tera::default();
143-
tera.add_raw_templates(to_add).to_failure()?;
143+
tera.add_raw_templates(to_add)
144+
.map_err(|err| anyhow!("{err}"))?;
144145
Ok(tera)
145146
}
146147

@@ -164,5 +165,5 @@ pub fn render_template<C: Serialize>(name: &str, context: C) -> Fallible<String>
164165
let tera_context = tera::Context::from_serialize(context)?;
165166
Ok(tera
166167
.render(name, &tera_context)
167-
.map_err(|e| failure::format_err!("{:?}", e))?)
168+
.map_err(|e| anyhow!("{:?}", e))?)
168169
}

src/bin/test-report.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use anyhow::Result;
12
use crater::experiments::ExperimentDBRecord;
23
use crater::report::ReportWriter;
34
use crater::results::EncodingType;
45
use crater::{config::Config, db::QueryUtils};
5-
use failure::Fallible;
66
use mime::{self, Mime};
77
use std::{borrow::Cow, fmt, path::Path};
88

@@ -31,7 +31,7 @@ fn main() {
3131
let experiments: Vec<_> = experiments
3232
.into_iter()
3333
.map(|record| record.into_experiment())
34-
.collect::<Fallible<_>>()
34+
.collect::<Result<_>>()
3535
.unwrap();
3636
let ex = experiments.iter().find(|e| e.name == "pr-118920").unwrap();
3737
let rdb = crater::results::DatabaseDB::new(&db);
@@ -67,11 +67,11 @@ impl ReportWriter for NullWriter {
6767
_b: &[u8],
6868
_mime: &Mime,
6969
_encoding_type: EncodingType,
70-
) -> Fallible<()> {
70+
) -> Result<()> {
7171
// no-op
7272
Ok(())
7373
}
74-
fn write_string<P: AsRef<Path>>(&self, _path: P, _s: Cow<str>, _mime: &Mime) -> Fallible<()> {
74+
fn write_string<P: AsRef<Path>>(&self, _path: P, _s: Cow<str>, _mime: &Mime) -> Result<()> {
7575
// no-op
7676
Ok(())
7777
}

src/cli.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! application state employs ownership techniques to ensure that
1010
//! parallel access is consistent and race-free.
1111
12+
use anyhow::{bail, Error, Result};
1213
use clap::Parser;
1314
use crater::actions::{self, Action, ActionsCtx};
1415
use crater::agent::{self, Capabilities};
@@ -21,7 +22,6 @@ use crater::results::{DatabaseDB, DeleteResults};
2122
use crater::runner;
2223
use crater::server;
2324
use crater::toolchain::Toolchain;
24-
use failure::{bail, Error, Fallible};
2525
use rustwide::{cmd::SandboxImage, Workspace, WorkspaceBuilder};
2626
use std::collections::HashSet;
2727
use std::net::SocketAddr;
@@ -38,15 +38,15 @@ pub struct DockerEnv(#[allow(unused)] String);
3838
impl FromStr for Ex {
3939
type Err = Error;
4040

41-
fn from_str(ex: &str) -> Fallible<Ex> {
41+
fn from_str(ex: &str) -> Result<Ex> {
4242
Ok(Ex(ex.to_string()))
4343
}
4444
}
4545

4646
impl FromStr for DockerEnv {
4747
type Err = Error;
4848

49-
fn from_str(env: &str) -> Fallible<DockerEnv> {
49+
fn from_str(env: &str) -> Result<DockerEnv> {
5050
Ok(DockerEnv(env.to_string()))
5151
}
5252
}
@@ -57,7 +57,7 @@ pub struct Dest(PathBuf);
5757
impl FromStr for Dest {
5858
type Err = Error;
5959

60-
fn from_str(env: &str) -> Fallible<Dest> {
60+
fn from_str(env: &str) -> Result<Dest> {
6161
Ok(Dest(env.into()))
6262
}
6363
}
@@ -273,7 +273,7 @@ pub enum Crater {
273273
}
274274

275275
impl Crater {
276-
pub fn run(&self) -> Fallible<()> {
276+
pub fn run(&self) -> Result<()> {
277277
match *self {
278278
Crater::CreateLists { ref lists } => {
279279
let mut lists: HashSet<_> = lists.iter().map(|s| s.as_str()).collect();

src/crates/lists.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) trait List {
2929
"INSERT INTO crates (crate, list, loaded_at) VALUES (?1, ?2, ?3);",
3030
&[&krate.id(), &Self::NAME, &now],
3131
)
32-
.with_context(|_| {
32+
.with_context(|| {
3333
format!(
3434
"failed to insert crate {} into the {} list",
3535
krate,

src/crates/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Crate {
7171
}
7272

7373
impl TryFrom<&'_ PackageId> for Crate {
74-
type Error = failure::Error;
74+
type Error = anyhow::Error;
7575

7676
fn try_from(pkgid: &PackageId) -> Fallible<Crate> {
7777
let parts = &pkgid
@@ -153,7 +153,7 @@ impl fmt::Display for Crate {
153153
}
154154

155155
impl FromStr for Crate {
156-
type Err = ::failure::Error;
156+
type Err = ::anyhow::Error;
157157

158158
// matches with `Crate::id'
159159
fn from_str(s: &str) -> Fallible<Self> {

src/crates/sources/github.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl List for GitHubList {
3434
info!("loading cached GitHub list from {}", self.source);
3535

3636
let mut resp = crate::utils::http::get_sync(&self.source)
37-
.with_context(|_| format!("failed to fetch GitHub crates list from {}", self.source))?;
37+
.with_context(|| format!("failed to fetch GitHub crates list from {}", self.source))?;
3838
let mut reader = ::csv::Reader::from_reader(&mut resp);
3939

4040
let mut list = Vec::new();
@@ -88,7 +88,7 @@ impl GitHubRepo {
8888
}
8989

9090
impl FromStr for GitHubRepo {
91-
type Err = ::failure::Error;
91+
type Err = ::anyhow::Error;
9292

9393
fn from_str(input: &str) -> Fallible<Self> {
9494
let mut components = input

0 commit comments

Comments
 (0)