Skip to content

Commit 9cd4ab4

Browse files
committed
chore: log invalid json body
1 parent b21da60 commit 9cd4ab4

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/evaluate.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ fn validate_toggle(_toggle: &Toggle) -> Result<(), FPError> {
496496

497497
#[allow(dead_code)]
498498
pub fn load_json(json_str: &str) -> Result<Repository, FPError> {
499-
let repo = serde_json::from_str::<Repository>(json_str).map_err(FPError::JsonError);
499+
let repo = serde_json::from_str::<Repository>(json_str)
500+
.map_err(|e| FPError::JsonError(json_str.to_owned(), e));
500501
if let Ok(repo) = &repo {
501502
for t in repo.toggles.values() {
502503
validate_toggle(t)?
@@ -1116,7 +1117,8 @@ mod condition_tests {
11161117
}
11171118
"#;
11181119

1119-
let segment = serde_json::from_str::<Condition>(json_str).map_err(FPError::JsonError);
1120+
let segment = serde_json::from_str::<Condition>(json_str)
1121+
.map_err(|e| FPError::JsonError(json_str.to_owned(), e));
11201122
assert!(segment.is_ok())
11211123
}
11221124

src/feature_probe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ mod server_sdk_contract_tests {
350350

351351
#[allow(dead_code)]
352352
pub(crate) fn load_tests_json(json_str: &str) -> Result<Tests, FPError> {
353-
serde_json::from_str::<Tests>(json_str).map_err(FPError::JsonError)
353+
serde_json::from_str::<Tests>(json_str)
354+
.map_err(|e| FPError::JsonError(json_str.to_owned(), e))
354355
}
355356

356357
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub struct FPDetail<T: Default + Debug> {
3535
#[non_exhaustive]
3636
#[derive(Debug, Error)]
3737
pub enum FPError {
38-
#[error("invalid json: {0}")]
39-
JsonError(#[from] serde_json::Error),
38+
#[error("invalid json: {0} error: {1}")]
39+
JsonError(String, serde_json::Error),
4040
#[error("invalid url: {0}")]
4141
UrlError(String),
4242
#[error("http error: {0}")]

src/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl Inner {
176176
Ok(resp) => match resp.text().await {
177177
Err(e) => Err(FPError::HttpError(e.to_string())),
178178
Ok(body) => match serde_json::from_str::<Repository>(&body) {
179-
Err(e) => Err(FPError::JsonError(e)),
179+
Err(e) => Err(FPError::JsonError(body, e)),
180180
Ok(r) => {
181181
// TODO: validate repo
182182
// TODO: diff change, notify subscriber
@@ -216,7 +216,7 @@ impl Inner {
216216
Err(e) => Err(FPError::HttpError(e.to_string())),
217217
Ok(body) => {
218218
match serde_json::from_str::<Repository>(&body) {
219-
Err(e) => Err(FPError::JsonError(e)),
219+
Err(e) => Err(FPError::JsonError(body, e)),
220220
Ok(r) => {
221221
// TODO: validate repo
222222
debug!("sync success {:?}", r);

0 commit comments

Comments
 (0)