refactor: complete error message unification (Phase 3.5)

Migrate remaining 45 error generation patterns to unified helpers:
- calls.rs: 13 sites → 0
- extern_provider.rs: 9 sites → 0
- externals.rs: 5 sites → 0
- boxes_plugin.rs: 5 sites → 0
- boxes.rs: 5 sites → 0
- boxes_string.rs: 4 sites → 0
- boxes_instance.rs: 2 sites → 0
- mod.rs + boxes_array.rs: 2 sites → 0

Error patterns now 100% unified:
- All 80 InvalidInstruction sites use helpers (100%)
- Consistent error formatting across entire codebase
- Single source of truth for error messages

Code reduction:
- Phase 3.5: 50-70 lines saved
- Cumulative (Phase 1+2+3+3.5): 200-267 lines removed (6-8% handlers)
- Total patterns unified: 192 (destination 60 + args 52 + errors 80)

Benefits:
- 100% error message consistency achieved
- Easy to modify error formats globally
- Foundation for i18n support ready
- Improved maintainability and testability

Test results: ✓ Build successful, Phase 21.0 smoke tests passing
Related: Phase 21.0 refactoring milestone complete
Risk: Low (error messages only, behavior preserved)
This commit is contained in:
nyash-codex
2025-11-06 23:34:46 +09:00
parent 0287020a5b
commit 22b668927e
9 changed files with 56 additions and 111 deletions

View File

@ -60,10 +60,10 @@ pub(super) fn invoke_plugin_box(
}
Ok(())
}
Err(e) => Err(VMError::InvalidInstruction(format!(
"BoxCall {}.{} failed: {:?}",
p.box_type, method, e
))),
Err(e) => Err(this.err_with_context(
&format!("BoxCall {}.{}", p.box_type, method),
&format!("{:?}", e)
)),
}
} else if let Some(string_box) = recv_box
.as_any()
@ -80,9 +80,7 @@ pub(super) fn invoke_plugin_box(
}
Ok(())
} else {
Err(VMError::InvalidInstruction(
"lastIndexOf requires 1 argument".into(),
))
Err(this.err_invalid("lastIndexOf requires 1 argument"))
}
}
"indexOf" | "find" => {
@ -94,15 +92,10 @@ pub(super) fn invoke_plugin_box(
}
Ok(())
} else {
Err(VMError::InvalidInstruction(
"indexOf/find requires 1 argument".into(),
))
Err(this.err_invalid("indexOf/find requires 1 argument"))
}
}
_ => Err(VMError::InvalidInstruction(format!(
"BoxCall method {} not supported on StringBox",
method
))),
_ => Err(this.err_method_not_found("StringBox", method)),
}
} else {
// Special-case: minimal runtime fallback for common InstanceBox methods when
@ -209,10 +202,6 @@ pub(super) fn invoke_plugin_box(
_ => {}
}
}
Err(VMError::InvalidInstruction(format!(
"BoxCall unsupported on {}.{}",
recv_box.type_name(),
method
)))
Err(this.err_method_not_found(&recv_box.type_name(), method))
}
}