Skip to content

Commit 31552f0

Browse files
committed
core/json: Kill some unwrap() calls
1 parent 2d9a54c commit 31552f0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

core/json/error.rs

+8
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,11 @@ pub fn set_location<T>(res: &mut Result<T>, span: &Span<'_>) {
106106
}
107107
}
108108
}
109+
110+
impl From<Error> for crate::LimboError {
111+
fn from(err: Error) -> Self {
112+
match err {
113+
Error::Message { msg, .. } => crate::LimboError::ParseError(msg),
114+
}
115+
}
116+
}

core/json/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub fn get_json(json_value: &OwnedValue, indent: Option<&str>) -> crate::Result<
4343

4444
let json_val = get_json_value(json_value)?;
4545
let json = match indent {
46-
Some(indent) => to_string_pretty(&json_val, indent).unwrap(),
47-
None => to_string(&json_val).unwrap(),
46+
Some(indent) => to_string_pretty(&json_val, indent)?,
47+
None => to_string(&json_val)?,
4848
};
4949

5050
Ok(OwnedValue::Text(LimboText::json(Rc::new(json))))
@@ -62,8 +62,8 @@ pub fn get_json(json_value: &OwnedValue, indent: Option<&str>) -> crate::Result<
6262
_ => {
6363
let json_val = get_json_value(json_value)?;
6464
let json = match indent {
65-
Some(indent) => to_string_pretty(&json_val, indent).unwrap(),
66-
None => to_string(&json_val).unwrap(),
65+
Some(indent) => to_string_pretty(&json_val, indent)?,
66+
None => to_string(&json_val)?,
6767
};
6868

6969
Ok(OwnedValue::Text(LimboText::json(Rc::new(json))))
@@ -166,7 +166,7 @@ pub fn json_arrow_extract(value: &OwnedValue, path: &OwnedValue) -> crate::Resul
166166
let extracted = json_extract_single(&json, path, false)?;
167167

168168
if let Some(val) = extracted {
169-
let json = to_string(val).unwrap();
169+
let json = to_string(val)?;
170170

171171
Ok(OwnedValue::Text(LimboText::json(Rc::new(json))))
172172
} else {
@@ -223,7 +223,7 @@ pub fn json_extract(value: &OwnedValue, paths: &[OwnedValue]) -> crate::Result<O
223223
return Ok(OwnedValue::Null);
224224
}
225225

226-
result.push_str(&to_string(&extracted).unwrap());
226+
result.push_str(&to_string(&extracted)?);
227227
result.push(',');
228228
}
229229
}
@@ -261,7 +261,7 @@ fn convert_json_to_db_type(extracted: &Val, all_as_db: bool) -> crate::Result<Ow
261261
}
262262
Val::String(s) => Ok(OwnedValue::Text(LimboText::new(Rc::new(s.clone())))),
263263
_ => {
264-
let json = to_string(&extracted).unwrap();
264+
let json = to_string(&extracted)?;
265265
if all_as_db {
266266
Ok(OwnedValue::Text(LimboText::new(Rc::new(json))))
267267
} else {
@@ -516,7 +516,7 @@ pub fn json_object(values: &[OwnedValue]) -> crate::Result<OwnedValue> {
516516
})
517517
.collect::<Result<IndexMap<String, Val>, _>>()?;
518518

519-
let result = crate::json::to_string(&value_map).unwrap();
519+
let result = crate::json::to_string(&value_map)?;
520520
Ok(OwnedValue::Text(LimboText::json(Rc::new(result))))
521521
}
522522

0 commit comments

Comments
 (0)