Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log every panic to the logfile #1602

Merged
merged 4 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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