Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROVER-331 Add specific CompositionError handling #2422

Merged
merged 4 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions src/composition/supergraph/config/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ fn graph_id_or_variant() -> String {
const ALPHA_CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ADDITIONAL_CHARSET: &[u8] =
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let mut value = format!(
"{}",
ALPHA_CHARSET[rng.gen_range(0..ALPHA_CHARSET.len())] as char
ALPHA_CHARSET[rng.random_range(0..ALPHA_CHARSET.len())] as char
);
let remaining = rng.gen_range(0..62);
let remaining = rng.random_range(0..62);
for _ in 0..remaining {
let c = ADDITIONAL_CHARSET[rng.gen_range(0..ADDITIONAL_CHARSET.len())] as char;
let c = ADDITIONAL_CHARSET[rng.random_range(0..ADDITIONAL_CHARSET.len())] as char;
value.push(c);
}
value
Expand Down
28 changes: 25 additions & 3 deletions src/error/metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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::options::JsonVersion;
use crate::utils::env::RoverEnvKey;

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

#[cfg(feature = "composition-js")]
{
use crate::composition::CompositionError;
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: 11 additions & 0 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ impl RoverError {
}

pub(crate) fn get_internal_error_json(&self) -> Value {
#[cfg(feature = "composition-js")]
{
use crate::composition::CompositionError;
match self.error.downcast_ref::<CompositionError>() {
Some(CompositionError::Build { source, .. }) => {
json!({"details": source, "code": self.code(), "message": self.message()})
}
_ => json!(self),
}
}
#[cfg(not(feature = "composition-js"))]
json!(self)
}

Expand Down
8 changes: 3 additions & 5 deletions tests/e2e/subgraph/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ use rstest::rstest;
use serde::Deserialize;
use speculoos::assert_that;
use speculoos::iter::ContainingIntoIterAssertions;
use tracing::error;
use tracing::info;
use tracing::{error, info};
use tracing_test::traced_test;

use crate::e2e::remote_supergraph_publish_test_variant_graphref;
use crate::e2e::test_artifacts_directory;
use crate::e2e::{remote_supergraph_publish_test_variant_graphref, test_artifacts_directory};

#[derive(Debug, Deserialize)]
struct SubgraphListResponse {
Expand Down Expand Up @@ -48,7 +46,7 @@ async fn e2e_test_rover_subgraph_publish(
// I appreciate that in theory it's possible there could be a clash here, however, there are
// 3.2 * 10^115 possibilities for identifiers, so I think for practical purposes we can
// consider these as unique.
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let id_regex = rand_regex::Regex::compile("[a-zA-Z][a-zA-Z0-9_-]{0,63}", 100)
.expect("Could not compile regex");
let id: String = rng.sample::<String, &rand_regex::Regex>(&id_regex);
Expand Down
Loading