Skip to content

Commit

Permalink
fix(error): Skip lineno deserialization on failure
Browse files Browse the repository at this point in the history
### Overview

Relay can send `lineno` field as a u64, but in clickhouse, we are only storing them as u32. This pr changes the behaviour of the error consumer when it encounters a `lineno` greater than a u32, instead of failing, it uses the default value (`None`).
  • Loading branch information
john-z-yang authored May 29, 2024
1 parent 93fb96c commit da2b886
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 10 deletions.
117 changes: 107 additions & 10 deletions rust_snuba/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust_snuba/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ hyper = "1.2.0"
tokio-stream = "0.1.15"
data-encoding = "2.5.0"
zstd = "0.12.3"
serde_with = "3.8.1"


[patch.crates-io]
Expand Down
39 changes: 39 additions & 0 deletions rust_snuba/src/processors/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
use serde::de;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use serde_with::serde_as;
use serde_with::DefaultOnError;
use std::collections::BTreeMap;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use uuid::Uuid;
Expand Down Expand Up @@ -227,6 +229,7 @@ struct StackTrace {
frames: Option<Vec<Option<StackFrame>>>,
}

#[serde_as]
#[derive(Debug, Deserialize, JsonSchema)]
struct StackFrame {
#[serde(default)]
Expand All @@ -243,6 +246,7 @@ struct StackFrame {
in_app: Option<bool>,
#[serde(default)]
colno: Option<u32>,
#[serde_as(deserialize_as = "DefaultOnError")]
#[serde(default)]
lineno: Option<u32>,
}
Expand Down Expand Up @@ -845,4 +849,39 @@ mod tests {
// confused by our untagged enum/anyOf wrapper
run_schema_type_test::<Message>("events", None);
}

#[test]
fn deserialize_invalid_lineno() {
const SERIALIZED: &str = r#"
{
"function": "foo",
"module": "app.hello",
"filename": "hello",
"abs_path": "hello",
"lineno": 90052021220,
"colno": 86472,
"in_app": true,
"context_line": null,
"data": null,
"errors": null,
"raw_function": null,
"image_addr": null,
"instruction_addr": null,
"addr_mode": null,
"package": null,
"platform": null,
"post_context": null,
"pre_context": null,
"source_link": null,
"symbol": null,
"symbol_addr": null,
"trust": null,
"vars": null,
"snapshot": null,
"lock": null
}
"#;
let deserialized: StackFrame = serde_json::from_str(SERIALIZED).unwrap();
assert_eq!(deserialized.lineno, None);
}
}

0 comments on commit da2b886

Please sign in to comment.