Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the error messages #144

Merged
merged 1 commit into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ matches = "^0.1.6"
byteorder = "^1.2.1"
libc = "^0.2.1"
getopts = "^0.2"

isatty = "0.1"
19 changes: 17 additions & 2 deletions src/bin/client-demo.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
extern crate getopts;
extern crate isatty;
extern crate rayon;
extern crate serde_json;
extern crate solana;

use getopts::Options;
use isatty::stdin_isatty;
use rayon::prelude::*;
use solana::accountant_stub::AccountantStub;
use solana::mint::Mint;
use solana::signature::{KeyPair, KeyPairUtil};
use solana::transaction::Transaction;
use std::env;
use std::io::stdin;
use std::io::{stdin, Read};
use std::net::UdpSocket;
use std::process::exit;
use std::thread::sleep;
Expand Down Expand Up @@ -58,7 +60,20 @@ 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_or_else(|e| {

if stdin_isatty() {
eprintln!("nothing found on stdin, expected a json file");
exit(1);
}

let mut buffer = String::new();
let num_bytes = stdin().read_to_string(&mut buffer).unwrap();
if num_bytes == 0 {
eprintln!("empty file on stdin, expected a json file");
exit(1);
}

let mint: Mint = serde_json::from_str(&buffer).unwrap_or_else(|e| {
eprintln!("failed to parse json: {}", e);
exit(1);
});
Expand Down
18 changes: 16 additions & 2 deletions src/bin/genesis-demo.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
extern crate isatty;
extern crate serde_json;
extern crate solana;

use isatty::stdin_isatty;
use solana::entry::create_entry;
use solana::event::Event;
use solana::hash::Hash;
use solana::mint::Mint;
use solana::signature::{KeyPair, KeyPairUtil, PublicKey};
use solana::transaction::Transaction;
use std::io::stdin;
use std::io::{stdin, Read};
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_or_else(|e| {
if stdin_isatty() {
eprintln!("nothing found on stdin, expected a json file");
exit(1);
}

let mut buffer = String::new();
let num_bytes = stdin().read_to_string(&mut buffer).unwrap();
if num_bytes == 0 {
eprintln!("empty file on stdin, expected a json file");
exit(1);
}

let mint: Mint = serde_json::from_str(&buffer).unwrap_or_else(|e| {
eprintln!("failed to parse json: {}", e);
exit(1);
});
Expand Down
18 changes: 16 additions & 2 deletions src/bin/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
//! A command-line executable for generating the chain's genesis block.

extern crate isatty;
extern crate serde_json;
extern crate solana;

use isatty::stdin_isatty;
use solana::mint::Mint;
use std::io::stdin;
use std::io::{stdin, Read};
use std::process::exit;

fn main() {
let mint: Mint = serde_json::from_reader(stdin()).unwrap_or_else(|e| {
if stdin_isatty() {
eprintln!("nothing found on stdin, expected a json file");
exit(1);
}

let mut buffer = String::new();
let num_bytes = stdin().read_to_string(&mut buffer).unwrap();
if num_bytes == 0 {
eprintln!("empty file on stdin, expected a json file");
exit(1);
}

let mint: Mint = serde_json::from_str(&buffer).unwrap_or_else(|e| {
eprintln!("failed to parse json: {}", e);
exit(1);
});
Expand Down
13 changes: 11 additions & 2 deletions src/bin/mint.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
extern crate isatty;
extern crate serde_json;
extern crate solana;

use isatty::stdin_isatty;
use solana::mint::Mint;
use std::io;
use std::process::exit;

fn main() {
let mut input_text = String::new();
if stdin_isatty() {
eprintln!("nothing found on stdin, expected a token number");
exit(1);
}

io::stdin().read_line(&mut input_text).unwrap();
let trimmed = input_text.trim();
let tokens = trimmed.parse::<i64>().unwrap();

let tokens = trimmed.parse::<i64>().unwrap_or_else(|e| {
eprintln!("{}", e);
exit(1);
});
let mint = Mint::new(tokens);
let serialized = serde_json::to_string(&mint).unwrap_or_else(|e| {
eprintln!("failed to serialize: {}", e);
Expand Down
22 changes: 18 additions & 4 deletions src/bin/testnode.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
extern crate env_logger;
extern crate getopts;
extern crate isatty;
extern crate serde_json;
extern crate solana;

use getopts::Options;
use isatty::stdin_isatty;
use solana::accountant::Accountant;
use solana::accountant_skel::AccountantSkel;
use solana::entry::Entry;
use solana::event::Event;
use solana::historian::Historian;
use std::env;
use std::io::{self, stdout, BufRead};
use std::io::{stdin, stdout, Read};
use std::process::exit;
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -47,9 +49,21 @@ fn main() {
port = matches.opt_str("p").unwrap().parse().expect("port");
}
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_or_else(|e| {

if stdin_isatty() {
eprintln!("nothing found on stdin, expected a log file");
exit(1);
}

let mut buffer = String::new();
let num_bytes = stdin().read_to_string(&mut buffer).unwrap();
if num_bytes == 0 {
eprintln!("empty file on stdin, expected a log file");
exit(1);
}

let mut entries = buffer.lines().map(|line| {
serde_json::from_str(&line).unwrap_or_else(|e| {
eprintln!("failed to parse json: {}", e);
exit(1);
})
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub mod accountant_skel;
pub mod accountant_stub;
pub mod ecdsa;
pub mod entry;
#[cfg(feature = "erasure")]
pub mod erasure;
pub mod event;
pub mod hash;
pub mod historian;
Expand All @@ -17,8 +19,6 @@ pub mod signature;
pub mod streamer;
pub mod subscribers;
pub mod transaction;
#[cfg(feature = "erasure")]
pub mod erasure;
extern crate bincode;
extern crate byteorder;
extern crate chrono;
Expand Down