Skip to content
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 @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* add `use_selection_fg` to theme file to allow customizing selection foreground color [[@Upsylonbare](https://github.com/Upsylonbare)] ([#2515](https://github.com/gitui-org/gitui/pull/2515))

### Changed
* improve error messages [[@acuteenvy](https://github.com/acuteenvy)] ([#2617](https://github.com/gitui-org/gitui/pull/2617))
* increase MSRV from 1.70 to 1.81 [[@naseschwarz](https://github.com/naseschwarz)] ([#2094](https://github.com/gitui-org/gitui/issues/2094))
* improve syntax highlighting file detection [[@acuteenvy](https://github.com/acuteenvy)] ([#2524](https://github.com/extrawurst/gitui/pull/2524))
* Updated project links to point to `gitui-org` instead of `extrawurst` [[@vasleymus](https://github.com/vasleymus)] ([#2538](https://github.com/gitui-org/gitui/pull/2538))
Expand Down
47 changes: 22 additions & 25 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,24 @@ enum Updater {
NotifyWatcher,
}

/// Do `log::error!` and `eprintln!` in one line.
macro_rules! log_eprintln {
( $($arg:tt)* ) => {{
log::error!($($arg)*);
eprintln!($($arg)*);
}};
}

fn main() -> Result<()> {
let app_start = Instant::now();

let cliargs = process_cmdline()?;

asyncgit::register_tracing_logging();

if !valid_path(&cliargs.repo_path) {
eprintln!("invalid path\nplease run gitui inside of a non-bare git repository");
return Ok(());
}
ensure_valid_path(&cliargs.repo_path)?;

let key_config = KeyConfig::init()
.map_err(|e| eprintln!("KeyConfig loading error: {e}"))
.map_err(|e| log_eprintln!("KeyConfig loading error: {e}"))
.unwrap_or_default();
let theme = Theme::init(&cliargs.theme);

Expand All @@ -141,7 +145,7 @@ fn main() -> Result<()> {
shutdown_terminal();
}

set_panic_handlers()?;
set_panic_handler()?;

let mut repo_path = cliargs.repo_path;
let mut terminal = start_terminal(io::stdout(), &repo_path)?;
Expand Down Expand Up @@ -291,13 +295,13 @@ fn shutdown_terminal() {
io::stdout().execute(LeaveAlternateScreen).map(|_f| ());

if let Err(e) = leave_screen {
eprintln!("leave_screen failed:\n{e}");
log::error!("leave_screen failed:\n{e}");
}

let leave_raw_mode = disable_raw_mode();

if let Err(e) = leave_raw_mode {
eprintln!("leave_raw_mode failed:\n{e}");
log::error!("leave_raw_mode failed:\n{e}");
}
}

Expand All @@ -315,12 +319,14 @@ fn draw(terminal: &mut Terminal, app: &App) -> io::Result<()> {
Ok(())
}

fn valid_path(repo_path: &RepoPath) -> bool {
let error = asyncgit::sync::repo_open_error(repo_path);
if let Some(error) = &error {
log::error!("repo open error: {error}");
fn ensure_valid_path(repo_path: &RepoPath) -> Result<()> {
match asyncgit::sync::repo_open_error(repo_path) {
Some(e) => {
log::error!("{e}");
bail!(e)
}
None => Ok(()),
}
error.is_none()
}

fn select_event(
Expand Down Expand Up @@ -388,20 +394,11 @@ fn start_terminal(
Ok(terminal)
}

// do log::error! and eprintln! in one line, pass string, error and backtrace
macro_rules! log_eprintln {
($string:expr, $e:expr, $bt:expr) => {
log::error!($string, $e, $bt);
eprintln!($string, $e, $bt);
};
}

fn set_panic_handlers() -> Result<()> {
// regular panic handler
fn set_panic_handler() -> Result<()> {
panic::set_hook(Box::new(|e| {
let backtrace = Backtrace::new();
shutdown_terminal();
log_eprintln!("\nGitUI was close due to an unexpected panic.\nPlease file an issue on https://github.com/gitui-org/gitui/issues with the following info:\n\n{:?}\ntrace:\n{:?}", e, backtrace);
log_eprintln!("\nGitUI was closed due to an unexpected panic.\nPlease file an issue on https://github.com/gitui-org/gitui/issues with the following info:\n\n{e}\n\ntrace:\n{backtrace:?}");
}));

// global threadpool
Expand Down
Loading