Skip to content

Commit

Permalink
Merge pull request #760 from Skgland/categorize-container-creation-fa…
Browse files Browse the repository at this point in the history
…ilure

Categorize container creation failure and other docker errors
  • Loading branch information
pietroalbini authored Jan 12, 2025
2 parents 9f7d5cd + 8b03dc9 commit 7e3e9fb
Show file tree
Hide file tree
Showing 38 changed files with 302 additions and 437 deletions.
289 changes: 114 additions & 175 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,57 @@ opt-level = 0
strip = false

[dependencies]
anyhow = "1.0.95"
aws-config = { version = "1", features = ["behavior-version-latest"] }
aws-sdk-s3 = "1.7"
base64 = "0.21.5"
bytes = "1"
cargo_metadata = "0.18.1"
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4", features = ["derive"] }
crates-index = { version = "2.2.0", default-features = false, features = ["git-performance", "git-https"] }
crossbeam-channel = "0.5"
csv = "1.0.2"
ctrlc = "3.1.3"
docsrs-metadata = { git = "https://github.com/rust-lang/docs.rs/" }
dotenv = "0.15"
failure = "0.1.3"
env_logger = "0.10.0"
flate2 = "1"
zstd = "0.13.0"
hmac = "0.12"
http = "0.2"
hyper = "0.14"
indexmap = { version = "2.0.2", features = ["serde"] }
lazy_static = "1.0"
log = "0.4.6"
mime = "0.3.1"
minifier = { version = "0.3", features = ["html"] }
nix = { version = "0.27.1", features = ["mman", "resource"] }
percent-encoding = "2.1.0"
prometheus = "0.13.3"
r2d2 = "0.8.2"
rusqlite = { version = "0.32.1", features = ["chrono", "functions", "bundled"] }
rand = "0.8"
regex = "1.0"
remove_dir_all = "0.7"
reqwest = { version = "0.11", features = ["blocking", "json"] }
rusqlite = { version = "0.32.1", features = ["chrono", "functions", "bundled"] }
rust_team_data = { git = "https://github.com/rust-lang/team" }
rustwide = { version = "0.19.0", features = ["unstable", "unstable-toolchain-ci"] }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde_regex = "1.1.0"
clap = { version = "4", features = ["derive"] }
sha-1 = "0.10"
systemstat = "0.1.11"
tar = "0.4.36"
tempfile = "3.0.0"
tera = "1.19.1"
thiserror = "1.0.38"
tokio = "1.24"
toml = "0.8.6"
url = "2"
walkdir = "2"
warp = "0.3"
log = "0.4.6"
env_logger = "0.10.0"
hmac = "0.12"
sha-1 = "0.10"
rust_team_data = { git = "https://github.com/rust-lang/team" }
systemstat = "0.1.11"
rustwide = { version = "0.16.0", features = ["unstable", "unstable-toolchain-ci"] }
percent-encoding = "2.1.0"
remove_dir_all = "0.7"
ctrlc = "3.1.3"
prometheus = "0.13.3"
cargo_metadata = "0.18.1"
indexmap = { version = "2.0.2", features = ["serde"] }
tokio = "1.24"
aws-sdk-s3 = "1.7"
aws-config = { version = "1", features = ["behavior-version-latest"] }
thiserror = "1.0.38"
nix = { version = "0.27.1", features = ["mman", "resource"] }
zstd = "0.13.0"

[dev-dependencies]
assert_cmd = "2.0.4"
Expand Down
4 changes: 2 additions & 2 deletions src/agent/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ResponseExt for ::reqwest::blocking::Response {
let status = self.status();
let result: ApiResponse<T> = self
.json()
.with_context(|_| format!("failed to parse API response (status code {status})",))?;
.with_context(|| format!("failed to parse API response (status code {status})",))?;
match result {
ApiResponse::Success { result } => Ok(result),
ApiResponse::SlowDown => Err(AgentApiError::ServerUnavailable.into()),
Expand Down Expand Up @@ -139,7 +139,7 @@ impl AgentApi {
})
}

