Skip to content

Conversation

jgsogo
Copy link
Collaborator

@jgsogo jgsogo commented Dec 10, 2024

No description provided.

Signed-off-by: Javier G. Sogo <[email protected]>
Signed-off-by: Javier G. Sogo <[email protected]>
src/errors.rs Outdated
Comment on lines 121 to 128
#[derive(Debug, Error)]
#[error("Operation '{}' '{}' '{}' failed to evaluate: {}", segment_rule.attribute_name, segment_rule.operator, value, source)]
pub(crate) struct SegmentEvaluationErrorKind {
pub(crate) segment: Segment,
pub(crate) segment_rule: SegmentRule,
pub(crate) value: String,
pub(crate) source: CheckOperatorErrorDetail,
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be more specific with the data we are using here and store just what we need, otherwise this object is too big.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I think for the segment and segment_rule probably the IDs are sufficient. -> follow up PR

Comment on lines +256 to +260
// let msg = rule.unwrap_err().to_string();
// assert!(msg.contains("'a2'"));
// assert!(msg.contains("'0'"));
// assert!(msg.contains("'non_existing_segment_id'"));
// assert!(msg.contains("not found"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the error types chain we are missing the entity

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I wanted to add it, but then thought, let's not over-engineer it. probably the user will know which entity he is evaluating. so maybe it is not required in the error

src/errors.rs Outdated
Comment on lines 115 to 116
#[error(transparent)]
SegmentEvaluationFailed(#[from] SegmentEvaluationErrorKind),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can declare this as follows, and remove one indirection

Suggested change
#[error(transparent)]
SegmentEvaluationFailed(#[from] SegmentEvaluationErrorKind),
#[error("Operation '{}' '{}' '{}' failed to evaluate: {}", segment_rule.attribute_name, segment_rule.operator, value, source)]
SegmentEvaluationFailed {
pub(crate) segment: Segment,
pub(crate) segment_rule: SegmentRule,
pub(crate) value: String,
pub(crate) source: CheckOperatorErrorDetail,
},

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tried this yesterday, but it did not work, as we are not allowed to add visibility qualifiers into enum declaration :-(

@jgsogo jgsogo requested a review from rainerschoe December 10, 2024 13:26
else {
panic!("Error type mismatch!");
};
assert_eq!(error.segment.name, "");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is empty (we have a Segment object). Is name actually empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going with segment ID for debugging always. in the unit-tests the name is empty string. only in the "real" json test data it is set.

@jgsogo
Copy link
Collaborator Author

jgsogo commented Dec 10, 2024

@rainerschoe , I've hidden the errors into a segment_evaluation module. If we like this, it can be kind of a pattern we will follow whenever we want to create a (private) deep hierarchy of errors (error-handling as a hobby 😅 )

rainerschoe
rainerschoe previously approved these changes Dec 11, 2024
Copy link
Member

@rainerschoe rainerschoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this (it works and is a good first step) and refine afterwards.
I like the hiding idea.

Co-authored-by: Rainer Schoenberger <[email protected]>
Signed-off-by: Javier G. Sogo <[email protected]>
@jgsogo jgsogo merged commit 1164943 into IBM:main Dec 11, 2024
2 checks passed
@jgsogo jgsogo deleted the error-handling branch December 11, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants