Skip to content

Commit

Permalink
Merge pull request #136 from rleungx/report-errors-to-stderr
Browse files Browse the repository at this point in the history
report serde parse errors to stderr
  • Loading branch information
garious authored Apr 19, 2018
2 parents 43e6741 + 60015ae commit ca877e6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/bin/client-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 10 additions & 2 deletions src/bin/genesis-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
12 changes: 10 additions & 2 deletions src/bin/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 6 additions & 1 deletion src/bin/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -11,5 +12,9 @@ fn main() {
let tokens = trimmed.parse::<i64>().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);
}
10 changes: 6 additions & 4 deletions src/bin/testnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ca877e6

Please sign in to comment.