aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe')
-rw-r--r--crates/shirabe/src/advisory/auditor.rs2
-rw-r--r--crates/shirabe/src/command/check_platform_reqs_command.rs8
-rw-r--r--crates/shirabe/src/command/config_command.rs2
-rw-r--r--crates/shirabe/src/command/fund_command.rs2
-rw-r--r--crates/shirabe/src/command/init_command.rs2
-rw-r--r--crates/shirabe/src/command/licenses_command.rs2
-rw-r--r--crates/shirabe/src/command/repository_command.rs15
-rw-r--r--crates/shirabe/src/command/search_command.rs2
-rw-r--r--crates/shirabe/src/command/show_command.rs8
-rw-r--r--crates/shirabe/src/factory.rs2
-rw-r--r--crates/shirabe/src/json/json_file.rs24
-rw-r--r--crates/shirabe/src/json/json_manipulator.rs74
-rw-r--r--crates/shirabe/src/package/locker.rs4
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs6
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs2
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs2
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs2
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs2
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs2
-rw-r--r--crates/shirabe/src/repository/vcs/vcs_driver.rs4
-rw-r--r--crates/shirabe/tests/command/bump_command_test.rs3
-rw-r--r--crates/shirabe/tests/command/remove_command_test.rs2
-rw-r--r--crates/shirabe/tests/command/repository_command_test.rs2
-rw-r--r--crates/shirabe/tests/command/require_command_test.rs3
-rw-r--r--crates/shirabe/tests/installer_test.rs6
-rw-r--r--crates/shirabe/tests/json/json_file_test.rs8
-rw-r--r--crates/shirabe/tests/json/json_manipulator_test.rs2
-rw-r--r--crates/shirabe/tests/package/locker_test.rs7
-rw-r--r--crates/shirabe/tests/repository/composer_repository_test.rs2
-rw-r--r--crates/shirabe/tests/repository/vcs/forgejo_driver_test.rs7
-rw-r--r--crates/shirabe/tests/repository/vcs/gitlab_driver_test.rs2
-rw-r--r--crates/shirabe/tests/repository/vcs_repository_test.rs6
32 files changed, 118 insertions, 99 deletions
diff --git a/crates/shirabe/src/advisory/auditor.rs b/crates/shirabe/src/advisory/auditor.rs
index e0bb374c..853fa36f 100644
--- a/crates/shirabe/src/advisory/auditor.rs
+++ b/crates/shirabe/src/advisory/auditor.rs
@@ -189,7 +189,7 @@ impl Auditor {
abandoned,
};
- io.write(&JsonFile::encode(&report));
+ io.write(&JsonFile::encode(&report)?);
return Ok(audit_bitmask);
}
diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs
index 088c9407..903e0c4c 100644
--- a/crates/shirabe/src/command/check_platform_reqs_command.rs
+++ b/crates/shirabe/src/command/check_platform_reqs_command.rs
@@ -59,7 +59,7 @@ impl CheckPlatformReqsCommand {
output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
results: &[CheckResult],
format: &str,
- ) {
+ ) -> anyhow::Result<()> {
let io = self.get_io();
if format == "json" {
@@ -117,7 +117,7 @@ impl CheckPlatformReqsCommand {
})
.collect();
- io.write(&JsonFile::encode(&PhpMixed::List(rows)));
+ io.write(&JsonFile::encode(&PhpMixed::List(rows))?);
} else {
let rows: Vec<PhpMixed> = results
.iter()
@@ -151,6 +151,8 @@ impl CheckPlatformReqsCommand {
self.render_table(rows, output);
}
+
+ Ok(())
}
}
@@ -396,7 +398,7 @@ impl Command for CheckPlatformReqsCommand {
.as_string()
.unwrap_or("text")
.to_string();
- self.print_table(_output, &results, &format);
+ self.print_table(_output, &results, &format)?;
Ok(exit_code)
}
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 0b22757a..7e8b82e9 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -497,7 +497,7 @@ impl Command for ConfigCommand {
pretty_print: false,
..Default::default()
},
- )
+ )?
} else {
value.as_string().unwrap_or("").to_string()
};
diff --git a/crates/shirabe/src/command/fund_command.rs b/crates/shirabe/src/command/fund_command.rs
index bf5e281a..8ea566dc 100644
--- a/crates/shirabe/src/command/fund_command.rs
+++ b/crates/shirabe/src/command/fund_command.rs
@@ -211,7 +211,7 @@ impl Command for FundCommand {
io.write("Thank you!");
} else if format == "json" {
let fundings_mixed: PhpMixed = fundings.clone().into();
- io.write(&JsonFile::encode(&fundings_mixed));
+ io.write(&JsonFile::encode(&fundings_mixed)?);
} else {
io.write("No funding links were found in your package dependencies. This doesn't mean they don't need your support!");
}
diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs
index ec3f38b5..6923f768 100644
--- a/crates/shirabe/src/command/init_command.rs
+++ b/crates/shirabe/src/command/init_command.rs
@@ -290,7 +290,7 @@ impl Command for InitCommand {
let file_obj = JsonFile::new(Factory::get_composer_file()?, None, None)?;
let options_for_encode: IndexMap<String, PhpMixed> = options.clone().into_iter().collect();
- let json = JsonFile::encode(&PhpMixed::Array(options_for_encode.clone()));
+ let json = JsonFile::encode(&PhpMixed::Array(options_for_encode.clone()))?;
if input.borrow().is_interactive() {
io.write_error3(&format!("\n{}\n", json), true, io_interface::NORMAL);
diff --git a/crates/shirabe/src/command/licenses_command.rs b/crates/shirabe/src/command/licenses_command.rs
index 002bce89..41e9ba90 100644
--- a/crates/shirabe/src/command/licenses_command.rs
+++ b/crates/shirabe/src/command/licenses_command.rs
@@ -273,7 +273,7 @@ impl Command for LicensesCommand {
output_map.insert("dependencies".to_string(), PhpMixed::Array(dependencies));
io.write(&JsonFile::encode(&PhpMixed::Array(
output_map.into_iter().collect(),
- )));
+ ))?);
}
"summary" => {
let mut used_licenses: IndexMap<String, i64> = IndexMap::new();
diff --git a/crates/shirabe/src/command/repository_command.rs b/crates/shirabe/src/command/repository_command.rs
index 31d2de3f..d23e114c 100644
--- a/crates/shirabe/src/command/repository_command.rs
+++ b/crates/shirabe/src/command/repository_command.rs
@@ -50,7 +50,7 @@ impl RepositoryCommand {
command
}
- fn list_repositories(&self, mut repos: IndexMap<String, PhpMixed>) {
+ fn list_repositories(&self, mut repos: IndexMap<String, PhpMixed>) -> anyhow::Result<()> {
let io = self.get_io();
let mut packagist_present = false;
@@ -84,7 +84,7 @@ impl RepositoryCommand {
if repos.is_empty() {
io.write("No repositories configured");
- return;
+ return Ok(());
}
for (key, repo) in &repos {
@@ -111,14 +111,19 @@ impl RepositoryCommand {
.get("type")
.and_then(|v| v.as_string())
.unwrap_or("unknown");
- let url = repo_map
+ let url = match repo_map
.get("url")
.and_then(|v| v.as_string())
.map(|s| s.to_string())
- .unwrap_or_else(|| JsonFile::encode(repo));
+ {
+ Some(url) => url,
+ None => JsonFile::encode(repo)?,
+ };
io.write(&format!("[{}] <info>{}</info> {}", name, r#type, url));
}
}
+
+ Ok(())
}
/// PHP: private function suggestTypeForAdd(): \Closure (a static closure — `this` unused)
@@ -352,7 +357,7 @@ impl Command for RepositoryCommand {
match action.as_str() {
"list" | "ls" | "show" => {
- self.list_repositories(repos);
+ self.list_repositories(repos)?;
Ok(0)
}
"add" => {
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs
index 2e0f95da..b0eabf80 100644
--- a/crates/shirabe/src/command/search_command.rs
+++ b/crates/shirabe/src/command/search_command.rs
@@ -293,7 +293,7 @@ impl Command for SearchCommand {
PhpMixed::Array(entry)
})
.collect();
- io.write(&JsonFile::encode(&PhpMixed::List(rows)));
+ io.write(&JsonFile::encode(&PhpMixed::List(rows))?);
}
Ok(0)
diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs
index 4cc0c204..a3bf7157 100644
--- a/crates/shirabe/src/command/show_command.rs
+++ b/crates/shirabe/src/command/show_command.rs
@@ -698,7 +698,7 @@ impl Command for ShowCommand {
);
self.get_io().write(&JsonFile::encode(&PhpMixed::Array(
wrapper.into_iter().collect(),
- )));
+ ))?);
} else {
self.display_package_tree(vec![array_tree]);
}
@@ -829,7 +829,7 @@ impl Command for ShowCommand {
);
self.get_io().write(&JsonFile::encode(&PhpMixed::Array(
wrapper.into_iter().collect(),
- )));
+ ))?);
} else {
self.display_package_tree(array_tree);
}
@@ -1289,7 +1289,7 @@ impl Command for ShowCommand {
let io = self.get_io();
io.write(&JsonFile::encode(&PhpMixed::Array(
json_map.into_iter().collect(),
- )));
+ ))?);
} else {
if input.borrow().get_option("latest")?.as_bool() == Some(true)
&& view_data.values().any(|v| !v.is_empty())
@@ -2222,7 +2222,7 @@ impl ShowCommand {
self.get_io().write(&JsonFile::encode(&PhpMixed::Array(
json.into_iter().collect(),
- )));
+ ))?);
Ok(())
}
diff --git a/crates/shirabe/src/factory.rs b/crates/shirabe/src/factory.rs
index 98fba740..b5f96cc3 100644
--- a/crates/shirabe/src/factory.rs
+++ b/crates/shirabe/src/factory.rs
@@ -790,7 +790,7 @@ impl Factory {
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect(),
- ));
+ ))?;
let locker = Locker::new(
io.clone(),
JsonFile::new(Platform::get_dev_null(), None, Some(io.clone()))?,
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index cba11f01..632519a7 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -220,7 +220,7 @@ impl JsonFile {
if self.path == "php://memory" {
file_put_contents(
&self.path,
- Self::encode_with_options(&hash, options).as_bytes(),
+ Self::encode_with_options(&hash, options)?.as_bytes(),
);
return Ok(());
@@ -256,7 +256,7 @@ impl JsonFile {
&self.path,
&format!(
"{}{}",
- Self::encode_with_options(&hash, options.clone()),
+ Self::encode_with_options(&hash, options.clone())?,
if options.pretty_print { "\n" } else { "" },
),
)?;
@@ -443,25 +443,23 @@ impl JsonFile {
Ok(true)
}
- pub fn encode<T: serde::Serialize + ?Sized>(data: &T) -> String {
+ pub fn encode<T: serde::Serialize + ?Sized>(data: &T) -> anyhow::Result<String> {
Self::encode_with_options(data, JsonEncodeOptions::default())
}
pub fn encode_with_options<T: serde::Serialize + ?Sized>(
data: &T,
options: JsonEncodeOptions,
- ) -> String {
- let json = json_encode_ex(data, options.to_flags())
- .map_err(|err| RuntimeException {
- message: format!("JSON encoding failed: {}", err),
- code: 0,
- })
- .unwrap(); // TODO(phase-c): propagating an Err.
+ ) -> anyhow::Result<String> {
+ let json = json_encode_ex(data, options.to_flags()).map_err(|err| RuntimeException {
+ message: format!("JSON encoding failed: {}", err),
+ code: 0,
+ })?;
if options.pretty_print && options.indent != Self::INDENT_DEFAULT {
// Pretty printing and not using default indentation
let indent_owned = options.indent;
- return Preg::replace_callback(
+ return Ok(Preg::replace_callback(
php_regex!(r"#^ {4,}#m"),
move |m: &indexmap::IndexMap<
shirabe_external_packages::composer::pcre::CaptureKey,
@@ -475,10 +473,10 @@ impl JsonFile {
str_repeat(&indent_owned, (strlen(whole) / 4) as usize)
},
&json,
- );
+ ));
}
- json
+ Ok(json)
}
/// Parses json string and returns hash.
diff --git a/crates/shirabe/src/json/json_manipulator.rs b/crates/shirabe/src/json/json_manipulator.rs
index 3647e846..48500de2 100644
--- a/crates/shirabe/src/json/json_manipulator.rs
+++ b/crates/shirabe/src/json/json_manipulator.rs
@@ -85,7 +85,7 @@ impl JsonManipulator {
let m = match json_grammar::find_top_level_key(
self.contents.as_bytes(),
- JsonFile::encode(r#type).as_bytes(),
+ JsonFile::encode(r#type)?.as_bytes(),
ValueKind::Json,
) {
Some(m) => m,
@@ -107,7 +107,7 @@ impl JsonManipulator {
links = format!(
"{}{}{}\"{}\"{}",
&links[..key_start],
- JsonFile::encode(&str_replace("\\/", "/", &existing_package)),
+ JsonFile::encode(&str_replace("\\/", "/", &existing_package))?,
separator,
constraint,
&links[value_end..]
@@ -133,8 +133,8 @@ impl JsonManipulator {
self.newline,
self.indent,
self.indent,
- JsonFile::encode(package),
- JsonFile::encode(constraint),
+ JsonFile::encode(package)?,
+ JsonFile::encode(constraint)?,
groups_1
),
"\\$",
@@ -148,8 +148,8 @@ impl JsonManipulator {
self.newline,
self.indent,
self.indent,
- JsonFile::encode(package),
- JsonFile::encode(constraint),
+ JsonFile::encode(package)?,
+ JsonFile::encode(constraint)?,
self.newline,
self.indent
);
@@ -375,22 +375,28 @@ impl JsonManipulator {
Some((i, e))
})
} else {
- json_grammar::find_top_level_key(
- self.contents.as_bytes(),
- b"\"repositories\"",
- ValueKind::Object,
- )
- .and_then(|reps| {
- let obj = self.contents[reps.value_pos..reps.value_end].to_string();
- let key = JsonFile::encode(&repository_index);
- json_grammar::find_top_level_key(obj.as_bytes(), key.as_bytes(), ValueKind::Object)
+ {
+ let key = JsonFile::encode(&repository_index)?;
+ json_grammar::find_top_level_key(
+ self.contents.as_bytes(),
+ b"\"repositories\"",
+ ValueKind::Object,
+ )
+ .and_then(|reps| {
+ let obj = self.contents[reps.value_pos..reps.value_end].to_string();
+ json_grammar::find_top_level_key(
+ obj.as_bytes(),
+ key.as_bytes(),
+ ValueKind::Object,
+ )
.map(|inner| {
(
reps.value_pos + inner.value_pos,
reps.value_pos + inner.value_end,
)
})
- })
+ })
+ }
};
let (repo_pos, repo_end) = match repo_span {
@@ -416,7 +422,7 @@ impl JsonManipulator {
Some(u) => format!(
"{}{}{}",
&raw_repo[..u.value_pos],
- JsonFile::encode(url),
+ JsonFile::encode(url)?,
&raw_repo[u.value_end..]
),
None => raw_repo,
@@ -692,7 +698,7 @@ impl JsonManipulator {
// main node content not match-able
let node = match json_grammar::find_top_level_key(
self.contents.as_bytes(),
- JsonFile::encode(main_node).as_bytes(),
+ JsonFile::encode(main_node)?.as_bytes(),
ValueKind::Object,
) {
Some(node) => node,
@@ -771,7 +777,7 @@ impl JsonManipulator {
self.newline,
self.indent,
self.indent,
- JsonFile::encode(&name_owned),
+ JsonFile::encode(&name_owned)?,
self.format(&value_local, 1, false)?,
whitespace
),
@@ -787,7 +793,7 @@ impl JsonManipulator {
&format!(
"{{{}{}: {},{}{}{}",
whitespace,
- JsonFile::encode(&name_owned),
+ JsonFile::encode(&name_owned)?,
self.format(&value_local, 1, false)?,
self.newline,
self.indent,
@@ -812,7 +818,7 @@ impl JsonManipulator {
self.newline,
self.indent,
self.indent,
- JsonFile::encode(&name_owned),
+ JsonFile::encode(&name_owned)?,
self.format(&value_local, 1, false)?,
whitespace
);
@@ -843,7 +849,7 @@ impl JsonManipulator {
// no node content match-able
let node = match json_grammar::find_top_level_key(
self.contents.as_bytes(),
- JsonFile::encode(main_node).as_bytes(),
+ JsonFile::encode(main_node)?.as_bytes(),
ValueKind::Object,
) {
Some(node) => node,
@@ -1025,7 +1031,7 @@ impl JsonManipulator {
// main node content not match-able
let node = match json_grammar::find_top_level_key(
self.contents.as_bytes(),
- JsonFile::encode(main_node).as_bytes(),
+ JsonFile::encode(main_node)?.as_bytes(),
ValueKind::Array,
) {
Some(node) => node,
@@ -1161,7 +1167,7 @@ impl JsonManipulator {
// main node content not match-able
let node = match json_grammar::find_top_level_key(
self.contents.as_bytes(),
- JsonFile::encode(main_node).as_bytes(),
+ JsonFile::encode(main_node)?.as_bytes(),
ValueKind::Array,
) {
Some(node) => node,
@@ -1225,7 +1231,7 @@ impl JsonManipulator {
// no node content match-able
let node = match json_grammar::find_top_level_key(
self.contents.as_bytes(),
- JsonFile::encode(main_node).as_bytes(),
+ JsonFile::encode(main_node)?.as_bytes(),
ValueKind::Array,
) {
Some(node) => node,
@@ -1304,7 +1310,7 @@ impl JsonManipulator {
let content = self.format(&content, 0, false)?;
// key exists already
- let encoded_key = JsonFile::encode(key);
+ let encoded_key = JsonFile::encode(key)?;
let key_match = if decoded.as_array().and_then(|a| a.get(key)).is_some() {
json_grammar::find_top_level_key(
self.contents.as_bytes(),
@@ -1350,7 +1356,7 @@ impl JsonManipulator {
",{}{}{}: {}{}}}",
self.newline,
self.indent,
- JsonFile::encode(key),
+ JsonFile::encode(key)?,
content,
self.newline
),
@@ -1369,7 +1375,7 @@ impl JsonManipulator {
&format!(
"{}{}: {}{}}}",
self.indent,
- JsonFile::encode(key),
+ JsonFile::encode(key)?,
content,
self.newline
),
@@ -1390,7 +1396,7 @@ impl JsonManipulator {
}
// key exists already
- let encoded_key = JsonFile::encode(key);
+ let encoded_key = JsonFile::encode(key)?;
let key_match = json_grammar::find_top_level_key(
self.contents.as_bytes(),
encoded_key.as_bytes(),
@@ -1443,7 +1449,7 @@ impl JsonManipulator {
}
// Match the key only when its value is an empty object `{ <space> }`.
- let encoded_key = JsonFile::encode(key);
+ let encoded_key = JsonFile::encode(key)?;
let cb = self.contents.as_bytes();
let key_match =
json_grammar::find_top_level_key(cb, encoded_key.as_bytes(), ValueKind::Object)
@@ -1531,7 +1537,7 @@ impl JsonManipulator {
elems.push(format!(
"{}{}: {}",
str_repeat(&self.indent, (depth + 2) as usize),
- JsonFile::encode(key),
+ JsonFile::encode(key)?,
self.format(val, depth + 1, false)?
));
}
@@ -1546,7 +1552,7 @@ impl JsonManipulator {
));
}
- Ok(JsonFile::encode(&data))
+ JsonFile::encode(&data)
}
pub(crate) fn detect_indenting(&mut self) {
@@ -1707,7 +1713,7 @@ impl ManipulatorFormatter {
elems.push(format!(
"{}{}: {}",
str_repeat(&self.indent, (depth + 2) as usize),
- JsonFile::encode(key),
+ JsonFile::encode(key)?,
self.format(val, depth + 1, false)?
));
}
@@ -1722,6 +1728,6 @@ impl ManipulatorFormatter {
));
}
- Ok(JsonFile::encode(&data))
+ JsonFile::encode(&data)
}
}
diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs
index 02cbfa4a..b7d8ba7a 100644
--- a/crates/shirabe/src/package/locker.rs
+++ b/crates/shirabe/src/package/locker.rs
@@ -132,7 +132,7 @@ impl Locker {
&JsonFile::encode_with_options(
&PhpMixed::Array(relevant_content.into_iter().collect()),
JsonEncodeOptions::none(),
- ),
+ )?,
))
}
@@ -620,7 +620,7 @@ impl Locker {
let parsed = JsonFile::parse_json(
Some(&JsonFile::encode(&PhpMixed::Array(
lock.into_iter().collect(),
- ))),
+ ))?),
None,
)?;
let parsed_map: IndexMap<String, PhpMixed> = match parsed {
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index 015a278e..c15c6e12 100644
--- a/crates/shirabe/src/repository/composer_repository.rs
+++ b/crates/shirabe/src/repository/composer_repository.rs
@@ -2874,7 +2874,7 @@ impl ComposerRepository {
.map(|(k, v)| (k.clone(), v.clone()))
.collect(),
);
- json = JsonFile::encode_with_options(&as_mixed, JsonEncodeOptions::none());
+ json = JsonFile::encode_with_options(&as_mixed, JsonEncodeOptions::none())?;
}
self.cache.borrow_mut().write(ck, &json);
}
@@ -3054,7 +3054,7 @@ impl ComposerRepository {
data.insert("last-modified".to_string(), PhpMixed::String(lmd.clone()));
let as_mixed =
PhpMixed::Array(data.iter().map(|(k, v)| (k.clone(), v.clone())).collect());
- json = JsonFile::encode_with_options(&as_mixed, JsonEncodeOptions::none());
+ json = JsonFile::encode_with_options(&as_mixed, JsonEncodeOptions::none())?;
}
if !self.cache.borrow().is_read_only() {
self.cache.borrow_mut().write(cache_key, &json);
@@ -3229,7 +3229,7 @@ impl ComposerRepository {
pretty_print: false,
..Default::default()
},
- );
+ )?;
}
if !self.cache.borrow().is_read_only() {
self.cache.borrow_mut().write(cache_key, &json);
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
index 49d0dcf1..0719701f 100644
--- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs
+++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs
@@ -364,7 +364,7 @@ impl ForgejoDriver {
pretty_print: false,
..Default::default()
},
- );
+ )?;
self.inner
.cache
.as_mut()
diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
index 95d29938..394077e9 100644
--- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
+++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs
@@ -281,7 +281,7 @@ impl GitBitbucketDriver {
pretty_print: false,
..Default::default()
},
- ),
+ )?,
)?;
}
}
diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs
index c7fe5266..8134a16b 100644
--- a/crates/shirabe/src/repository/vcs/github_driver.rs
+++ b/crates/shirabe/src/repository/vcs/github_driver.rs
@@ -303,7 +303,7 @@ impl GitHubDriver {
pretty_print: false,
..Default::default()
},
- ),
+ )?,
)
});
}
diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
index 8d100755..9a4c22a1 100644
--- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs
+++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs
@@ -298,7 +298,7 @@ impl GitLabDriver {
pretty_print: false,
..Default::default()
},
- ),
+ )?,
)
});
}
diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs
index 3c233db8..716b1943 100644
--- a/crates/shirabe/src/repository/vcs/svn_driver.rs
+++ b/crates/shirabe/src/repository/vcs/svn_driver.rs
@@ -227,7 +227,7 @@ impl SvnDriver {
pretty_print: false,
..Default::default()
},
- );
+ )?;
self.inner
.cache
.as_mut()
diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs
index 5aa74959..3321201c 100644
--- a/crates/shirabe/src/repository/vcs/vcs_driver.rs
+++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs
@@ -171,7 +171,7 @@ impl VcsDriverBase {
pretty_print: false,
..Default::default()
},
- );
+ )?;
self.cache.as_mut().map(|c| c.write(identifier, &encoded));
}
self.info_cache.insert(identifier.to_string(), composer);
@@ -237,7 +237,7 @@ pub trait VcsDriver: VcsDriverInterface {
pretty_print: false,
..Default::default()
},
- );
+ )?;
self.cache_mut().map(|c| c.write(identifier, &encoded));
}
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"
diff --git a/crates/shirabe/tests/installer_test.rs b/crates/shirabe/tests/installer_test.rs
index b81ec7a4..d0b60ba8 100644
--- a/crates/shirabe/tests/installer_test.rs
+++ b/crates/shirabe/tests/installer_test.rs
@@ -707,7 +707,8 @@ fn load_integration_tests(path: &str) -> Vec<IntegrationCase> {
let encoded = JsonFile::encode_with_options(
&composer,
shirabe::json::JsonEncodeOptions::none(),
- );
+ )
+ .unwrap();
let hash = format!("{:x}", md5::compute(encoded.as_bytes()));
lock["hash"] = serde_json::Value::String(hash);
}
@@ -926,7 +927,8 @@ fn do_test_integration(case: &IntegrationCase, expect_output: Option<&str>) {
// escaped), or the freshness check spuriously fails on any composer.json containing "/"
// (e.g. any vendor/package name).
let contents =
- JsonFile::encode_with_options(&case.composer, shirabe::json::JsonEncodeOptions::none());
+ JsonFile::encode_with_options(&case.composer, shirabe::json::JsonEncodeOptions::none())
+ .unwrap();
let locker = Locker::new(io.clone(), lock_json, locker_im, &contents, process);
composer
.borrow_mut()
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<JsonEncodeOptions>) {
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<String, PhpMixed> = 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();
diff --git a/crates/shirabe/tests/json/json_manipulator_test.rs b/crates/shirabe/tests/json/json_manipulator_test.rs
index 00fa7c24..8e418e2d 100644
--- a/crates/shirabe/tests/json/json_manipulator_test.rs
+++ b/crates/shirabe/tests/json/json_manipulator_test.rs
@@ -4128,7 +4128,7 @@ fn test_remove_main_key_removes_key_where_value_is_null() {
manipulator.remove_main_key("bar").unwrap();
- let expected = JsonFile::encode(&arr(&[("foo", PhpMixed::Int(9000))]));
+ let expected = JsonFile::encode(&arr(&[("foo", PhpMixed::Int(9000))])).unwrap();
assert_eq!(
JsonFile::parse_json(Some(&expected), None).unwrap(),
diff --git a/crates/shirabe/tests/package/locker_test.rs b/crates/shirabe/tests/package/locker_test.rs
index c355c774..f1747166 100644
--- a/crates/shirabe/tests/package/locker_test.rs
+++ b/crates/shirabe/tests/package/locker_test.rs
@@ -17,7 +17,7 @@ fn null_io() -> std::rc::Rc<std::cell::RefCell<dyn IOInterface>> {
std::rc::Rc::new(std::cell::RefCell::new(NullIO::new()))
}
-/// ref: LockerTest::getJsonContent — `JsonFile::encode(ksort([minimum-stability, name]), 0)`.
+/// ref: LockerTest::getJsonContent — `JsonFile::encode(ksort([minimum-stability, name]), 0).unwrap()`.
fn get_json_content(custom_data: &[(&str, &str)]) -> String {
let mut data: IndexMap<String, PhpMixed> = IndexMap::new();
data.insert(
@@ -30,7 +30,7 @@ fn get_json_content(custom_data: &[(&str, &str)]) -> String {
}
data.sort_keys();
- JsonFile::encode_with_options(&PhpMixed::Array(data), JsonEncodeOptions::none())
+ JsonFile::encode_with_options(&PhpMixed::Array(data), JsonEncodeOptions::none()).unwrap()
}
/// Builds a `Locker` backed by a real `composer.lock` `JsonFile` inside a fresh temp dir,
@@ -246,7 +246,8 @@ fn test_is_fresh_false() {
m
}),
JsonEncodeOptions::none(),
- );
+ )
+ .unwrap();
let (mut locker, _temp_dir, _io) = make_locker(&json_content, Some(&lock));
assert!(!locker.is_fresh().unwrap());
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<String, PhpMixed> {
}
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<SetUp> {
// 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<SetUp> {
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<SetUp> {
// 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"]);