Skip to content

Commit 6b83643

Browse files
committed
fix(ffe): Correct error code mapping and enforce ERROR reason for non-zero error codes
- Fix errorCodeToTag() to match actual Rust constants: 1=ERROR_TYPE_MISMATCH→type_mismatch, 2=ERROR_CONFIG_PARSE→parse_error, 3=ERROR_FLAG_UNRECOGNIZED→flag_not_found (was transposed) - Per OpenFeature spec, force reason=ERROR for any non-zero error_code. FlagUnrecognizedOrDisabled returns REASON_DEFAULT from the Rust layer but must be reported as ERROR to callers.
1 parent dea34a4 commit 6b83643

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/DDTrace/FeatureFlags/FlagEvalMetrics.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ private static function errorCodeToTag($code)
103103
{
104104
switch ((int)$code) {
105105
case 1:
106-
return 'flag_not_found';
106+
return 'type_mismatch'; // ERROR_TYPE_MISMATCH
107107
case 2:
108-
return 'type_mismatch';
108+
return 'parse_error'; // ERROR_CONFIG_PARSE
109109
case 3:
110-
return 'parse_error';
110+
return 'flag_not_found'; // ERROR_FLAG_UNRECOGNIZED
111111
default:
112112
return 'general';
113113
}

src/DDTrace/FeatureFlags/Provider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ public function evaluate($flagKey, $variationType, $defaultValue, $targetingKey,
166166

167167
// Error or no variant → return default
168168
if ($errorCode !== 0 || $result['variant'] === null) {
169-
$evalResult = ['value' => $defaultValue, 'reason' => $reasonStr, 'variant' => null, 'allocation_key' => null,
169+
// Per OpenFeature spec, any non-zero error code must use reason=ERROR
170+
$reportReason = ($errorCode !== 0) ? 'ERROR' : $reasonStr;
171+
$evalResult = ['value' => $defaultValue, 'reason' => $reportReason, 'variant' => null, 'allocation_key' => null,
170172
'error_code' => $errorCode];
171173
FlagEvalMetrics::record($flagKey, $evalResult);
172174
return $evalResult;

0 commit comments

Comments
 (0)