Skip to content

Raise errors instead of unwrapping in document #106

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

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,14 @@ impl Document {
/// Args:
/// field_name (str): The field for which we are adding the bytes.
/// value (str): The json object that will be added to the document.
fn add_json(&mut self, field_name: String, json: &str) {
///
/// Raises a ValueError if the json is invalid.
fn add_json(&mut self, field_name: String, json: &str) -> PyResult<()> {
let json_object: serde_json::Value =
serde_json::from_str(json).unwrap();
serde_json::from_str(json).map_err(to_pyerr)?;
self.add_value(field_name, json_object);

Ok(())
}

/// Returns the number of added fields that have been added to the document
Expand Down