-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into refactor/literals-instead-of-constants
- Loading branch information
Showing
41 changed files
with
1,098 additions
and
788 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[attr]generated linguist-generated=true diff=generated | ||
|
||
Cargo.lock generated | ||
reports/*.* generated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#![allow(clippy::unwrap_used)] | ||
use std::{io::Write, panic::PanicInfo}; | ||
use termcolor::{Color, ColorSpec, WriteColor}; | ||
|
||
use std::io::IsTerminal; | ||
|
||
use termcolor::{BufferWriter, ColorChoice}; | ||
|
||
pub fn stderr_buffer_writer() -> BufferWriter { | ||
// Prefer to add colors to the output only if it is forced via an environment variable or | ||
// because it's a terminal | ||
|
||
let color_choice = { | ||
if std::env::var("FORCE_COLOR").is_ok_and(|e| !e.is_empty()) { | ||
ColorChoice::Always | ||
} else if std::io::stderr().is_terminal() { | ||
ColorChoice::Auto | ||
} else { | ||
ColorChoice::Never | ||
} | ||
}; | ||
|
||
BufferWriter::stderr(color_choice) | ||
} | ||
|
||
pub fn add_handler() { | ||
std::panic::set_hook(Box::new(move |info: &PanicInfo<'_>| { | ||
print_compiler_bug_message(info) | ||
})); | ||
} | ||
|
||
fn print_compiler_bug_message(info: &PanicInfo<'_>) { | ||
let message = match ( | ||
info.payload().downcast_ref::<&str>(), | ||
info.payload().downcast_ref::<String>(), | ||
) { | ||
(Some(s), _) => (*s).to_string(), | ||
(_, Some(s)) => s.to_string(), | ||
(None, None) => "unknown error".into(), | ||
}; | ||
|
||
let location = match info.location() { | ||
None => "".into(), | ||
Some(location) => format!("{}:{}\n\t", location.file(), location.line()), | ||
}; | ||
|
||
let buffer_writer = stderr_buffer_writer(); | ||
let mut buffer = buffer_writer.buffer(); | ||
buffer | ||
.set_color(ColorSpec::new().set_bold(true).set_fg(Some(Color::Red))) | ||
.unwrap(); | ||
write!(buffer, "error").unwrap(); | ||
buffer.set_color(ColorSpec::new().set_bold(true)).unwrap(); | ||
write!(buffer, ": Fatal compiler bug!\n\n").unwrap(); | ||
buffer.set_color(&ColorSpec::new()).unwrap(); | ||
writeln!( | ||
buffer, | ||
"This is a fatal bug in the Aderyn, sorry! | ||
Please report this crash to https://github.com/cyfrin/aderyn/issues/new and include this error message with your report. | ||
Panic: {location}{message} | ||
Aderyn version: {version} | ||
Operating system: {os} | ||
If you can also share your code and say what file you were editing or any | ||
steps to reproduce the crash that would be a great help. | ||
You may also want to try again with the `ADERYN_LOG=trace` environment | ||
variable set. | ||
", | ||
location = location, | ||
message = message, | ||
version = env!("CARGO_PKG_VERSION"), | ||
os = std::env::consts::OS, | ||
) | ||
.unwrap(); | ||
buffer_writer.print(&buffer).unwrap(); | ||
} |
Oops, something went wrong.