Files
sausage/userland/fd/src/error.rs
T
surma b9e3e3677d userland: search and exec tools, spawn library (T14)
rg (ripgrep 15.2), grep (ours, on ripgrep's regex crates), find and xargs
(ours), sed (uutils 0.3 wrapper), diff and cmp (uutils diffutils 0.6 with -r),
fd 10.5, jaq 2.3, env and timeout. userland/spawn is a small Command-like
client of the process interface. search-test.nu: 42 cases match native tools.
2026-11-06 17:21:51 +00:00

52 lines
1.2 KiB
Rust

use std::fmt::Display;
use std::io;
use crate::sanitize::write_sanitized;
/// Print an error message using a format string, sanitizing any arguments if necessary
macro_rules! print_error {
($fmt:literal, $($arg:expr),*) => {
eprintln!(concat!("[fd error]: ", $fmt), $($crate::error::SanitizeErr::sanitize($arg)),*)
}
}
/// Trait for specifying how to sanitize a type for error display, if needed.
pub(crate) trait SanitizeErr {
type Sanitized: Display;
fn sanitize(self) -> Self::Sanitized;
}
impl SanitizeErr for &str {
type Sanitized = Self;
fn sanitize(self) -> Self {
self
}
}
impl SanitizeErr for io::Error {
type Sanitized = SanitizedError<io::Error>;
fn sanitize(self) -> Self::Sanitized {
SanitizedError(self)
}
}
impl SanitizeErr for ignore::Error {
type Sanitized = SanitizedError<ignore::Error>;
fn sanitize(self) -> Self::Sanitized {
SanitizedError(self)
}
}
pub struct SanitizedError<E>(E);
impl<E: std::error::Error> Display for SanitizedError<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let raw = self.0.to_string();
write_sanitized(f, &raw)
}
}