mirror of
https://github.com/sxyazi/yazi.git
synced 2026-05-13 08:16:40 +00:00
fix: handle broken pipe errors gracefully (#2110)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
fd21452aa4
commit
00e8adc3de
6 changed files with 50 additions and 12 deletions
|
|
@ -1 +1 @@
|
|||
{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","Sysinfo","ffprobe","vframes","luma","obase"],"version":"0.2","language":"en"}
|
||||
{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","Sysinfo","ffprobe","vframes","luma","obase","outln","errln","tmtheme"],"version":"0.2","language":"en"}
|
||||
|
|
@ -2,20 +2,40 @@ yazi_macro::mod_pub!(package);
|
|||
|
||||
yazi_macro::mod_flat!(args);
|
||||
|
||||
use std::process::ExitCode;
|
||||
|
||||
use clap::Parser;
|
||||
use yazi_macro::{errln, outln};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
async fn main() -> ExitCode {
|
||||
match run().await {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(e) => {
|
||||
for cause in e.chain() {
|
||||
if let Some(ioerr) = cause.downcast_ref::<std::io::Error>() {
|
||||
if ioerr.kind() == std::io::ErrorKind::BrokenPipe {
|
||||
return ExitCode::from(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
errln!("{:#}", e).ok();
|
||||
ExitCode::FAILURE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn run() -> anyhow::Result<()> {
|
||||
yazi_shared::init();
|
||||
yazi_fs::init();
|
||||
|
||||
if std::env::args_os().nth(1).is_some_and(|s| s == "-V" || s == "--version") {
|
||||
println!(
|
||||
outln!(
|
||||
"Ya {} ({} {})",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
env!("VERGEN_GIT_SHA"),
|
||||
env!("VERGEN_BUILD_DATE")
|
||||
);
|
||||
)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +46,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
if let Err(e) =
|
||||
yazi_dds::Client::shot("dds-emit", CommandPub::receiver()?, &cmd.body()?).await
|
||||
{
|
||||
eprintln!("Cannot emit command: {e}");
|
||||
errln!("Cannot emit command: {e}")?;
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +55,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
yazi_boot::init_default();
|
||||
yazi_dds::init();
|
||||
if let Err(e) = yazi_dds::Client::shot("dds-emit", cmd.receiver, &cmd.body()?).await {
|
||||
eprintln!("Cannot emit command: {e}");
|
||||
errln!("Cannot emit command: {e}")?;
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +81,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
yazi_dds::init();
|
||||
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, CommandPub::receiver()?, &cmd.body()?).await
|
||||
{
|
||||
eprintln!("Cannot send message: {e}");
|
||||
errln!("Cannot send message: {e}")?;
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +90,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
yazi_boot::init_default();
|
||||
yazi_dds::init();
|
||||
if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, &cmd.body()?).await {
|
||||
eprintln!("Cannot send message: {e}");
|
||||
errln!("Cannot send message: {e}")?;
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::path::PathBuf;
|
|||
use anyhow::{Context, Result, bail};
|
||||
use tokio::fs;
|
||||
use yazi_fs::{Xdg, maybe_exists, must_exists, remove_dir_clean};
|
||||
use yazi_macro::outln;
|
||||
|
||||
use super::Package;
|
||||
|
||||
|
|
@ -48,7 +49,7 @@ For safety, please manually delete it from your plugin/flavor directory and re-r
|
|||
|
||||
Self::deploy_assets(from.join("assets"), to.join("assets")).await?;
|
||||
|
||||
println!("Done!");
|
||||
outln!("Done!")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use anyhow::{Context, Result, bail};
|
|||
use tokio::fs;
|
||||
use toml_edit::{Array, DocumentMut, InlineTable, Item, Value};
|
||||
use yazi_fs::Xdg;
|
||||
use yazi_macro::outln;
|
||||
|
||||
use super::Package;
|
||||
|
||||
|
|
@ -78,13 +79,13 @@ impl Package {
|
|||
};
|
||||
|
||||
let deps = deps.as_array().context("`deps` must be an array")?;
|
||||
println!("{section}s:");
|
||||
outln!("{section}s:")?;
|
||||
|
||||
for dep in deps {
|
||||
let Some(dep) = dep.as_inline_table() else { continue };
|
||||
match (dep.get("use").and_then(Value::as_str), dep.get("rev").and_then(Value::as_str)) {
|
||||
(Some(use_), None) => println!("\t{use_}"),
|
||||
(Some(use_), Some(rev)) => println!("\t{use_} ({rev})"),
|
||||
(Some(use_), None) => outln!("\t{use_}")?,
|
||||
(Some(use_), Some(rev)) => outln!("\t{use_} ({rev})")?,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ mod asset;
|
|||
mod event;
|
||||
mod module;
|
||||
mod platform;
|
||||
mod stdio;
|
||||
|
|
|
|||
15
yazi-macro/src/stdio.rs
Normal file
15
yazi-macro/src/stdio.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#[macro_export]
|
||||
macro_rules! outln {
|
||||
($($tt:tt)*) => {{
|
||||
use std::io::Write;
|
||||
writeln!(std::io::stdout(), $($tt)*)
|
||||
}}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! errln {
|
||||
($($tt:tt)*) => {{
|
||||
use std::io::Write;
|
||||
writeln!(std::io::stderr(), $($tt)*)
|
||||
}}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue