Skip to content

Commit 84e6254

Browse files
authored
Do not store segment in error, only segment id (#27)
- fix fixture: add segment id - only store segment_id in error, I think whole segment is not needed - clean up some outdated comments
2 parents 1164943 + 7cba841 commit 84e6254

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/segment_evaluation/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) enum SegmentEvaluationError {
2828
#[derive(Debug, Error)]
2929
#[error("Operation '{}' '{}' '{}' failed to evaluate: {}", segment_rule.attribute_name, segment_rule.operator, value, source)]
3030
pub(crate) struct SegmentEvaluationErrorKind {
31-
pub(crate) segment: Segment,
31+
pub(crate) segment_id: String,
3232
pub(crate) segment_rule: SegmentRule,
3333
pub(crate) value: String,
3434
pub(crate) source: CheckOperatorErrorDetail,
@@ -38,7 +38,7 @@ impl From<(CheckOperatorErrorDetail, &Segment, &SegmentRule, &String)> for Segme
3838
fn from(value: (CheckOperatorErrorDetail, &Segment, &SegmentRule, &String)) -> Self {
3939
let (source, segment, segment_rule, value) = value;
4040
Self::SegmentEvaluationFailed(SegmentEvaluationErrorKind {
41-
segment: segment.clone(),
41+
segment_id: segment.segment_id.clone(),
4242
segment_rule: segment_rule.clone(),
4343
value: value.clone(),
4444
source,

src/segment_evaluation/mod.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub mod tests {
176176
"some_segment_id_1".into(),
177177
Segment {
178178
name: "".into(),
179-
segment_id: "".into(),
179+
segment_id: "some_segment_id_1".into(),
180180
description: "".into(),
181181
tags: None,
182182
rules: vec![SegmentRule {
@@ -252,11 +252,6 @@ pub mod tests {
252252
panic!("Error type mismatch!");
253253
};
254254
assert_eq!(segment_id, "non_existing_segment_id");
255-
// let msg = rule.unwrap_err().to_string();
256-
// assert!(msg.contains("'a2'"));
257-
// assert!(msg.contains("'0'"));
258-
// assert!(msg.contains("'non_existing_segment_id'"));
259-
// assert!(msg.contains("not found"));
260255
}
261256

262257
// SCENARIO - evaluating an operator fails. Meaning, [for example] user has added a numeric value(int/float) in appconfig segment attribute, but in their application they pass the attribute with a boolean value.
@@ -269,13 +264,6 @@ pub mod tests {
269264
};
270265
let rule =
271266
find_applicable_segment_rule_for_entity(&segments, segment_rules.into_iter(), &entity);
272-
// Error message should look something like this:
273-
// Failed to evaluate entity: Failed to evaluate entity 'a2' against targeting rule '0'.
274-
// Caused by: Failed to evaluate segment 'some_segment_id_1'
275-
// Caused by: Operation 'name' 'is' 'heinz' failed to evaluate.
276-
// Caused by: Entity attribute has unexpected type: Number.
277-
// We are checking here that the parts are present to allow debugging of config by the user:
278-
279267
let e = rule.unwrap_err();
280268
assert!(matches!(e, Error::EntityEvaluationError(_)));
281269
let Error::EntityEvaluationError(EntityEvaluationError(
@@ -284,7 +272,7 @@ pub mod tests {
284272
else {
285273
panic!("Error type mismatch!");
286274
};
287-
assert_eq!(error.segment.name, "");
275+
assert_eq!(error.segment_id, "some_segment_id_1");
288276
assert_eq!(error.segment_rule.attribute_name, "name");
289277
assert_eq!(error.value, "heinz");
290278
}

0 commit comments

Comments
 (0)