diff --git a/src/bin/client-demo.rs b/src/bin/client-demo.rs index 50b2dd064029f3..1482c17df2c8a0 100644 --- a/src/bin/client-demo.rs +++ b/src/bin/client-demo.rs @@ -43,7 +43,10 @@ fn main() { if matches.opt_present("t") { threads = matches.opt_str("t").unwrap().parse().expect("integer"); } - let mint: Mint = serde_json::from_reader(stdin()).unwrap(); + let mint: Mint = serde_json::from_reader(stdin()).unwrap_or_else(|e| { + eprintln!("failed to parse json: {}", e); + exit(1); + }); let mint_keypair = mint.keypair(); let mint_pubkey = mint.pubkey(); diff --git a/src/bin/genesis-demo.rs b/src/bin/genesis-demo.rs index bcf26bc0e0aea9..ff983d9a10b742 100644 --- a/src/bin/genesis-demo.rs +++ b/src/bin/genesis-demo.rs @@ -8,13 +8,17 @@ use solana::mint::Mint; use solana::signature::{KeyPair, KeyPairUtil, PublicKey}; use solana::transaction::Transaction; use std::io::stdin; +use std::process::exit; fn transfer(from: &KeyPair, (to, tokens): (PublicKey, i64), last_id: Hash) -> Event { Event::Transaction(Transaction::new(from, to, tokens, last_id)) } fn main() { - let mint: Mint = serde_json::from_reader(stdin()).unwrap(); + let mint: Mint = serde_json::from_reader(stdin()).unwrap_or_else(|e| { + eprintln!("failed to parse json: {}", e); + exit(1); + }); let mut entries = mint.create_entries(); let from = mint.keypair(); @@ -25,6 +29,10 @@ fn main() { entries.push(create_entry(&seed, 0, events)); for entry in entries { - println!("{}", serde_json::to_string(&entry).unwrap()); + let serialized = serde_json::to_string(&entry).unwrap_or_else(|e| { + eprintln!("failed to serialize: {}", e); + exit(1); + }); + println!("{}", serialized); } } diff --git a/src/bin/genesis.rs b/src/bin/genesis.rs index 66d2357b542250..10a1437d738a79 100644 --- a/src/bin/genesis.rs +++ b/src/bin/genesis.rs @@ -5,10 +5,18 @@ extern crate solana; use solana::mint::Mint; use std::io::stdin; +use std::process::exit; fn main() { - let mint: Mint = serde_json::from_reader(stdin()).unwrap(); + let mint: Mint = serde_json::from_reader(stdin()).unwrap_or_else(|e| { + eprintln!("failed to parse json: {}", e); + exit(1); + }); for x in mint.create_entries() { - println!("{}", serde_json::to_string(&x).unwrap()); + let serialized = serde_json::to_string(&x).unwrap_or_else(|e| { + eprintln!("failed to serialize: {}", e); + exit(1); + }); + println!("{}", serialized); } } diff --git a/src/bin/mint.rs b/src/bin/mint.rs index 880257af7fd514..9dab5bc76fe5ce 100644 --- a/src/bin/mint.rs +++ b/src/bin/mint.rs @@ -3,6 +3,7 @@ extern crate solana; use solana::mint::Mint; use std::io; +use std::process::exit; fn main() { let mut input_text = String::new(); @@ -11,5 +12,9 @@ fn main() { let tokens = trimmed.parse::().unwrap(); let mint = Mint::new(tokens); - println!("{}", serde_json::to_string(&mint).unwrap()); + let serialized = serde_json::to_string(&mint).unwrap_or_else(|e| { + eprintln!("failed to serialize: {}", e); + exit(1); + }); + println!("{}", serialized); } diff --git a/src/bin/testnode.rs b/src/bin/testnode.rs index 068a4c839ba53f..a8587e3ed7de71 100644 --- a/src/bin/testnode.rs +++ b/src/bin/testnode.rs @@ -33,10 +33,12 @@ fn main() { } let addr = format!("0.0.0.0:{}", port); let stdin = io::stdin(); - let mut entries = stdin - .lock() - .lines() - .map(|line| serde_json::from_str(&line.unwrap()).unwrap()); + let mut entries = stdin.lock().lines().map(|line| { + serde_json::from_str(&line.unwrap()).unwrap_or_else(|e| { + eprintln!("failed to parse json: {}", e); + exit(1); + }) + }); // The first item in the ledger is required to be an entry with zero num_hashes, // which implies its id can be used as the ledger's seed.