openethereum/parity/die.rs

62 lines
1.9 KiB
Rust
Raw Normal View History

2016-04-21 13:12:43 +02:00
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std;
use ethcore;
2016-05-18 11:44:55 +02:00
use ethcore::client::Error as ClientError;
2016-04-21 13:12:43 +02:00
use util::UtilError;
use std::process::exit;
#[macro_export]
macro_rules! die {
2016-07-05 19:21:18 +02:00
($($arg:tt)*) => (::die::die_with_message(&format!("{}", format_args!($($arg)*))));
2016-04-21 13:12:43 +02:00
}
pub fn die_with_error(module: &'static str, e: ethcore::error::Error) -> ! {
2016-04-21 13:12:43 +02:00
use ethcore::error::Error;
match e {
Error::Util(UtilError::StdIo(e)) => die_with_io_error(module, e),
2016-05-18 11:44:55 +02:00
Error::Client(ClientError::Trace(e)) => die_with_message(&format!("{}", e)),
_ => {
trace!(target: module, "{:?}", e);
die!("{}: {}", module, e);
}
2016-04-21 13:12:43 +02:00
}
}
pub fn die_with_io_error(module: &'static str, e: std::io::Error) -> ! {
2016-05-22 18:48:40 +02:00
trace!(target: module, "{:?}", e);
2016-04-21 13:12:43 +02:00
match e.kind() {
std::io::ErrorKind::PermissionDenied => {
die!("{}: No permissions to bind to specified port.", module)
2016-04-21 13:12:43 +02:00
},
std::io::ErrorKind::AddrInUse => {
die!("{}: Specified address is already in use. Please make sure that nothing is listening on the same port or try using a different one.", module)
2016-04-21 13:12:43 +02:00
},
std::io::ErrorKind::AddrNotAvailable => {
die!("{}: Could not use specified interface or given address is invalid.", module)
2016-04-21 13:12:43 +02:00
},
_ => die!("{}: {}", module, e),
2016-04-21 13:12:43 +02:00
}
}
pub fn die_with_message(msg: &str) -> ! {
println!("ERROR: {}", msg);
exit(1);
}