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/json/json_file_test.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/tests/json/json_file_test.rs') diff --git a/crates/shirabe/tests/json/json_file_test.rs b/crates/shirabe/tests/json/json_file_test.rs index 195c6918..7aac35a9 100644 --- a/crates/shirabe/tests/json/json_file_test.rs +++ b/crates/shirabe/tests/json/json_file_test.rs @@ -16,8 +16,8 @@ fn expect_parse_exception(text: &str, json: &str) { fn assert_json_format(json: &str, data: &PhpMixed, options: Option) { let json = json.replace('\r', ""); match options { - None => assert_eq!(json, JsonFile::encode(data)), - Some(options) => assert_eq!(json, JsonFile::encode_with_options(data, options)), + None => assert_eq!(json, JsonFile::encode(data).unwrap()), + Some(options) => assert_eq!(json, JsonFile::encode_with_options(data, options).unwrap()), } } @@ -191,11 +191,11 @@ fn test_double_escaped_unicode() { PhpMixed::String("Zdjęcia".to_string()), PhpMixed::String("hjkjhl\\u0119kkjk".to_string()), ]); - let encoded_data = JsonFile::encode(&data); + let encoded_data = JsonFile::encode(&data).unwrap(); let mut wrapper: IndexMap = IndexMap::new(); wrapper.insert("t".to_string(), PhpMixed::String(encoded_data)); - let double_encoded_data = JsonFile::encode(&PhpMixed::Array(wrapper)); + let double_encoded_data = JsonFile::encode(&PhpMixed::Array(wrapper)).unwrap(); let decoded_data = shirabe_php_shim::json_decode(&double_encoded_data, true).unwrap(); let t = decoded_data.as_array().unwrap().get("t").unwrap(); -- cgit v1.3.1