Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 63 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sentry-tracing = "0.36.0"
openssl = { version = "0.10.78", features = ["vendored"] }
openssl-src = { version = "=300.3.1", optional = true }
quick-junit = "0.5.0"
schemars = "1.2"
serde = { version = "1.0.215", features = ["derive"] }
serde_json = "1.0"
clap-verbosity-flag = "3.0.2"
Expand Down
40 changes: 23 additions & 17 deletions cli/src/context_quarantine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,14 @@ use pluralizer::pluralize;
use prost::Message;
use proto::upload_metrics::trunk::QuarantineQueryResult;

use crate::summary_output::Quarantining;

#[derive(Debug)]
pub enum QuarantineFetchStatus {
FetchSucceeded,
FetchSkipped,
FetchFailed(anyhow::Error),
}
impl QuarantineFetchStatus {
pub fn is_failure(&self) -> bool {
match self {
Self::FetchSucceeded => false,
Self::FetchSkipped => false,
Self::FetchFailed(_) => true,
}
}
}

#[derive(Debug)]
pub struct QuarantineContext {
Expand All @@ -54,6 +47,20 @@ pub struct QuarantineContext {
pub quarantine_resolution_mode: QuarantineResolutionMode,
}
impl QuarantineContext {
pub fn quarantining(&self, disable_quarantining: bool) -> Quarantining {
if disable_quarantining {
Quarantining::DisabledViaCli
} else if self.quarantine_status.quarantining_disabled_for_repo {
Quarantining::DisabledViaApi
} else {
match &self.fetch_status {
QuarantineFetchStatus::FetchFailed(_) => Quarantining::LookupFailed,
QuarantineFetchStatus::FetchSkipped => Quarantining::NotNeeded,
QuarantineFetchStatus::FetchSucceeded => Quarantining::Checked,
}
}
}

pub fn skip_fetch(failures: Vec<Test>) -> Self {
Self {
exit_code: i32::default(),
Expand Down Expand Up @@ -83,14 +90,13 @@ pub fn quarantine_query_result(
disable_quarantining: bool,
ctx: &QuarantineContext,
) -> proto::upload_metrics::trunk::QuarantineQueryResult {
if disable_quarantining || ctx.quarantine_status.quarantining_disabled_for_repo {
return QuarantineQueryResult::Disabled;
}

match &ctx.fetch_status {
QuarantineFetchStatus::FetchFailed(_) => QuarantineQueryResult::Failure,
QuarantineFetchStatus::FetchSkipped => QuarantineQueryResult::Skipped,
QuarantineFetchStatus::FetchSucceeded => QuarantineQueryResult::Success,
match ctx.quarantining(disable_quarantining) {
Quarantining::DisabledViaCli | Quarantining::DisabledViaApi => {
QuarantineQueryResult::Disabled
}
Quarantining::LookupFailed => QuarantineQueryResult::Failure,
Quarantining::NotNeeded => QuarantineQueryResult::Skipped,
Quarantining::Checked => QuarantineQueryResult::Success,
}
}

Expand Down
33 changes: 26 additions & 7 deletions cli/src/error_report.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use api::client::ClientErrorExplanation;
use http::StatusCode;
use schemars::JsonSchema;
use serde::Serialize;

pub(crate) const HELP_TEXT: &str = "For more help, contact us at https://slack.trunk.io/";
Expand Down Expand Up @@ -50,21 +51,35 @@ pub struct ErrorReport {

impl ErrorReport {
pub fn new(error: anyhow::Error, org_url_slug: String, base_message: Option<String>) -> Self {
let kind = ErrorKind::of(&error);
match kind {
let report = Self::unlogged(error, org_url_slug, base_message);
match report.kind {
ErrorKind::ConnectionRefused => tracing::warn!(CONNECTION_REFUSED_CONTEXT),
ErrorKind::Unauthorized => tracing::warn!(UNAUTHORIZED_CONTEXT),
ErrorKind::GitRepository => tracing::warn!(GIX_ERROR_CONTEXT),
ErrorKind::Interrupted => {
if let Some(message) = get_interrupting_message(&error) {
if let Some(message) = get_interrupting_message(&report.error) {
tracing::warn!("{}", message);
}
}
ErrorKind::Other => {
tracing::error!("{}", error);
tracing::error!(hidden_in_console = true, "Caused by error: {:#?}", error);
tracing::error!("{}", report.error);
tracing::error!(
hidden_in_console = true,
"Caused by error: {:#?}",
report.error
);
}
}
report
}

/// For callers that log the error themselves, so it isn't sent to Sentry twice.
pub fn unlogged(
error: anyhow::Error,
org_url_slug: String,
base_message: Option<String>,
) -> Self {
let kind = ErrorKind::of(&error);
Self {
context: Context {
base_message,
Expand All @@ -77,12 +92,16 @@ impl ErrorReport {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, JsonSchema)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ErrorKind {
/// Couldn't connect to Trunk.
ConnectionRefused,
/// Trunk rejected the org slug or token.
Unauthorized,
/// The repo root couldn't be opened as a git repository.
GitRepository,
/// The run stopped early, such as when it found no test reports and empty results aren't allowed.
Interrupted,
Other,
}
Expand Down
Loading
Loading