Skip to content

Commit

Permalink
report parse errors to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
rleungx committed Apr 19, 2018
1 parent 903374a commit b687150
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/bin/client-demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use solana::mint::Mint;
use solana::signature::{KeyPair, KeyPairUtil};
use solana::transaction::Transaction;
use std::env;
use std::io::stdin;
use std::io::{stderr, stdin, Write};
use std::net::UdpSocket;
use std::process::exit;
use std::thread::sleep;
use std::time::{Duration, Instant};

Expand All @@ -27,7 +28,10 @@ fn main() {
let args: Vec<String> = env::args().collect();
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!(f.to_string()),
Err(e) => {
writeln!(stderr(), "{}", e).unwrap();

This comment has been minimized.

Copy link
@garious

garious Apr 19, 2018

Contributor

Can you use eprintln! instead?

This comment has been minimized.

Copy link
@rleungx

rleungx Apr 19, 2018

Author Contributor

Sure.

exit(1);
}
};

if matches.opt_present("s") {
Expand Down
8 changes: 6 additions & 2 deletions src/bin/testnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use solana::entry::Entry;
use solana::event::Event;
use solana::historian::Historian;
use std::env;
use std::io::{self, stdout, BufRead};
use std::io::{self, stderr, stdout, BufRead, Write};
use std::process::exit;
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex};

Expand All @@ -22,7 +23,10 @@ fn main() {
let args: Vec<String> = env::args().collect();
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => panic!(f.to_string()),
Err(e) => {
writeln!(stderr(), "{}", e).unwrap();
exit(1);
}
};
if matches.opt_present("p") {
port = matches.opt_str("p").unwrap().parse().expect("port");
Expand Down

1 comment on commit b687150

@garious
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent of that issue was to report the serde parse errors from stdin, not the command-line parse errors. For example, try passing a non-number to solana-mint, or bogus data to solana-genesis, solana-testnode, or solana-client-demo. You should see an obscure unwrap() panic instead of a nice serde error message.

Please sign in to comment.