From 338e365be528143fb1f9691e01b7a15f61c6580f Mon Sep 17 00:00:00 2001 From: Edwin Sutanto Date: Sun, 17 Apr 2022 20:40:36 +0700 Subject: [PATCH 1/2] fix: Improved message if error occurred during FORMAT parsing in vcf-to-txt The tag name in FORMAT field that causes panic is now printed. --- src/bcf/to_txt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bcf/to_txt.rs b/src/bcf/to_txt.rs index 21996e8d..571ab456 100644 --- a/src/bcf/to_txt.rs +++ b/src/bcf/to_txt.rs @@ -198,7 +198,7 @@ pub fn to_txt(info_tags: &[&str], format_tags: &[&str], show_genotypes: bool) -> match tag_type { bcf::header::TagType::Flag => { - panic!("there is no flag type for format"); + panic!("Unable to find FORMAT \"{}\" in the input file!", name); } bcf::header::TagType::Integer => { writer.write_field( From b3d1854386ee3e72079f4c869f325e41ed58d03b Mon Sep 17 00:00:00 2001 From: Edwin Sutanto Date: Mon, 18 Apr 2022 09:13:50 +0700 Subject: [PATCH 2/2] Change the error message to the cause of error --- src/bcf/to_txt.rs | 2 +- tests/lib.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/bcf/to_txt.rs b/src/bcf/to_txt.rs index 571ab456..241a4f64 100644 --- a/src/bcf/to_txt.rs +++ b/src/bcf/to_txt.rs @@ -198,7 +198,7 @@ pub fn to_txt(info_tags: &[&str], format_tags: &[&str], show_genotypes: bool) -> match tag_type { bcf::header::TagType::Flag => { - panic!("Unable to find FORMAT \"{}\" in the input file!", name); + panic!("Unable to find FORMAT \"{0}\" in the input file! Is \"{0}\" an INFO tag?", name); } bcf::header::TagType::Integer => { writer.write_field( diff --git a/tests/lib.rs b/tests/lib.rs index c70e9e09..f3f64f9c 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -108,6 +108,21 @@ fn vcf_to_txt() { ); } +#[test] +// FIXME: can't work out how to use should_panic macro +//#[should_panic] +fn vcf_to_txt_input_info_as_format() { + assert!(String::from_utf8_lossy( + &Command::new("bash") + .arg("-c") + .arg("target/debug/rbt vcf-to-txt --fmt T < tests/test.vcf") + .output() + .unwrap() + .stderr + ) + .contains("'Unable to find FORMAT \"T\" in the input file! Is \"T\" an INFO tag?'")); +} + #[test] fn vcf_match() { assert!(Command::new("bash")