Skip to content

Commit

Permalink
fix: Improved message if error occurred during FORMAT parsing in vcf-…
Browse files Browse the repository at this point in the history
…to-txt (#243)

* 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.

* Change the error message to the cause of error
  • Loading branch information
essut committed Jun 14, 2022
1 parent 9b7ae9a commit 4231371
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bcf/to_txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \"{0}\" in the input file! Is \"{0}\" an INFO tag?", name);
}
bcf::header::TagType::Integer => {
writer.write_field(
Expand Down
15 changes: 15 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4231371

Please sign in to comment.