aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-03 22:24:51 +0900
committernsfisis <nsfisis@gmail.com>2026-06-03 22:24:51 +0900
commiteba99f7e5f38d9501b37d9b188b6f324a947dc74 (patch)
tree27c893a33e6176acfe569d6175b13364783a7b95 /crates
parent27764ef4447a02e5c59bbcc7b4547838aae82d89 (diff)
downloadphp-shirabe-eba99f7e5f38d9501b37d9b188b6f324a947dc74.tar.gz
php-shirabe-eba99f7e5f38d9501b37d9b188b6f324a947dc74.tar.zst
php-shirabe-eba99f7e5f38d9501b37d9b188b6f324a947dc74.zip
fix(config,loader): wire JsonValidationException catch; drop unportable chain TODOs
JsonConfigSource::manipulate_json now downcasts the validate_schema error to JsonValidationException (matching PHP's specific catch), restores the original contents, and surfaces e.get_errors(); other errors propagate. ArrayLoader's two version-parse catch sites only had TODOs for preserving the original exception as 'previous'. shirabe_semver raises generic anyhow errors (not shim exception types), so the existing catch-all is already faithful to PHP's catch (\UnexpectedValueException), and the flat shim exception structs intentionally hold no previous field; the wrapped message already carries the original cause. Remove the stale TODOs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe/src/config/json_config_source.rs8
-rw-r--r--crates/shirabe/src/package/loader/array_loader.rs5
2 files changed, 5 insertions, 8 deletions
diff --git a/crates/shirabe/src/config/json_config_source.rs b/crates/shirabe/src/config/json_config_source.rs
index 7b5fc03..28481db 100644
--- a/crates/shirabe/src/config/json_config_source.rs
+++ b/crates/shirabe/src/config/json_config_source.rs
@@ -207,19 +207,19 @@ impl JsonConfigSource {
)?;
}
- // TODO(phase-b): use anyhow::Result<Result<T, E>> to model PHP try/catch
match self.file.validate_schema(JsonFile::LAX_SCHEMA, None) {
Ok(_) => {}
Err(e) => {
- // TODO(phase-b): downcast e to JsonValidationException to match the specific catch
- let _jve: &JsonValidationException = todo!("downcast e to JsonValidationException");
+ let Some(jve) = e.downcast_ref::<JsonValidationException>() else {
+ return Err(e);
+ };
// restore contents to the original state
file_put_contents(self.file.get_path(), contents.as_bytes());
return Err(RuntimeException {
message: format!(
"Failed to update composer.json with a valid format, reverting to the original content. Please report an issue to us with details (command you run and a copy of your composer.json). {}{}",
PHP_EOL,
- implode(PHP_EOL, todo!("e.get_errors()")),
+ implode(PHP_EOL, jve.get_errors()),
),
code: 0,
}
diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs
index e1cc60b..634bef8 100644
--- a/crates/shirabe/src/package/loader/array_loader.rs
+++ b/crates/shirabe/src/package/loader/array_loader.rs
@@ -195,7 +195,6 @@ impl ArrayLoader {
{
Ok(v) => version = v,
Err(e) => {
- // TODO(phase-b): preserve original exception chain via anyhow::Error::context
return Err(UnexpectedValueException {
message: format!(
"Failed to normalize version for package \"{}\": {}",
@@ -761,9 +760,7 @@ impl ArrayLoader {
let parsed_constraint = match self.version_parser.parse_constraints(&constraint) {
Ok(c) => c,
- Err(e) => {
- // TODO(phase-b): preserve original exception chain
- let _ = &e;
+ Err(_e) => {
return Err(UnexpectedValueException {
message: format!(
"Link constraint in {} {} > {} should be a valid version constraint, got \"{}\"",