From 408f520e4c1c30ed0f90aa80c0a02e3c6e70c511 Mon Sep 17 00:00:00 2001 From: raphCode <15750438+raphCode@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:47:25 +0200 Subject: [PATCH] Log every panic to the logfile (#1602) * Add unified panic logging * Remove redundant logging in client * Add to changelog * Improve changelog --- CHANGELOG.md | 1 + zellij-client/src/lib.rs | 2 -- zellij-utils/src/errors.rs | 18 ++++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee96be802c..b7e6e46888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * fix: avoid sending mouse click events on pane frames to applications (https://github.com/zellij-org/zellij/pull/1584) * feat: search through terminal scrollback (https://github.com/zellij-org/zellij/pull/1521) * feat: support themes directory (https://github.com/zellij-org/zellij/pull/1577) +* feat: Improve logging by writing server panics into the logfile (https://github.com/zellij-org/zellij/pull/1602) ## [0.30.0] - 2022-06-07 * fix: right and middle clicks creating selection (https://github.com/zellij-org/zellij/pull/1372) diff --git a/zellij-client/src/lib.rs b/zellij-client/src/lib.rs index 3b81694b41..380b39c869 100644 --- a/zellij-client/src/lib.rs +++ b/zellij-client/src/lib.rs @@ -7,7 +7,6 @@ mod sessions; mod stdin_ansi_parser; mod stdin_handler; -use log::error; use log::info; use std::env::current_exe; use std::io::{self, Write}; @@ -210,7 +209,6 @@ pub fn start_client( let send_client_instructions = send_client_instructions.clone(); let os_input = os_input.clone(); Box::new(move |info| { - error!("Panic occurred in client:\n{:?}", info); if let Ok(()) = os_input.unset_raw_mode(0) { handle_panic(info, &send_client_instructions); } diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index 0e18bb9e5f..bd20612276 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -3,6 +3,7 @@ use crate::channels::{SenderWithContext, ASYNCOPENCALLS, OPENCALLS}; use colored::*; +use log::error; use serde::{Deserialize, Serialize}; use std::fmt::{Display, Error, Formatter}; use std::panic::PanicInfo; @@ -70,13 +71,15 @@ where let mut report: Report = Panic(format!("\u{1b}[0;31m{}\u{1b}[0;0m", msg)).into(); + let mut location_string = String::new(); if let Some(location) = info.location() { - report = report.wrap_err(format!( + location_string = format!( "At {}:{}:{}", location.file(), location.line(), location.column() - )); + ); + report = report.wrap_err(location_string.clone()); } if !err_ctx.is_empty() { @@ -88,6 +91,17 @@ where thread )); + error!( + "{}", + format!( + "Panic occured: + thread: {} + location: {} + message: {}", + thread, location_string, msg + ) + ); + if thread == "main" { // here we only show the first line because the backtrace is not readable otherwise // a better solution would be to escape raw mode before we do this, but it's not trivial