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/repository/composer_repository_test.rs | 2 +- crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs | 7 +++++-- crates/shirabe/tests/repository/vcs/gitlab_driver_test.rs | 2 +- crates/shirabe/tests/repository/vcs_repository_test.rs | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/tests/repository') diff --git a/crates/shirabe/tests/repository/composer_repository_test.rs b/crates/shirabe/tests/repository/composer_repository_test.rs index 0d1439b5..1670cb79 100644 --- a/crates/shirabe/tests/repository/composer_repository_test.rs +++ b/crates/shirabe/tests/repository/composer_repository_test.rs @@ -62,7 +62,7 @@ fn repo_config(url: &str) -> IndexMap { } fn json_encode(value: &PhpMixed) -> String { - shirabe::json::json_file::JsonFile::encode(value) + shirabe::json::json_file::JsonFile::encode(value).unwrap() } fn str_kv(pairs: &[(&str, PhpMixed)]) -> PhpMixed { diff --git a/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs b/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs index d9138b0c..46d3832d 100644 --- a/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs @@ -123,6 +123,7 @@ fn repo_body() -> String { ); m })) + .unwrap() } #[test] @@ -175,7 +176,8 @@ fn test_get_branches() { entry.insert("name".to_string(), PhpMixed::String("main".to_string())); entry.insert("commit".to_string(), PhpMixed::Array(commit)); entry - })])); + })])) + .unwrap(); let (http_downloader, _http_guard) = http_mock(vec![ expect_full( @@ -217,7 +219,8 @@ fn test_get_tags() { entry.insert("name".to_string(), PhpMixed::String("1.0".to_string())); entry.insert("commit".to_string(), PhpMixed::Array(commit)); entry - })])); + })])) + .unwrap(); let (http_downloader, _http_guard) = http_mock(vec![ expect_full( diff --git a/crates/shirabe/tests/repository/vcs/gitlab_driver_test.rs b/crates/shirabe/tests/repository/vcs/gitlab_driver_test.rs index 2dd968ce..aa89040d 100644 --- a/crates/shirabe/tests/repository/vcs/gitlab_driver_test.rs +++ b/crates/shirabe/tests/repository/vcs/gitlab_driver_test.rs @@ -513,7 +513,7 @@ fn test_get_paginated_refs() { "2013-03-09T16:35:23.000+01:00", )); } - let branch_data = shirabe::json::JsonFile::encode(&PhpMixed::List(branch_data)); + let branch_data = shirabe::json::JsonFile::encode(&PhpMixed::List(branch_data)).unwrap(); let (http_downloader, _guard) = get_http_downloader_mock( vec![ diff --git a/crates/shirabe/tests/repository/vcs_repository_test.rs b/crates/shirabe/tests/repository/vcs_repository_test.rs index 9ae3eac4..79d40a5d 100644 --- a/crates/shirabe/tests/repository/vcs_repository_test.rs +++ b/crates/shirabe/tests/repository/vcs_repository_test.rs @@ -60,7 +60,7 @@ fn set_up() -> Option { // add composed tag & master branch write_file( "composer.json", - &shirabe::json::JsonFile::encode(&composer(None)), + &shirabe::json::JsonFile::encode(&composer(None)).unwrap(), ); exec(&["add", "composer.json"]); exec(&["commit", "-m", "addcomposer"]); @@ -79,7 +79,7 @@ fn set_up() -> Option { exec(&["checkout", "master"]); write_file( "composer.json", - &shirabe::json::JsonFile::encode(&composer(Some("1.0.0"))), + &shirabe::json::JsonFile::encode(&composer(Some("1.0.0"))).unwrap(), ); exec(&["add", "composer.json"]); exec(&["commit", "-m", "addversion"]); @@ -105,7 +105,7 @@ fn set_up() -> Option { // update master to 2.0 write_file( "composer.json", - &shirabe::json::JsonFile::encode(&composer(Some("2.0.0"))), + &shirabe::json::JsonFile::encode(&composer(Some("2.0.0"))).unwrap(), ); exec(&["add", "composer.json"]); exec(&["commit", "-m", "bump-version"]); -- cgit v1.3.1