-
Notifications
You must be signed in to change notification settings - Fork 0
fix: handle unknown metric types in API responses #40
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -79,6 +79,9 @@ pub enum MetricType { | |||||
| #[serde(rename = "METRIC_COMPOSITE_EVALUATION")] | ||||||
| #[value(name = "composite")] | ||||||
| CompositeEvaluation, | ||||||
| #[serde(other)] | ||||||
| #[value(skip)] | ||||||
| Unknown, | ||||||
| } | ||||||
|
|
||||||
| impl std::fmt::Display for MetricType { | ||||||
|
|
@@ -95,6 +98,7 @@ impl std::fmt::Display for MetricType { | |||||
| Self::Regex => write!(f, "REGEX"), | ||||||
| Self::Pause => write!(f, "PAUSE"), | ||||||
| Self::CompositeEvaluation => write!(f, "COMPOSITE"), | ||||||
| Self::Unknown => write!(f, "BUILT_IN"), | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't label every unknown server value as
Suggested change- Self::Unknown => write!(f, "BUILT_IN"),
+ Self::Unknown => write!(f, "UNKNOWN"),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
In serde 1.x, when an enum derives Serialize/Deserialize and one unit variant is annotated with #[serde(other)], how is that catch-all variant serialized if it has no #[serde(rename = "...")]?💡 Result:
#[serde(other)]only affects deserialization (it’s the fallback when the input tag doesn’t match any other variant). It does not change how the variant is serialized. So if you serialize that unit variant and it has no#[serde(rename = "...")], Serde will serialize it like any normal unit variant, using its (possiblyrename_all-transformed) variant name as the tag value (e.g.,Unknown→"Unknown"unless renamed by rules). [1]Source:
[1] (serde.rs)
Citations:
Block
Unknownfrom outbound request serialization.The
Unknownvariant will be serialized as"Unknown"by the derivedSerializeimpl, which is not a valid backend enum literal. SinceMetricTypeis used inCreateMetricRequestandUpdateMetricRequest, a deserialized unknown value can leak into outbound requests as invalid data. Either split request and response enums or add a manualSerializeimpl that rejectsUnknownon writes.🤖 Prompt for AI Agents