Skip to content

Commit 572804b

Browse files
committed
[ffe] Expose EvaluationFailure
This is required to allow tracers return more precise error codes.
1 parent 466bafa commit 572804b

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

datadog-ffe/src/rules_based/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum EvaluationError {
2929
/// default assignment.
3030
#[derive(thiserror::Error, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
3131
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
32-
pub(crate) enum EvaluationFailure {
32+
pub enum EvaluationFailure {
3333
/// True evaluation error that should be returned to the user.
3434
#[error(transparent)]
3535
Error(EvaluationError),

datadog-ffe/src/rules_based/eval/eval_assignment.rs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ pub fn get_assignment(
2020
subject: &EvaluationContext,
2121
expected_type: Option<VariationType>,
2222
now: DateTime<Utc>,
23-
) -> Result<Option<Assignment>, EvaluationError> {
23+
) -> Result<Assignment, EvaluationFailure> {
2424
let Some(config) = configuration else {
2525
log::trace!(
2626
flag_key,
2727
targeting_key = subject.targeting_key();
2828
"returning default assignment because of: {}", EvaluationFailure::ConfigurationMissing);
29-
return Ok(None);
29+
return Err(EvaluationFailure::ConfigurationMissing);
3030
};
3131

3232
config.eval_flag(flag_key, subject, expected_type, now)
@@ -39,28 +39,26 @@ impl Configuration {
3939
context: &EvaluationContext,
4040
expected_type: Option<VariationType>,
4141
now: DateTime<Utc>,
42-
) -> Result<Option<Assignment>, EvaluationError> {
42+
) -> Result<Assignment, EvaluationFailure> {
4343
let result = self
4444
.flags
4545
.compiled
4646
.eval_flag(flag_key, context, expected_type, now);
4747

48-
match result {
48+
match &result {
4949
Ok(assignment) => {
5050
log::trace!(
51-
flag_key,
52-
targeting_key = context.targeting_key(),
53-
assignment:serde = assignment.value;
54-
"evaluated a flag");
55-
Ok(Some(assignment))
51+
flag_key,
52+
targeting_key = context.targeting_key(),
53+
assignment:serde = assignment.value;
54+
"evaluated a flag");
5655
}
5756

5857
Err(EvaluationFailure::ConfigurationMissing) => {
5958
log::warn!(
60-
flag_key,
61-
targeting_key = context.targeting_key();
62-
"evaluating a flag before flags configuration has been fetched");
63-
Ok(None)
59+
flag_key,
60+
targeting_key = context.targeting_key();
61+
"evaluating a flag before flags configuration has been fetched");
6462
}
6563

6664
Err(EvaluationFailure::Error(err)) => {
@@ -69,19 +67,16 @@ impl Configuration {
6967
targeting_key = context.targeting_key();
7068
"error occurred while evaluating a flag: {err}",
7169
);
72-
Err(err)
7370
}
74-
75-
// Non-Error failures are considered normal conditions and usually don't need extra
76-
// attention, so we remap them to Ok(None) before returning to the user.
7771
Err(err) => {
7872
log::trace!(
7973
flag_key,
8074
targeting_key = context.targeting_key();
8175
"returning default assignment because of: {err}");
82-
Ok(None)
8376
}
8477
}
78+
79+
result
8580
}
8681
}
8782

@@ -281,8 +276,7 @@ mod tests {
281276
&subject,
282277
Some(test_case.variation_type),
283278
now,
284-
)
285-
.unwrap_or(None);
279+
);
286280

287281
let result_assingment = result
288282
.as_ref()

datadog-ffe/src/rules_based/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod ufc;
1212

1313
pub use attributes::Attribute;
1414
pub use configuration::Configuration;
15-
pub use error::EvaluationError;
15+
pub use error::{EvaluationError, EvaluationFailure};
1616
pub use eval::{get_assignment, EvaluationContext};
1717
pub use str::Str;
1818
pub use timestamp::{now, Timestamp};

0 commit comments

Comments
 (0)