Skip to content

Commit

Permalink
feat: add panic logs on backend
Browse files Browse the repository at this point in the history
  • Loading branch information
invm authored and Michael Ionov committed Dec 28, 2023
1 parent 40caf97 commit 4184483
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tracing = "0.1.37"
tracing-subscriber = "0.3.17"
sqlparser = "0.38.0"
md-5 = "0.10.6"
chrono = "0.4.31"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
30 changes: 22 additions & 8 deletions src-tauri/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use chrono;
use log::error;
use state::AppState;
use std::{fs, panic};
use tauri::{Manager, State};
use tokio::sync::mpsc;
use tokio::sync::Mutex;
use tracing_subscriber;

use query_noir::{
database::queries::initialize_database,
handlers::{connections, queries},
queues::query::{async_process_model, rs2js},
state::{self, AsyncState},
utils::init, database::queries::initialize_database,
utils::{fs::get_app_path, init},
};

use tokio::sync::mpsc;
use tokio::sync::Mutex;
use tracing_subscriber;

use state::AppState;
use tauri::{Manager, State};

#[derive(Clone, serde::Serialize)]
struct Payload {
args: Vec<String>,
Expand All @@ -24,6 +27,17 @@ struct Payload {
fn main() {
tracing_subscriber::fmt::init();

panic::set_hook(Box::new(|info| {
error!("Panicked: {:?}", info);
let path = get_app_path();
let ts = chrono::offset::Utc::now();
fs::write(
format!("{}/error.log", path),
format!("{} - {:?}", ts, info),
)
.unwrap();
}));

let (async_proc_input_tx, async_proc_input_rx) = mpsc::channel(1);
let (async_proc_output_tx, mut async_proc_output_rx) = mpsc::channel(1);

Expand Down
8 changes: 8 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ function App() {
messages: { notify },
} = useAppSelector();

addEventListener('unhandledrejection', (e) => {
console.log({ message: 'Unhandled rejection', info: (e.reason?.message || e.reason || e).toString() });
});

window.addEventListener('error', (e) => {
console.log({ message: 'Unhandled error', error: e.error });
});

const compareAndAssign = async (event: QueryTaskResult) => {
const { status, query_idx, tab_idx, conn_id } = event;
if (getConnection().id === conn_id && contentStore.idx === tab_idx) {
Expand Down

0 comments on commit 4184483

Please sign in to comment.