Skip to content

Commit 5c06e69

Browse files
committed
fix(cli): preserve decoded wire error identity
1 parent 27ccb28 commit 5c06e69

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎src/cli.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ pub fn run_with_args(
358358
fn load_ordinary_cli_program(
359359
source_path: &Path,
360360
options: CompileSourceFileOptions,
361-
) -> Result<Program, io::Error> {
361+
) -> Result<Program, Box<dyn std::error::Error>> {
362362
if source_path.extension().is_some_and(|ext| ext == "vmbc") {
363-
crate::decode_program(&std::fs::read(source_path)?).map_err(io::Error::other)
363+
Ok(crate::decode_program(&std::fs::read(source_path)?)?)
364364
} else {
365365
let compiled = compile_source_file_with_options(source_path, options)
366366
.map_err(|err| io::Error::other(render_source_path_error(source_path, &err)))?;

‎src/cli_capture_certification_tests.rs‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,41 @@ fn opted_in_epoch_configuration_and_interrupt_conflict_keep_legacy_rules() {
510510
assert_eq!(observations.lock().unwrap().calls, 1);
511511
}
512512

513+
#[test]
514+
fn malformed_vmbc_keeps_wire_error_type_in_all_ordinary_cli_routes() {
515+
let scratch = Scratch::new();
516+
let path = scratch.0.join("malformed.vmbc");
517+
std::fs::write(&path, b"invalid VMBC bytes").unwrap();
518+
let expected = crate::decode_program(&std::fs::read(&path).unwrap())
519+
.unwrap_err()
520+
.to_string();
521+
for selected in [
522+
CliHostServices::default(),
523+
CliHostServices::default().with_capture_certification(),
524+
services(Arc::new(Mutex::new(Observations::default()))),
525+
services(Arc::new(Mutex::new(Observations::default()))).with_capture_certification(),
526+
] {
527+
for emit in [false, true] {
528+
let mut args = Vec::new();
529+
if emit {
530+
args.extend([
531+
"--emit-vmbc".to_owned(),
532+
scratch.0.join("rejected.vmbc").display().to_string(),
533+
]);
534+
}
535+
args.push(path.display().to_string());
536+
let error = run_with_args(&CliRuntime::default(), &args, &selected).unwrap_err();
537+
assert_eq!(error.to_string(), expected);
538+
assert!(
539+
error.downcast_ref::<crate::WireError>().is_some(),
540+
"WireError was wrapped: {error:?}"
541+
);
542+
assert!(error.downcast_ref::<io::Error>().is_none());
543+
assert!(!scratch.0.join("rejected.vmbc").exists());
544+
}
545+
}
546+
}
547+
513548
#[test]
514549
fn default_services_remain_uncertified_with_actual_owner_candidate() {
515550
let scratch = Scratch::new();

0 commit comments

Comments
 (0)