From 7e31bab9ff7209c9b6d7928a581d7a449846f42e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 2 Aug 2026 17:32:43 +0900 Subject: fix(json): propagate JsonFile::encode errors instead of unwrapping PHP's JsonFile::encode throws a RuntimeException when json_encode fails; the port swallowed that into an .unwrap() marked TODO(phase-c). Return anyhow::Result from encode/encode_with_options and propagate at every call site (print_table and list_repositories become Result-returning to carry it). Co-Authored-By: Claude Fable 5 --- crates/shirabe/tests/command/bump_command_test.rs | 3 ++- crates/shirabe/tests/command/remove_command_test.rs | 2 +- crates/shirabe/tests/command/repository_command_test.rs | 2 +- crates/shirabe/tests/command/require_command_test.rs | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/tests/command') diff --git a/crates/shirabe/tests/command/bump_command_test.rs b/crates/shirabe/tests/command/bump_command_test.rs index 509b42a7..d511f2a1 100644 --- a/crates/shirabe/tests/command/bump_command_test.rs +++ b/crates/shirabe/tests/command/bump_command_test.rs @@ -43,7 +43,8 @@ fn run_bump_case( let mut json = JsonFile::new("./composer.json".to_string(), None, None).unwrap(); let read = json.read().unwrap(); - let actual: serde_json::Value = serde_json::from_str(&JsonFile::encode(&read)).unwrap(); + let actual: serde_json::Value = + serde_json::from_str(&JsonFile::encode(&read).unwrap()).unwrap(); assert_eq!(expected, actual); drop(tear_down); diff --git a/crates/shirabe/tests/command/remove_command_test.rs b/crates/shirabe/tests/command/remove_command_test.rs index 52e27829..7b195746 100644 --- a/crates/shirabe/tests/command/remove_command_test.rs +++ b/crates/shirabe/tests/command/remove_command_test.rs @@ -28,7 +28,7 @@ fn input(pairs: Vec<(&str, PhpMixed)>) -> Vec<(PhpMixed, PhpMixed)> { fn read_json_file(path: &str) -> serde_json::Value { let mut json = JsonFile::new(path.to_string(), None, None).unwrap(); let read = json.read().unwrap(); - serde_json::from_str(&JsonFile::encode(&read)).unwrap() + serde_json::from_str(&JsonFile::encode(&read).unwrap()).unwrap() } /// Mirrors PHPUnit's assertEmpty for a decoded JSON document (empty object/array/null). diff --git a/crates/shirabe/tests/command/repository_command_test.rs b/crates/shirabe/tests/command/repository_command_test.rs index 901b9f3e..48ca301a 100644 --- a/crates/shirabe/tests/command/repository_command_test.rs +++ b/crates/shirabe/tests/command/repository_command_test.rs @@ -9,7 +9,7 @@ use shirabe_php_shim::PhpMixed; fn read_composer_json() -> serde_json::Value { let mut json = JsonFile::new("./composer.json".to_string(), None, None).unwrap(); let read = json.read().unwrap(); - serde_json::from_str(&JsonFile::encode(&read)).unwrap() + serde_json::from_str(&JsonFile::encode(&read).unwrap()).unwrap() } #[test] diff --git a/crates/shirabe/tests/command/require_command_test.rs b/crates/shirabe/tests/command/require_command_test.rs index f23a6951..4237c4f8 100644 --- a/crates/shirabe/tests/command/require_command_test.rs +++ b/crates/shirabe/tests/command/require_command_test.rs @@ -385,7 +385,8 @@ fn test_inconsistent_require_keys() { let mut composer_content = JsonFile::new(format!("{}/composer.json", dir.display()), None, None).unwrap(); let content = composer_content.read().unwrap(); - let content: serde_json::Value = serde_json::from_str(&JsonFile::encode(&content)).unwrap(); + let content: serde_json::Value = + serde_json::from_str(&JsonFile::encode(&content).unwrap()).unwrap(); assert!( content.get(other_key).is_some(), "expected key {other_key} present" -- cgit v1.3.1