mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 16:51:01 +00:00
Remove panic
This commit is contained in:
@ -150,14 +150,12 @@ pub struct JsonDocument {
|
||||
}
|
||||
|
||||
impl JsonDocument {
|
||||
pub fn new(value: &serde_json::Value) -> Self {
|
||||
let to_string = serde_json::to_string(&value)
|
||||
.expect("JsonDocument should only be created with valid JSON"); // TODO: Remove panic
|
||||
let back_to_value: BTreeMap<String, Box<RawValue>> = serde_json::from_str(&to_string)
|
||||
.expect("JsonDocument should only be created with valid JSON");
|
||||
let object =
|
||||
liquid::to_object(&value).expect("JsonDocument should only be created with valid JSON");
|
||||
Self { object, cached: back_to_value }
|
||||
pub fn new(value: &serde_json::Value) -> Result<Self, ()> {
|
||||
let to_string = serde_json::to_string(&value).map_err(|_| ())?;
|
||||
let back_to_value: BTreeMap<String, Box<RawValue>> =
|
||||
serde_json::from_str(&to_string).map_err(|_| ())?;
|
||||
let object = liquid::to_object(&value).map_err(|_| ())?;
|
||||
Ok(Self { object, cached: back_to_value })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,12 +173,14 @@ pub fn get_inline_document_fields(
|
||||
index: &Index,
|
||||
rtxn: &RoTxn<'_>,
|
||||
inline_doc: &serde_json::Value,
|
||||
) -> Result<LiquidValue, crate::Error> {
|
||||
) -> Result<Result<LiquidValue, ()>, crate::Error> {
|
||||
let fid_map_with_meta = index.fields_ids_map_with_metadata(rtxn)?;
|
||||
let inline_doc = JsonDocument::new(inline_doc);
|
||||
let Ok(inline_doc) = JsonDocument::new(inline_doc) else {
|
||||
return Ok(Err(()));
|
||||
};
|
||||
let fields = OwnedFields::new(&inline_doc, &fid_map_with_meta);
|
||||
|
||||
Ok(fields.to_value())
|
||||
Ok(Ok(fields.to_value()))
|
||||
}
|
||||
|
||||
pub fn get_document(
|
||||
|
Reference in New Issue
Block a user