panic hook
This commit is contained in:
parent
7fdc97b619
commit
65f375dd97
|
@ -40,6 +40,12 @@ version = "0.3.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.10"
|
||||
|
@ -56,6 +62,7 @@ name = "kabel"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"hex",
|
||||
"is-terminal",
|
||||
"libkabel",
|
||||
"tracing-subscriber",
|
||||
|
|
|
@ -12,3 +12,4 @@ libkabel = { version = "0.1", path = "../libkabel", features = ["pretty-emitter"
|
|||
is-terminal = "0.4"
|
||||
tracing-subscriber = "0.3"
|
||||
colored = "2"
|
||||
hex = "0.4"
|
|
@ -7,8 +7,27 @@ use libkabel::source::SourceFile;
|
|||
use std::error::Error;
|
||||
use std::io;
|
||||
use std::{env, fs};
|
||||
use std::fmt::Write;
|
||||
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
std::panic::set_hook(Box::new(|i| {
|
||||
eprintln!("{}", "----- Kabel has crashed! -----".red());
|
||||
eprintln!("{} {} {}", "--".red(), "THIS IS NOT YOUR FAULT".bold().red(), "--".red());
|
||||
eprintln!("{}", "Please report the following Error ID to the Kabel developers, along with your program's complete source code.".red());
|
||||
|
||||
let mut panic_info = String::new();
|
||||
write!(panic_info, "{i}").unwrap();
|
||||
let error_id = hex::encode(panic_info);
|
||||
|
||||
eprintln!("{}{}", "Error ID: ".red(), error_id.italic().red());
|
||||
eprintln!("{}", "Please, either:".red());
|
||||
eprintln!("{}", "- Open an issue at https://git.e3t.cc/tm85/kabel, or".red());
|
||||
eprintln!("{}", "- E-Mail the developers at kabel@e3t.cc".red());
|
||||
eprintln!("{} {} {}", "-- Remember:".red(), "THIS IS NOT YOUR FAULT".bold().red(), "--".red());
|
||||
eprintln!("{}", "----- Kabel has crashed! -----".red());
|
||||
}));
|
||||
|
||||
let argv: Vec<String> = env::args().collect();
|
||||
if argv.len() != 2 {
|
||||
println!("Usage: {} <file.kab>", &argv[0]);
|
||||
|
@ -49,7 +68,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
"error: Please report this error to the kabel developers along with your"
|
||||
.red()
|
||||
);
|
||||
eprintln!("{}", "fail: program's complete source code. Either");
|
||||
eprintln!("{}", "fail: program's complete source code. Either".red());
|
||||
eprintln!(
|
||||
"{}",
|
||||
"fail: - Open an Issue at https://git.e3t.cc/tm85/kabel, or".red()
|
||||
|
|
|
@ -46,7 +46,7 @@ impl Display for TokenType {
|
|||
TokenType::Minus => write!(f, "-"),
|
||||
TokenType::Plus => write!(f, "+"),
|
||||
TokenType::Star => write!(f, "*"),
|
||||
TokenType::Semicolon => write!(f, ";\n"),
|
||||
TokenType::Semicolon => writeln!(f, ";"),
|
||||
TokenType::To => write!(f, "to"),
|
||||
TokenType::Identifier(i) => write!(f, "{i}"),
|
||||
TokenType::Colon => write!(f, ":"),
|
||||
|
|
Loading…
Reference in New Issue