File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ use config::Config;
1616use log:: info;
1717use simplelog:: CombinedLogger ;
1818use std:: io;
19+ use std:: panic;
1920use std:: path:: PathBuf ;
2021use std:: process:: { self , ExitCode } ;
2122use structopt:: StructOpt ;
@@ -140,6 +141,22 @@ struct Opt {
140141
141142#[ allow( clippy:: too_many_lines) ]
142143fn main ( ) -> Result < ExitCode > {
144+ let version = env ! ( "CARGO_PKG_VERSION" ) ;
145+
146+ // via: https://github.com/astral-sh/ruff/blob/40fd52dde0ddf0b95a3433163f51560b4827ab75/crates/ruff_server/src/server.rs#L140
147+ panic:: set_hook ( Box :: new ( move |panic_info| {
148+ use std:: io:: Write ;
149+ let backtrace = std:: backtrace:: Backtrace :: force_capture ( ) ;
150+ // Don't use `eprintln` because `eprintln` itself may panic if the pipe is broken.
151+ let mut stderr = std:: io:: stderr ( ) . lock ( ) ;
152+ let open_an_issue = format ! (
153+ r#"An internal error has occured with Squawk v{version}!
154+ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the logs above!
155+ "#
156+ ) ;
157+ writeln ! ( stderr, "{panic_info}\n {backtrace}\n {open_an_issue}" ) . ok ( ) ;
158+ } ) ) ;
159+
143160 let opts = Opt :: from_args ( ) ;
144161
145162 if opts. verbose {
You can’t perform that action at this time.
0 commit comments