Skip to content

Commit

Permalink
ROVER-331 Add specific CompositionError handling
Browse files Browse the repository at this point in the history
It seems that in the move from old to new we got rid of some specific
handling around composition errors. This has been re-added
  • Loading branch information
jonathanrainer committed Feb 25, 2025
1 parent 484d54f commit a8d30bf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/error/metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::env;

use serde::Serialize;

pub use code::RoverErrorCode;
use houston::HoustonProblem;
use rover_client::{EndpointKind, RoverClientError};
use serde::Serialize;
pub use suggestion::RoverErrorSuggestion;

use crate::{options::JsonVersion, utils::env::RoverEnvKey};
use crate::composition::CompositionError;
use crate::options::JsonVersion;
use crate::utils::env::RoverEnvKey;

mod code;
mod suggestion;
Expand Down Expand Up @@ -396,6 +397,24 @@ impl From<&mut anyhow::Error> for RoverErrorMetadata {
};
}

if let Some(composition_error) = error.downcast_ref::<CompositionError>() {
let (suggestion, code) = match composition_error {
CompositionError::Build { source, .. } => (
Some(RoverErrorSuggestion::FixCompositionErrors {
num_subgraphs: source.len(),
}),
Some(RoverErrorCode::E029),
),
_ => (None, None),
};
return RoverErrorMetadata {
json_version: JsonVersion::default(),
suggestions: suggestion.into_iter().collect(),
code,
skip_printing_cause,
};
}

RoverErrorMetadata::default()
}
}
11 changes: 10 additions & 1 deletion src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use serde::ser::SerializeStruct;
use serde::{Serialize, Serializer};
use serde_json::{json, Value};

use crate::composition::CompositionError;
use crate::options::JsonVersion;

/// A specialized `Error` type for Rover that wraps `anyhow`
Expand Down Expand Up @@ -114,7 +115,15 @@ impl RoverError {
}

pub(crate) fn get_internal_error_json(&self) -> Value {
json!(self)
match self.error.downcast_ref::<CompositionError>() {
None => json!(self),
Some(err) => match err {
CompositionError::Build { source, .. } => {
json!({"details": source, "code": self.code(), "message": self.message()})
}
_ => json!(self),
},
}
}

pub(crate) fn get_json_version(&self) -> JsonVersion {
Expand Down

0 comments on commit a8d30bf

Please # to comment.