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:
@ -82,7 +82,7 @@ impl MirInterpreter {
|
||||
// Only supported on C-API route; expect 1 or 2 args: obj_path [, exe_out]
|
||||
let obj_path = match args.get(0) {
|
||||
Some(v) => match self.reg_load(*v) { Ok(v) => v.to_string(), Err(e) => return Some(Err(e)) },
|
||||
None => return Some(Err(VMError::InvalidInstruction("env.codegen.link_object expects 1+ args".into()))),
|
||||
None => return Some(Err(self.err_invalid("env.codegen.link_object expects 1+ args"))),
|
||||
};
|
||||
let exe_out = match args.get(1) {
|
||||
Some(v) => Some(match self.reg_load(*v) { Ok(v) => v.to_string(), Err(e) => return Some(Err(e)) }),
|
||||
@ -114,9 +114,7 @@ impl MirInterpreter {
|
||||
eprintln!("[hb:entry:provider] hostbridge.extern_invoke");
|
||||
}
|
||||
if args.len() < 2 {
|
||||
return Some(Err(VMError::InvalidInstruction(
|
||||
"extern_invoke expects at least 2 args".into(),
|
||||
)));
|
||||
return Some(Err(self.err_invalid("extern_invoke expects at least 2 args")));
|
||||
}
|
||||
let name = match self.reg_load(args[0]) { Ok(v) => v.to_string(), Err(e) => return Some(Err(e)) };
|
||||
let method = match self.reg_load(args[1]) { Ok(v) => v.to_string(), Err(e) => return Some(Err(e)) };
|
||||
@ -186,7 +184,7 @@ impl MirInterpreter {
|
||||
_ => (v.to_string(), None),
|
||||
}
|
||||
} else {
|
||||
return Some(Err(VMError::InvalidInstruction("extern_invoke env.codegen.link_object expects args array".into())));
|
||||
return Some(Err(self.err_invalid("extern_invoke env.codegen.link_object expects args array")));
|
||||
};
|
||||
if std::env::var("NYASH_LLVM_USE_CAPI").ok().as_deref() != Some("1") ||
|
||||
std::env::var("HAKO_V1_EXTERN_PROVIDER_C_ABI").ok().as_deref() != Some("1") {
|
||||
@ -204,15 +202,10 @@ impl MirInterpreter {
|
||||
if let Some(s) = first_arg_str {
|
||||
match crate::host_providers::mir_builder::program_json_to_mir_json(&s) {
|
||||
Ok(out) => Ok(VMValue::String(Self::patch_mir_json_version(&out))),
|
||||
Err(e) => Err(VMError::InvalidInstruction(format!(
|
||||
"env.mirbuilder.emit: {}",
|
||||
e
|
||||
))),
|
||||
Err(e) => Err(self.err_with_context("env.mirbuilder.emit", &e.to_string())),
|
||||
}
|
||||
} else {
|
||||
Err(VMError::InvalidInstruction(
|
||||
"extern_invoke env.mirbuilder.emit expects 1 arg".into(),
|
||||
))
|
||||
Err(self.err_invalid("extern_invoke env.mirbuilder.emit expects 1 arg"))
|
||||
}
|
||||
}
|
||||
("env.codegen", "emit_object") => {
|
||||
@ -225,15 +218,10 @@ impl MirInterpreter {
|
||||
};
|
||||
match crate::host_providers::llvm_codegen::mir_json_to_object(&s, opts) {
|
||||
Ok(p) => Ok(VMValue::String(p.to_string_lossy().into_owned())),
|
||||
Err(e) => Err(VMError::InvalidInstruction(format!(
|
||||
"env.codegen.emit_object: {}",
|
||||
e
|
||||
))),
|
||||
Err(e) => Err(self.err_with_context("env.codegen.emit_object", &e.to_string())),
|
||||
}
|
||||
} else {
|
||||
Err(VMError::InvalidInstruction(
|
||||
"extern_invoke env.codegen.emit_object expects 1 arg".into(),
|
||||
))
|
||||
Err(self.err_invalid("extern_invoke env.codegen.emit_object expects 1 arg"))
|
||||
}
|
||||
}
|
||||
("env.codegen", "link_object") => {
|
||||
@ -267,7 +255,7 @@ impl MirInterpreter {
|
||||
}
|
||||
let objs = match obj_s {
|
||||
Some(s) => s,
|
||||
None => return Some(Err(VMError::InvalidInstruction("extern_invoke env.codegen.link_object expects args".into()))),
|
||||
None => return Some(Err(self.err_invalid("extern_invoke env.codegen.link_object expects args"))),
|
||||
};
|
||||
if std::env::var("NYASH_LLVM_USE_CAPI").ok().as_deref() != Some("1") ||
|
||||
std::env::var("HAKO_V1_EXTERN_PROVIDER_C_ABI").ok().as_deref() != Some("1") {
|
||||
@ -285,7 +273,7 @@ impl MirInterpreter {
|
||||
if std::env::var("HAKO_CABI_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!("[hb:unsupported:provider] {}.{}", name, method);
|
||||
}
|
||||
Err(VMError::InvalidInstruction(format!(
|
||||
Err(self.err_invalid(format!(
|
||||
"hostbridge.extern_invoke unsupported for {}.{} [provider]",
|
||||
name, method
|
||||
)))
|
||||
|
||||
Reference in New Issue
Block a user