Skip to content

Commit 677bde6

Browse files
committed
Auto merge of #834 - jyn514:master, r=RalfJung
Give a useful error message if user gives invalid random seed I thought this crash was in my code at first because the error was so vague.
2 parents 3655480 + ebf65cb commit 677bde6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/bin/miri.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ extern crate syntax;
1717
use std::str::FromStr;
1818
use std::env;
1919

20+
use hex::FromHexError;
21+
2022
use rustc_interface::interface;
2123
use rustc::hir::def_id::LOCAL_CRATE;
2224

@@ -153,7 +155,14 @@ fn main() {
153155
if seed.is_some() {
154156
panic!("Cannot specify -Zmiri-seed multiple times!");
155157
}
156-
let seed_raw = hex::decode(arg.trim_start_matches("-Zmiri-seed=")).unwrap();
158+
let seed_raw = hex::decode(arg.trim_start_matches("-Zmiri-seed="))
159+
.unwrap_or_else(|err| match err {
160+
FromHexError::InvalidHexCharacter { .. } => panic!(
161+
"-Zmiri-seed should only contain valid hex digits [0-9a-fA-F]"
162+
),
163+
FromHexError::OddLength => panic!("-Zmiri-seed should have an even number of digits"),
164+
err => panic!("Unknown error decoding -Zmiri-seed as hex: {:?}", err),
165+
});
157166
if seed_raw.len() > 8 {
158167
panic!(format!("-Zmiri-seed must be at most 8 bytes, was {}", seed_raw.len()));
159168
}

0 commit comments

Comments
 (0)