panics now also write a log to ~/.local/shed/log/panic.log
This commit is contained in:
16
src/main.rs
16
src/main.rs
@@ -34,6 +34,7 @@ use crate::libsh::sys::TTY_FILENO;
|
|||||||
use crate::libsh::utils::AutoCmdVecUtils;
|
use crate::libsh::utils::AutoCmdVecUtils;
|
||||||
use crate::parse::execute::exec_input;
|
use crate::parse::execute::exec_input;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
use crate::procio::IoMode;
|
||||||
use crate::readline::term::{LineWriter, RawModeGuard, raw_mode};
|
use crate::readline::term::{LineWriter, RawModeGuard, raw_mode};
|
||||||
use crate::readline::{Prompt, ReadlineEvent, ShedVi};
|
use crate::readline::{Prompt, ReadlineEvent, ShedVi};
|
||||||
use crate::signal::{GOT_SIGWINCH, JOB_DONE, QUIT_CODE, check_signals, sig_setup, signals_pending};
|
use crate::signal::{GOT_SIGWINCH, JOB_DONE, QUIT_CODE, check_signals, sig_setup, signals_pending};
|
||||||
@@ -85,6 +86,21 @@ fn setup_panic_handler() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let data_dir = env::var("XDG_DATA_HOME").unwrap_or_else(|_| {
|
||||||
|
let home = env::var("HOME").unwrap();
|
||||||
|
format!("{home}/.local/share")
|
||||||
|
});
|
||||||
|
let log_dir = Path::new(&data_dir).join("shed").join("log");
|
||||||
|
std::fs::create_dir_all(&log_dir).unwrap();
|
||||||
|
let log_file_path = log_dir.join("panic.log");
|
||||||
|
let mut log_file = parse::get_redir_file(parse::RedirType::Output, log_file_path).unwrap();
|
||||||
|
|
||||||
|
let panic_info_raw = info.to_string();
|
||||||
|
log_file.write_all(panic_info_raw.as_bytes()).unwrap();
|
||||||
|
|
||||||
|
let backtrace = std::backtrace::Backtrace::force_capture();
|
||||||
|
log_file.write_all(format!("\nBacktrace:\n{:?}", backtrace).as_bytes()).unwrap();
|
||||||
|
|
||||||
default_panic_hook(info);
|
default_panic_hook(info);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1736,18 +1736,19 @@ fn node_is_punctuated(tokens: &[Tk]) -> bool {
|
|||||||
.is_some_and(|tk| matches!(tk.class, TkRule::Sep))
|
.is_some_and(|tk| matches!(tk.class, TkRule::Sep))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_redir_file(class: RedirType, path: PathBuf) -> ShResult<File> {
|
pub fn get_redir_file<P: AsRef<Path>>(class: RedirType, path: P) -> ShResult<File> {
|
||||||
|
let path = path.as_ref();
|
||||||
let result = match class {
|
let result = match class {
|
||||||
RedirType::Input => OpenOptions::new().read(true).open(Path::new(&path)),
|
RedirType::Input => OpenOptions::new().read(true).open(Path::new(&path)),
|
||||||
RedirType::Output => OpenOptions::new()
|
RedirType::Output => OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
.open(Path::new(&path)),
|
.open(path),
|
||||||
RedirType::Append => OpenOptions::new()
|
RedirType::Append => OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
.open(Path::new(&path)),
|
.open(path),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
};
|
};
|
||||||
Ok(result?)
|
Ok(result?)
|
||||||
|
|||||||
Reference in New Issue
Block a user