Skip to content

Commit

Permalink
Log every panic to the logfile (#1602)
Browse files Browse the repository at this point in the history
* Add unified panic logging

* Remove redundant logging in client

* Add to changelog

* Improve changelog
  • Loading branch information
raphCode authored Jul 26, 2022
1 parent 9dc392e commit 408f520
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}
Expand Down
18 changes: 16 additions & 2 deletions zellij-utils/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit 408f520

Please sign in to comment.