]> git.lizzy.rs Git - rust.git/commitdiff
Give a useful error message if user gives invalid random seed
authorJoshua Nelson <jyn514@gmail.com>
Sat, 13 Jul 2019 12:28:33 +0000 (08:28 -0400)
committerJoshua Nelson <jyn514@gmail.com>
Sat, 13 Jul 2019 12:28:33 +0000 (08:28 -0400)
src/bin/miri.rs

index 5a425baf0f61fb62ad1aa9127412b8af554ba988..0f28a0c5d8dca915cf88acae40e81aae1d82d1e3 100644 (file)
@@ -17,6 +17,8 @@
 use std::str::FromStr;
 use std::env;
 
+use hex::FromHexError;
+
 use rustc_interface::interface;
 use rustc::hir::def_id::LOCAL_CRATE;
 
@@ -153,7 +155,14 @@ fn main() {
                     if seed.is_some() {
                         panic!("Cannot specify -Zmiri-seed multiple times!");
                     }
-                    let seed_raw = hex::decode(arg.trim_start_matches("-Zmiri-seed=")).unwrap();
+                    let seed_raw = hex::decode(arg.trim_start_matches("-Zmiri-seed="))
+                        .unwrap_or_else(|err| match err {
+                            FromHexError::InvalidHexCharacter { .. } => panic!(
+                                "-Zmiri-seed should only contain valid hex digits [0-9a-fA-F]"
+                            ),
+                            FromHexError::OddLength => panic!("-Zmiri-seed should have an even number of digits"),
+                            err => panic!("Unknown error decoding -Zmiri-seed as hex: {:?}", err),
+                        });
                     if seed_raw.len() > 8 {
                         panic!(format!("-Zmiri-seed must be at most 8 bytes, was {}", seed_raw.len()));
                     }