Skip to content

Commit 72ff135

Browse files
authored
ref(general): Replace Value::Null variant with empty Annotated (#133)
1 parent dcf51ec commit 72ff135

File tree

16 files changed

+80
-91
lines changed

16 files changed

+80
-91
lines changed

general/src/macros.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ macro_rules! derive_string_meta_structure {
1111
Annotated(None, meta)
1212
}
1313
},
14-
Annotated(Some(Value::Null), meta) => Annotated(None, meta),
1514
Annotated(None, meta) => Annotated(None, meta),
1615
Annotated(Some(value), mut meta) => {
1716
meta.add_error(crate::types::Error::expected($expectation));

general/src/processor/impls.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ impl ProcessValue for Value {
227227
#[inline]
228228
fn value_type(&self) -> Option<ValueType> {
229229
match self {
230-
Value::Null => None,
231230
Value::Bool(_) => Some(ValueType::Boolean),
232231
Value::I64(_) => Some(ValueType::Number),
233232
Value::U64(_) => Some(ValueType::Number),
@@ -249,7 +248,6 @@ impl ProcessValue for Value {
249248
P: Processor,
250249
{
251250
match self {
252-
Value::Null => Default::default(),
253251
Value::Bool(value) => ProcessValue::process_value(value, meta, processor, state),
254252
Value::I64(value) => ProcessValue::process_value(value, meta, processor, state),
255253
Value::U64(value) => ProcessValue::process_value(value, meta, processor, state),

general/src/processor/traits.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub trait Processor: Sized {
8686
pub trait ProcessValue: FromValue + ToValue + Debug {
8787
/// Returns the type of the value.
8888
#[inline]
89+
// TODO(ja): Make this a non-option
8990
fn value_type(&self) -> Option<ValueType> {
9091
None
9192
}

general/src/protocol/debugmeta.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ impl FromValue for DebugId {
8484
Annotated(None, meta)
8585
}
8686
},
87-
Annotated(Some(Value::Null), meta) => Annotated(None, meta),
8887
Annotated(Some(value), mut meta) => {
8988
meta.add_error(Error::expected("debug id"));
9089
meta.set_original_value(Some(value));

general/src/protocol/event.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl Empty for EventType {
100100

101101
impl FromValue for EventType {
102102
fn from_value(value: Annotated<Value>) -> Annotated<Self> {
103-
match <String as FromValue>::from_value(value) {
103+
match String::from_value(value) {
104104
Annotated(Some(value), mut meta) => match value.parse() {
105105
Ok(eventtype) => Annotated(Some(eventtype), meta),
106106
Err(_) => {
@@ -515,17 +515,13 @@ fn test_event_type() {
515515

516516
#[test]
517517
fn test_fingerprint_empty_string() {
518-
let json = r#"{
519-
"fingerprint": [
520-
""
521-
]
522-
}"#;
518+
let json = r#"{"fingerprint":[""]}"#;
523519
let event = Annotated::new(Event {
524520
fingerprint: Annotated::new(vec!["".to_string()].into()),
525521
..Default::default()
526522
});
527523

528-
assert_eq_dbg!(json, event.to_json_pretty().unwrap());
524+
assert_eq_dbg!(json, event.to_json().unwrap());
529525
assert_eq_dbg!(event, Annotated::from_json(json).unwrap());
530526
}
531527

@@ -539,5 +535,5 @@ fn test_fingerprint_null_values() {
539535
});
540536

541537
assert_eq_dbg!(event, Annotated::from_json(input).unwrap());
542-
assert_eq_dbg!(output, event.to_json_pretty().unwrap());
538+
assert_eq_dbg!(output, event.to_json().unwrap());
543539
}

general/src/protocol/exception.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,22 @@ fn test_coerces_object_value_to_string() {
104104
assert_eq_dbg!(exception, Annotated::from_json(input).unwrap());
105105
assert_eq_str!(output, exception.to_json().unwrap());
106106
}
107+
108+
#[test]
109+
fn test_explicit_none() {
110+
let json = r#"{
111+
"value": null,
112+
"type": "ZeroDivisionError"
113+
}"#;
114+
115+
let exception = Annotated::new(Exception {
116+
ty: Annotated::new("ZeroDivisionError".to_string()),
117+
..Default::default()
118+
});
119+
120+
assert_eq_dbg!(exception, Annotated::from_json(json).unwrap());
121+
assert_eq_str!(
122+
r#"{"type":"ZeroDivisionError"}"#,
123+
exception.to_json().unwrap()
124+
);
125+
}

general/src/protocol/logentry.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ impl FromValue for LogEntry {
3232
// add the former as the 'formatted' attribute of the latter.
3333
// See GH-3248
3434
match value {
35-
x @ Annotated(Some(Value::Object(_)), _)
36-
| x @ Annotated(None, _)
37-
| x @ Annotated(Some(Value::Null), _) => {
35+
x @ Annotated(Some(Value::Object(_)), _) | x @ Annotated(None, _) => {
3836
#[derive(Debug, FromValue)]
3937
struct Helper {
4038
message: Annotated<String>,
@@ -58,6 +56,7 @@ impl FromValue for LogEntry {
5856
},
5957
)
6058
}
59+
Annotated(Some(Value::Bool(false)), _) => Annotated(None, Default::default()),
6160
x => Annotated::new(LogEntry {
6261
formatted: LenientString::from_value(x).map_value(|x| x.into_inner()),
6362
..Default::default()

general/src/protocol/mechanism.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ impl FromValue for Mechanism {
190190
})
191191
}
192192
}
193-
Annotated(Some(Value::Null), meta) => Annotated(None, meta),
194193
Annotated(Some(value), mut meta) => {
195194
meta.add_error(Error::expected("exception mechanism"));
196195
meta.set_original_value(Some(value));

general/src/protocol/request.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ impl FromValue for Cookies {
5050
| annotated @ Annotated(Some(Value::Array(_)), _) => {
5151
PairList::from_value(annotated).map_value(Cookies)
5252
}
53-
Annotated(Some(Value::Null), meta) => Annotated(None, meta),
5453
Annotated(None, meta) => Annotated(None, meta),
5554
Annotated(Some(value), mut meta) => {
5655
meta.add_error(Error::expected("cookies"));
@@ -179,7 +178,6 @@ impl FromValue for Query {
179178
| annotated @ Annotated(Some(Value::Array(_)), _) => {
180179
FromValue::from_value(annotated).map_value(Query)
181180
}
182-
Annotated(Some(Value::Null), meta) => Annotated(None, meta),
183181
Annotated(None, meta) => Annotated(None, meta),
184182
Annotated(Some(value), mut meta) => {
185183
meta.add_error(Error::expected("query-string or map"));

general/src/protocol/stacktrace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fn test_frame_vars_null_preserved() {
251251
let frame = Annotated::new(Frame {
252252
vars: Annotated::new({
253253
let mut vars = Object::new();
254-
vars.insert("despacito".to_string(), Annotated::new(Value::Null));
254+
vars.insert("despacito".to_string(), Annotated::empty());
255255
vars
256256
}),
257257
..Default::default()
@@ -272,7 +272,7 @@ fn test_frame_vars_empty_annotated_is_serialized() {
272272
let frame = Annotated::new(Frame {
273273
vars: Annotated::new({
274274
let mut vars = Object::new();
275-
vars.insert("despacito".to_string(), Annotated::new(Value::Null));
275+
vars.insert("despacito".to_string(), Annotated::empty());
276276
vars.insert("despacito2".to_string(), Annotated::empty());
277277
vars
278278
}),

0 commit comments

Comments
 (0)