# Oopsie woopsie!
A crate to make debugging unexpected panics easier both on developer and consumer machines.
Provides a panic handler which generates a helpful panic message and saves a backtrace, system information and minidump to a file.

## Features
- Generates a panic message with the panic payload and panic location.
- Makes the panic message colorful with feature `colored_panic_message`.
- Creates a panic log file which contains the panic message, system info, and a backtrace.
- Creates a minidump of the current process (Currently quite limited).
- Terminates the program with a configured termination method: `Exit`, `Abort`, `Loop`.

## Usage example
```
use std::panic;

fn main() {
    panic::set_hook(Box::new(|panicinfo: &panic::PanicInfo| {
        let panic_handling_config = oopsie_woopsie::PanicHandlingConfig {
            termination_method: "exit".to_string(), // The method used to terminate the program. Possible values: `Exit`, `Abort`, `Loop`.
            termination_exit_code: Some(101), // The returned error code when termination method `Exit` is used. Defaults to exit code 101.
            panic_info_log_file_destination: "C:/some/path/panic.txt".to_string(), // The path where to place the panic info log file.
            minidump_file_destination: "C:/some/path/panic.mdmp".to_string(), // The path where to place the minidump file. Will be ignored if feature `write_minidump` is disabled.
        };

        // Replaces the default panic handler with the custom made one.
        oopsie_woopsie::handle_error(
            panicinfo,
            panic_handling_config,
            Some(std::backtrace::Backtrace::force_capture()), // If you don't want to capture a backtrace, set this to `None`.
        );
    }));
}
```

## Example generated panic message (With enabled features `write_panic_log` and `write_minidump`)
```
[PANIC HANDLER INFO] Writing panic info.


A panic occured!

Panic location: file "src\\main.rs" - line 20 column 5.
Panic payload: a very interesting panic message right here.


[PANIC HANDLER INFO] Attempted to write panic info. Status: Ok(()).
[PANIC HANDLER INFO] Reading system info.
[PANIC HANDLER INFO] Read system info.
[PANIC HANDLER INFO] Writing information to panic log file "C:/some/path/panic.txt".
[PANIC HANDLER INFO] Attempted to write panic log file. Status: Ok(()).
[PANIC HANDLER INFO] Writing minidump file to "C:/some/path/panic.mdmp"
[PANIC HANDLER INFO] Attempted to write minidump file. Status: Ok(()).
```

## Example generated panic message using the [oofs error handling library](https://crates.io/crates/oofs) ([Using example 1](https://crates.io/crates/oofs#basic-example-1))
```
[PANIC HANDLER INFO] Writing panic info.


A panic occured!

Panic location: file "src\\main.rs" - line 36 column 21.
Panic payload: inner_fn($0, $1) failed at `src\main.rs:9:5`

Parameters:
    $0: usize = 123
    $1: &str = "hello world"



[PANIC HANDLER INFO] Attempted to write panic info. Status: Ok(()).
[PANIC HANDLER INFO] Reading system info.
[PANIC HANDLER INFO] Read system info.
[PANIC HANDLER INFO] Writing information to panic log file "C:/some/path/panic.txt".
[PANIC HANDLER INFO] Attempted to write panic log file. Status: Ok(()).
[PANIC HANDLER INFO] Writing minidump file to "C:/some/path/panic.mdmp".
[PANIC HANDLER INFO] Attempted to write minidump file. Status: Ok(()).
```

### Reminder: This crate only works for panics. It cannot debug crashes. If you need crash debugging, you need to use an out-of-process crash handler such as [Breakpad](https://github.com/google/breakpad), [Crashpad](https://github.com/chromium/crashpad). There is also [EmbarkStudio's Crash handling utility crates](https://github.com/EmbarkStudios/crash-handling).
### Also another thing: I do not have any other ideas i would like to add to this crate, so it will probably just contain bug fixes. If you have a suggestion, you can open an issue in the [Github repository](https://github.com/Normantas/oopsie-woopsie).