pub fn next_experiment(&self) -> Fallible<Experiment> {
pub fn next_experiment(&self) -> Result<Experiment> {
self.retry(|this| loop {
let resp: Option<_> = this
.build_request(Method::POST, "next-experiment")
Expand Down
10 changes: 5 additions & 5 deletions src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::experiments::Experiment;
use crate::prelude::*;
use crate::utils;
use crate::utils::disk_usage::DiskUsage;
use failure::Error;
use anyhow::{Error, Result};
use rustwide::Workspace;
use std::collections::BTreeSet;
use std::ops;
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Agent {
})
}

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

thread::spawn(move || loop {
if let Err(e) = api.heartbeat().with_context(|_| "failed to send heartbeat") {
if let Err(e) = api.heartbeat().with_context(|| "failed to send heartbeat") {
utils::report_failure(&e);
}
thread::sleep(Duration::from_secs(60));
Expand Down Expand Up @@ -203,8 +203,8 @@ pub fn run(
if let Some(ex) = ex {
if let Err(e) = agent
.api
.report_error(&ex, format!("{}", err.find_root_cause()))
.with_context(|_| "error encountered")
.report_error(&ex, format!("{}", err.root_cause()))
.with_context(|| "error encountered")
{
utils::report_failure(&e);
}
Expand Down
7 changes: 4 additions & 3 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl FileContent {
Ok(match *self {
FileContent::Static(content) => Cow::Borrowed(content),
FileContent::Dynamic(ref path) => {
Cow::Owned(::std::fs::read(path).with_context(|_| {
Cow::Owned(::std::fs::read(path).with_context(|| {
format!("failed to load dynamic asset: {}", path.to_string_lossy())
})?)
}
Expand Down Expand Up @@ -140,7 +140,8 @@ fn build_tera_cache() -> Fallible<Tera> {
.collect::<Vec<_>>();

let mut tera = Tera::default();
tera.add_raw_templates(to_add).to_failure()?;
tera.add_raw_templates(to_add)
.map_err(|err| anyhow!("{err}"))?;
Ok(tera)
}

Expand All @@ -164,5 +165,5 @@ pub fn render_template<C: Serialize>(name: &str, context: C) -> Fallible<String>
let tera_context = tera::Context::from_serialize(context)?;
Ok(tera
.render(name, &tera_context)
.map_err(|e| failure::format_err!("{:?}", e))?)
.map_err(|e| anyhow!("{:?}", e))?)
}
8 changes: 4 additions & 4 deletions src/bin/test-report.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Result;
use crater::experiments::ExperimentDBRecord;
use crater::report::ReportWriter;
use crater::results::EncodingType;
use crater::{config::Config, db::QueryUtils};
use failure::Fallible;
use mime::{self, Mime};
use std::{borrow::Cow, fmt, path::Path};

Expand Down Expand Up @@ -31,7 +31,7 @@ fn main() {
let experiments: Vec<_> = experiments
.into_iter()
.map(|record| record.into_experiment())
.collect::<Fallible<_>>()
.collect::<Result<_>>()
.unwrap();
let ex = experiments.iter().find(|e| e.name == "pr-118920").unwrap();
let rdb = crater::results::DatabaseDB::new(&db);
Expand Down Expand Up @@ -67,11 +67,11 @@ impl ReportWriter for NullWriter {
_b: &[u8],
_mime: &Mime,
_encoding_type: EncodingType,
) -> Fallible<()> {
) -> Result<()> {
// no-op
Ok(())
}
fn write_string<P: AsRef<Path>>(&self, _path: P, _s: Cow<str>, _mime: &Mime) -> Fallible<()> {
fn write_string<P: AsRef<Path>>(&self, _path: P, _s: Cow<str>, _mime: &Mime) -> Result<()> {
// no-op
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! application state employs ownership techniques to ensure that
//! parallel access is consistent and race-free.
use anyhow::{bail, Error, Result};
use clap::Parser;
use crater::actions::{self, Action, ActionsCtx};
use crater::agent::{self, Capabilities};
Expand All @@ -21,7 +22,6 @@ use crater::results::{DatabaseDB, DeleteResults};
use crater::runner;
use crater::server;
use crater::toolchain::Toolchain;
use failure::{bail, Error, Fallible};
use rustwide::{cmd::SandboxImage, Workspace, WorkspaceBuilder};
use std::collections::HashSet;
use std::net::SocketAddr;
Expand All @@ -38,15 +38,15 @@ pub struct DockerEnv(#[allow(unused)] String);
impl FromStr for Ex {
type Err = Error;

fn from_str(ex: &str) -> Fallible<Ex> {
fn from_str(ex: &str) -> Result<Ex> {
Ok(Ex(ex.to_string()))
}
}

impl FromStr for DockerEnv {
type Err = Error;

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

fn from_str(env: &str) -> Fallible<Dest> {
fn from_str(env: &str) -> Result<Dest> {
Ok(Dest(env.into()))
}
}
Expand Down Expand Up @@ -273,7 +273,7 @@ pub enum Crater {
}

impl Crater {
pub fn run(&self) -> Fallible<()> {
pub fn run(&self) -> Result<()> {
match *self {
Crater::CreateLists { ref lists } => {
let mut lists: HashSet<_> = lists.iter().map(|s| s.as_str()).collect();
Expand Down
2 changes: 1 addition & 1 deletion src/crates/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) trait List {
"INSERT INTO crates (crate, list, loaded_at) VALUES (?1, ?2, ?3);",
&[&krate.id(), &Self::NAME, &now],
)
.with_context(|_| {
.with_context(|| {
format!(
"failed to insert crate {} into the {} list",
krate,
Expand Down
4 changes: 2 additions & 2 deletions src/crates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Crate {
}

impl TryFrom<&'_ PackageId> for Crate {
type Error = failure::Error;
type Error = anyhow::Error;

fn try_from(pkgid: &PackageId) -> Fallible<Crate> {
let parts = &pkgid
Expand Down Expand Up @@ -153,7 +153,7 @@ impl fmt::Display for Crate {
}

impl FromStr for Crate {
type Err = ::failure::Error;
type Err = ::anyhow::Error;

// matches with `Crate::id'
fn from_str(s: &str) -> Fallible<Self> {
Expand Down
4 changes: 2 additions & 2 deletions src/crates/sources/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl List for GitHubList {
info!("loading cached GitHub list from {}", self.source);

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

let mut list = Vec::new();
Expand Down Expand Up @@ -88,7 +88,7 @@ impl GitHubRepo {
}

impl FromStr for GitHubRepo {
type Err = ::failure::Error;
type Err = ::anyhow::Error;

fn from_str(input: &str) -> Fallible<Self> {
let mut components = input
Expand Down
4 changes: 2 additions & 2 deletions src/crates/sources/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ impl List for LocalList {
.file_name()
.to_str()
.ok_or_else(|| {
err_msg(format!(
anyhow!(
"invalid UTF-8 in local crate name: {}",
entry.file_name().to_string_lossy()
))
)
})?
.to_string();

Expand Down
5 changes: 2 additions & 3 deletions src/crates/sources/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ impl List for RegistryList {
let mut index = GitIndex::with_path(
WORK_DIR.join("crates.io-index"),
"https://github.com/rust-lang/crates.io-index",
)
.to_failure()?;
index.update().to_failure()?;
)?;
index.update()?;

for krate in index.crates() {
// The versions() method returns the list of published versions starting from the
Expand Down
2 changes: 1 addition & 1 deletion src/db/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ pub fn execute(db: &mut Connection) -> Fallible<()> {
MigrationKind::SQL(sql) => t.execute_batch(sql),
MigrationKind::Code(code) => code(&t),
}
.with_context(|e| format!("error running migration: {name}: {e:?}"))?;
.with_context(|| format!("error running migration: {name}"))?;

t.execute("INSERT INTO migrations (name) VALUES (?1)", [&name])?;
t.commit()?;
Expand Down
6 changes: 3 additions & 3 deletions src/experiments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ pub enum CrateSelect {
from_into_string!(CrateSelect);

impl FromStr for CrateSelect {
type Err = failure::Error;
type Err = anyhow::Error;

fn from_str(s: &str) -> failure::Fallible<Self> {
fn from_str(s: &str) -> Fallible<Self> {
let ret = match s {
s if s.starts_with("top-") => {
let n: u32 = s["top-".len()..].parse()?;
Expand Down Expand Up @@ -156,7 +156,7 @@ impl DeferredCrateSelect {
}

impl FromStr for DeferredCrateSelect {
type Err = failure::Error;
type Err = anyhow::Error;

fn from_str(input: &str) -> Fallible<Self> {
if input.starts_with("https://") || input.starts_with("http://") {
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod cli;

use clap::Parser;
use crater::utils;
use failure::Fallible;
use std::panic;
use std::process;

Expand Down Expand Up @@ -53,6 +52,6 @@ fn main() {
process::exit(i32::from(!success));
}

fn main_() -> Fallible<()> {
fn main_() -> anyhow::Result<()> {
cli::Crater::parse().run()
}
Loading

0 comments on commit 7e3e9fb

Please sign in to comment.