Revert "b/logs: do some things to try to log panics on startups" (#148)

This commit is contained in:
Tyler Wilding 2023-04-01 00:55:42 -05:00 committed by GitHub
parent 56c7c7ff8d
commit 45c86dbfe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 84 deletions

1
src-tauri/Cargo.lock generated
View file

@ -2258,7 +2258,6 @@ dependencies = [
name = "opengoal-launcher" name = "opengoal-launcher"
version = "2.0.5" version = "2.0.5"
dependencies = [ dependencies = [
"backtrace",
"chrono", "chrono",
"dir-diff", "dir-diff",
"fern", "fern",

View file

@ -35,7 +35,6 @@ thiserror = "1.0.40"
rev_buf_reader = "0.3.0" rev_buf_reader = "0.3.0"
flate2 = "1.0.25" flate2 = "1.0.25"
tar = "0.4.38" tar = "0.4.38"
backtrace = "0.3.67"
[features] [features]
# by default Tauri runs in production mode # by default Tauri runs in production mode

View file

@ -7,36 +7,15 @@ use fern::colors::{Color, ColoredLevelConfig};
use tauri::{Manager, RunEvent}; use tauri::{Manager, RunEvent};
use util::file::create_dir; use util::file::create_dir;
use backtrace::Backtrace; use std::env;
use std::{env, io::Write};
mod commands; mod commands;
mod config; mod config;
mod textures; mod textures;
mod util; mod util;
fn panic_hook(info: &std::panic::PanicInfo) {
let backtrace = Backtrace::new();
log::error!("panic occurred: {:?}\n{:?}", info, backtrace);
match std::fs::File::create("og-launcher-crash.log") {
Ok(mut file) => {
if let Err(err) =
file.write_all(format!("panic occurred: {:?}\n{:?}", info, backtrace).as_bytes())
{
log::error!("unable to log crash report to a file - {:?}", err)
}
}
Err(err) => log::error!("unable to log crash report to a file - {:?}", err),
}
std::process::exit(1);
}
fn main() { fn main() {
// In the event that some catastrophic happens, atleast log it out tauri::Builder::default()
// the panic_hook will log to a file in the folder of the executable
std::panic::set_hook(Box::new(panic_hook));
let tauri_setup = tauri::Builder::default()
.setup(|app| { .setup(|app| {
// Setup Logging // Setup Logging
let log_path = app let log_path = app
@ -58,7 +37,7 @@ fn main() {
// since almost all of them are the same as the color for the whole line, we // since almost all of them are the same as the color for the whole line, we
// just clone `colors_line` and overwrite our changes // just clone `colors_line` and overwrite our changes
let colors_level = colors_line.clone().info(Color::Cyan); let colors_level = colors_line.clone().info(Color::Cyan);
let log_setup_ok = fern::Dispatch::new() fern::Dispatch::new()
// Perform allocation-free log formatting // Perform allocation-free log formatting
.format(move |out, message, record| { .format(move |out, message, record| {
out.finish(format_args!( out.finish(format_args!(
@ -81,26 +60,23 @@ fn main() {
.chain(std::io::stdout()) .chain(std::io::stdout())
.chain(fern::DateBased::new(&log_path, "/%Y-%m-%d.log")) .chain(fern::DateBased::new(&log_path, "/%Y-%m-%d.log"))
// Apply globally // Apply globally
.apply(); .apply()
match log_setup_ok { .expect("Could not setup logs");
Ok(_) => { log::info!("Logging Initialized");
log::info!("Logging Initialized");
// Truncate rotated log files to '5' // Truncate rotated log files to '5'
let mut paths: Vec<_> = std::fs::read_dir(&log_path)?.map(|r| r.unwrap()).collect(); let mut paths: Vec<_> = std::fs::read_dir(&log_path)?.map(|r| r.unwrap()).collect();
paths.sort_by_key(|dir| dir.path()); paths.sort_by_key(|dir| dir.path());
paths.reverse(); paths.reverse();
let mut i = 0; let mut i = 0;
for path in paths { for path in paths {
i += 1; i += 1;
log::info!("{}", path.path().display()); log::info!("{}", path.path().display());
if i > 5 { if i > 5 {
log::info!("deleting - {}", path.path().display()); log::info!("deleting - {}", path.path().display());
std::fs::remove_file(path.path())?; std::fs::remove_file(path.path())?;
}
}
} }
Err(err) => log::error!("Could not initialize logging {:?}", err), }
};
// Load the config (or initialize it with defaults) // Load the config (or initialize it with defaults)
// //
@ -148,43 +124,11 @@ fn main() {
commands::window::open_dir_in_os commands::window::open_dir_in_os
]) ])
.build(tauri::generate_context!()) .build(tauri::generate_context!())
.map_err(|err| { .expect("error building tauri app")
let backtrace = Backtrace::new(); .run(|_app_handle, event| match event {
log::error!( RunEvent::ExitRequested { .. } => {
"unexpected top level error occurred: {:?}\n{:?}", std::process::exit(0);
err,
backtrace
);
match std::fs::File::create("og-launcher-crash.log") {
Ok(mut file) => {
if let Err(file_err) = file.write_all(
format!(
"unexpected top level error occurred: {:?}\n{:?}",
err, backtrace
)
.as_bytes(),
) {
log::error!("unable to log crash report to a file - {:?}", file_err)
}
}
Err(err) => log::error!("unable to log crash report to a file - {:?}", err),
} }
std::process::exit(1); _ => (),
}); })
match tauri_setup {
Ok(app) => {
log::info!("application starting up");
app.run(|_app_handle, event| match event {
RunEvent::ExitRequested { .. } => {
log::info!("Exit requested, exiting!");
std::process::exit(0);
}
_ => (),
})
}
Err(err) => {
log::error!("Could not setup tauri application {:?}, exiting", err);
std::process::exit(1);
}
};
} }

View file

@ -38,7 +38,10 @@
"windows": { "windows": {
"certificateThumbprint": null, "certificateThumbprint": null,
"digestAlgorithm": "sha256", "digestAlgorithm": "sha256",
"timestampUrl": "" "timestampUrl": "",
"webviewInstallMode": {
"type": "embedBootstrapper"
}
} }
}, },
"allowlist": { "allowlist": {