Merge pull request #136 from rleungx/report-errors-to-stderr
report serde parse errors to stderr
This commit is contained in:
commit
ca877e689c
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue