diff --git a/src/cli/mod.rs b/src/cli/mod.rs index fe1f06f..ee1c3c2 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -734,6 +734,7 @@ async fn push_new_release( StatusCode::UNAUTHORIZED => { let body = &release_metadata_post_response.bytes().await?; let message = serde_json::from_slice::(body)?; + return Err(Error::Unauthorized(message))?; } _ => { diff --git a/src/error.rs b/src/error.rs index d3e4705..d094fc9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,6 @@ #[derive(Debug, thiserror::Error)] pub(crate) enum Error { + /// Unauthorized, with a single line message detailing the nature of the problem. #[error("Unauthorized: {0}")] Unauthorized(String), #[error("{upload_name}/{rolling_prefix_or_tag} already exists")] @@ -15,4 +16,17 @@ impl Error { Self::Unauthorized(_) | Self::Conflict { .. } => false, } } + + /// Output a Github Actions annotation command if desired. + // Note: These may only be one line! Any further lines will not be printed! + pub(crate) fn maybe_github_actions_annotation(&self) { + if std::env::var("GITHUB_ACTIONS").is_ok() { + match self { + Error::Unauthorized(message) => { + println!("::error title=Unauthorized::{message}") + } + Error::Conflict { .. } => println!("::error title=Conflict::{self}"), + } + } + } } diff --git a/src/main.rs b/src/main.rs index 9596d35..918b824 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,16 @@ async fn main() -> color_eyre::Result { let cli = cli::FlakeHubPushCli::parse(); cli.instrumentation.setup()?; - cli.execute().await + + match cli.execute().await { + Ok(exit) => Ok(exit), + Err(error) => { + if let Some(known_error) = error.downcast_ref::() { + known_error.maybe_github_actions_annotation() + } + Err(error) + } + } } #[derive(Debug, Clone, Copy, clap::ValueEnum, serde::Serialize, serde::Deserialize)]