diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index f10579c808c..5d9e182bd46 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -17,7 +17,6 @@ use std::io::{self, BufWriter, ErrorKind, IsTerminal, Read, Write}; use std::os::fd::AsFd; #[cfg(unix)] use std::os::unix::fs::FileTypeExt; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{UResult, strip_errno}; use uucore::translate; @@ -79,7 +78,7 @@ impl LineNumber { } } -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] enum CatError { /// Wrapper around `io::Error` #[error("{}", strip_errno(.0))] diff --git a/src/uu/chcon/src/errors.rs b/src/uu/chcon/src/errors.rs index fa4ae6fee54..43e9b36864f 100644 --- a/src/uu/chcon/src/errors.rs +++ b/src/uu/chcon/src/errors.rs @@ -9,13 +9,12 @@ use std::ffi::OsString; use std::fmt::Write; use std::io; -use thiserror::Error; use uucore::display::Quotable; use uucore::translate; pub(crate) type Result = std::result::Result; -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] pub(crate) enum Error { #[error("{}", translate!("chcon-error-no-context-specified"))] MissingContext, @@ -86,7 +85,7 @@ impl Error { } } -pub(crate) fn report_full_error(mut err: &dyn std::error::Error) -> String { +pub(crate) fn report_full_error(mut err: &dyn core::error::Error) -> String { let mut desc = String::with_capacity(256); write!(desc, "{err}").unwrap(); while let Some(source) = err.source() { diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index a50f0a6bf0e..dea8e3f1471 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -10,7 +10,6 @@ use std::ffi::OsString; use std::fs; use std::os::unix::fs::{MetadataExt, PermissionsExt}; use std::path::{Path, PathBuf}; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{ExitCode, UError, UResult, USimpleError, UUsageError, set_exit_code}; use uucore::fs::display_permissions_unix; @@ -23,7 +22,7 @@ use uucore::{format_usage, show, show_error}; use uucore::translate; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum ChmodError { #[error("{}", translate!("chmod-error-cannot-stat", "file" => _0.quote()))] CannotStat(PathBuf), diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 68e8fe2ed05..fbe2f1fdbe1 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -9,7 +9,7 @@ mod error; use crate::error::ChrootError; use clap::{Arg, ArgAction, Command}; use std::ffi::{CString, OsStr}; -use std::io::{Error, ErrorKind}; +use std::io::ErrorKind; use std::os::unix::prelude::OsStrExt; use std::os::unix::process::CommandExt; use std::path::{Path, PathBuf}; @@ -318,7 +318,7 @@ fn set_supplemental_gids(gids: &[libc::gid_t]) -> std::io::Result<()> { if err == 0 { Ok(()) } else { - Err(Error::last_os_error()) + Err(std::io::Error::last_os_error()) } } @@ -328,7 +328,7 @@ fn set_gid(gid: libc::gid_t) -> std::io::Result<()> { if err == 0 { Ok(()) } else { - Err(Error::last_os_error()) + Err(std::io::Error::last_os_error()) } } @@ -338,7 +338,7 @@ fn set_uid(uid: libc::uid_t) -> std::io::Result<()> { if err == 0 { Ok(()) } else { - Err(Error::last_os_error()) + Err(std::io::Error::last_os_error()) } } @@ -440,6 +440,6 @@ fn enter_chroot(root: &Path, skip_chdir: bool) -> UResult<()> { } Ok(()) } else { - Err(ChrootError::CannotEnter(root.into(), Error::last_os_error()).into()) + Err(ChrootError::CannotEnter(root.into(), std::io::Error::last_os_error()).into()) } } diff --git a/src/uu/chroot/src/error.rs b/src/uu/chroot/src/error.rs index 0592d72efad..6a12a007414 100644 --- a/src/uu/chroot/src/error.rs +++ b/src/uu/chroot/src/error.rs @@ -5,28 +5,26 @@ // spell-checker:ignore NEWROOT Userspec userspec //! Errors returned by chroot. use std::ffi::OsString; -use std::io::Error; use std::path::PathBuf; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::UError; use uucore::libc; use uucore::translate; /// Errors that can happen while executing chroot. -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum ChrootError { /// Failed to enter the specified directory. #[error("{}", translate!("chroot-error-cannot-enter", "dir" => _0.quote(), "err" => _1))] - CannotEnter(PathBuf, #[source] Error), + CannotEnter(PathBuf, #[source] std::io::Error), /// Failed to execute the specified command. #[error("{}", translate!("chroot-error-command-failed", "cmd" => _0.quote(), "err" => _1))] - CommandFailed(OsString, #[source] Error), + CommandFailed(OsString, #[source] std::io::Error), /// Failed to find the specified command. #[error("{}", translate!("chroot-error-command-not-found", "cmd" => _0.quote(), "err" => _1))] - CommandNotFound(OsString, #[source] Error), + CommandNotFound(OsString, #[source] std::io::Error), #[error("{}", translate!("chroot-error-groups-parsing-failed"))] GroupsParsingFailed, @@ -58,15 +56,15 @@ pub enum ChrootError { /// The call to `setgid()` failed. #[error("{}", translate!("chroot-error-set-gid-failed", "gid" => _0, "err" => _1))] - SetGidFailed(String, #[source] Error), + SetGidFailed(String, #[source] std::io::Error), /// The call to `setgroups()` failed. #[error("{}", translate!("chroot-error-set-groups-failed", "err" => _0))] - SetGroupsFailed(Error), + SetGroupsFailed(std::io::Error), /// The call to `setuid()` failed. #[error("{}", translate!("chroot-error-set-user-failed", "user" => _0.maybe_quote(), "err" => _1))] - SetUserFailed(String, #[source] Error), + SetUserFailed(String, #[source] std::io::Error), } impl UError for ChrootError { diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 2e9ae6b62ef..cb8d7bc7012 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -24,7 +24,6 @@ use filetime::FileTime; use indicatif::{ProgressBar, ProgressStyle}; #[cfg(unix)] use nix::sys::stat::{Mode, SFlag, dev_t, mknod as nix_mknod, mode_t}; -use thiserror::Error; use platform::copy_on_write; use uucore::display::Quotable; @@ -50,7 +49,7 @@ use crate::copydir::copy_directory; mod copydir; mod platform; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum CpError { /// Simple [`io::Error`] wrapper #[error("{0}")] @@ -128,7 +127,7 @@ impl Display for BackupError { } } -impl std::error::Error for BackupError {} +impl core::error::Error for BackupError {} impl UError for CpError { fn code(&self) -> i32 { diff --git a/src/uu/csplit/src/csplit_error.rs b/src/uu/csplit/src/csplit_error.rs index d73400bd7d1..ae937957978 100644 --- a/src/uu/csplit/src/csplit_error.rs +++ b/src/uu/csplit/src/csplit_error.rs @@ -4,13 +4,12 @@ // file that was distributed with this source code. use std::io; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::UError; use uucore::translate; /// Errors thrown by the csplit command -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum CsplitError { #[error("IO error: {}", _0)] IoError(#[from] io::Error), diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index a2bc1103651..072b189c23d 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -9,7 +9,6 @@ mod unit_tests; use super::{ConversionMode, IConvFlags, IFlags, Num, OConvFlags, OFlags, Settings, StatusLevel}; use crate::conversion_tables::ConversionTable; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::UError; use uucore::parser::parse_size::{ParseSizeError, Parser as SizeParser}; @@ -17,7 +16,7 @@ use uucore::show_warning; use uucore::translate; /// Parser Errors describe errors with parser input -#[derive(Debug, PartialEq, Eq, Error)] +#[derive(Debug, PartialEq, Eq, thiserror::Error)] pub enum ParseError { #[error("{}", translate!("dd-error-unrecognized-operand", "operand" => .0.clone()))] UnrecognizedOperand(String), diff --git a/src/uu/df/src/columns.rs b/src/uu/df/src/columns.rs index fe3c0155a54..c6cbb4359db 100644 --- a/src/uu/df/src/columns.rs +++ b/src/uu/df/src/columns.rs @@ -5,7 +5,6 @@ // spell-checker:ignore itotal iused iavail ipcent pcent squashfs use crate::{OPT_INODES, OPT_OUTPUT, OPT_PRINT_TYPE}; use clap::{ArgMatches, parser::ValueSource}; -use thiserror::Error; use uucore::display::Quotable; /// The columns in the output table produced by `df`. @@ -58,7 +57,7 @@ pub(crate) enum Column { } /// An error while defining which columns to display in the output table. -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub(crate) enum ColumnError { /// If a column appears more than once in the `--output` argument. #[error("{}", .0.quote())] diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index f7d5efdaaf3..e22b37fe406 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -23,7 +23,6 @@ use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource}; use std::ffi::OsString; use std::io::stdout; use std::path::Path; -use thiserror::Error; use crate::blocks::{BlockSize, read_block_size}; use crate::columns::{Column, ColumnError}; @@ -118,7 +117,7 @@ impl Options { } } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum OptionsError { // TODO This needs to vary based on whether `--block-size` // or `-B` were provided. @@ -429,7 +428,7 @@ where Ok(result) } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum DfError { /// A problem while parsing command-line options. #[error("{}", .0)] diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 012517dc3eb..bc5560bafea 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -20,7 +20,6 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::mpsc; use std::thread; -use thiserror::Error; use uucore::display::{Quotable, print_verbatim}; use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code}; use uucore::fsext::{MetadataTimeField, metadata_get_time}; @@ -737,7 +736,7 @@ fn du_regular( Ok(my_stat) } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum DuError { #[error("{}", translate!("du-error-invalid-max-depth", "depth" => _0.quote()))] InvalidMaxDepthArg(String), diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 3343544253e..386ccbf69f6 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -47,9 +47,7 @@ use uucore::signals::{signal_by_name_or_value, signal_name_by_value, signal_numb use uucore::translate; use uucore::{format_usage, show_warning}; -use thiserror::Error; - -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, PartialEq, thiserror::Error)] pub enum EnvError { #[error("{}", translate!("env-error-missing-closing-quote", "position" => .0, "quote" => .1))] EnvMissingClosingQuote(usize, char), diff --git a/src/uu/expand/src/expand.rs b/src/uu/expand/src/expand.rs index 4c3b09f64b7..683eebdcd0e 100644 --- a/src/uu/expand/src/expand.rs +++ b/src/uu/expand/src/expand.rs @@ -12,7 +12,6 @@ use std::io::{BufReader, BufWriter, Read, Write, stdin, stdout}; use std::num::IntErrorKind; use std::path::Path; use std::str::from_utf8; -use thiserror::Error; use unicode_width::UnicodeWidthChar; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code}; @@ -55,7 +54,7 @@ fn is_digit_or_comma(c: char) -> bool { } /// Errors that can occur when parsing a `--tabs` argument. -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum ParseError { #[error("{}", translate!("expand-error-invalid-character", "char" => .0.quote()))] InvalidCharacter(String), diff --git a/src/uu/expr/src/expr.rs b/src/uu/expr/src/expr.rs index 9392fcee72c..f08f5c2d2fb 100644 --- a/src/uu/expr/src/expr.rs +++ b/src/uu/expr/src/expr.rs @@ -6,7 +6,6 @@ use clap::{Arg, ArgAction, Command}; use std::io::{Write, stdout}; use syntax_tree::{AstNode, is_truthy}; -use thiserror::Error; use uucore::os_string_to_vec; use uucore::translate; use uucore::{ @@ -26,7 +25,7 @@ mod options { pub type ExprResult = Result; -#[derive(Error, Clone, Debug, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] pub enum ExprError { #[error("{}", translate!("expr-error-unexpected-argument", "arg" => _0.quote()))] UnexpectedArgument(String), diff --git a/src/uu/fmt/src/fmt.rs b/src/uu/fmt/src/fmt.rs index dd8f10fd882..79c70a0cab4 100644 --- a/src/uu/fmt/src/fmt.rs +++ b/src/uu/fmt/src/fmt.rs @@ -18,12 +18,11 @@ use uucore::format_usage; use linebreak::break_lines; use parasplit::ParagraphStream; -use thiserror::Error; mod linebreak; mod parasplit; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum FmtError { #[error("{}", translate!("fmt-error-invalid-goal", "goal" => .0.quote()))] InvalidGoal(String), diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index 86128fc63b8..5511610d673 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -6,7 +6,6 @@ // spell-checker:ignore (ToDO) passwd use std::io::{Write, stdout}; -use thiserror::Error; use uucore::{ display::Quotable, entries::{Locate, Passwd, get_groups_gnu, gid2grp}, @@ -21,7 +20,7 @@ mod options { pub const USERS: &str = "USERNAME"; } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum GroupsError { #[error("{message}", message = translate!("groups-error-fetch"))] GetGroupsFailed, diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index 6d548457aa1..5ce778572e2 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -14,7 +14,6 @@ use std::num::TryFromIntError; #[cfg(unix)] use std::os::fd::AsFd; use std::path::{Path, PathBuf}; -use thiserror::Error; use uucore::display::{Quotable, print_verbatim}; use uucore::error::{FromIo, UError, UResult, USimpleError}; use uucore::line_ending::LineEnding; @@ -33,7 +32,7 @@ use take::copy_all_but_n_bytes; use take::copy_all_but_n_lines; use take::take_lines; -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] enum HeadError { /// Wrapper around `io::Error` #[error("{}", translate!("head-error-reading-file", "name" => name.quote(), "err" => err))] diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index f19f8aca249..66299b8ff75 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -19,7 +19,6 @@ use std::fs::{File, OpenOptions}; use std::io::{Write, stdout}; use std::path::{MAIN_SEPARATOR, Path, PathBuf}; use std::process; -use thiserror::Error; use uucore::backup_control::{self, BackupMode}; use uucore::buf_copy::copy_stream; use uucore::display::Quotable; @@ -68,7 +67,7 @@ pub struct Behavior { privileged: bool, } -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] enum InstallError { #[error("{}", translate!("install-error-dir-needs-arg", "util_name" => "install"))] DirNeedsArg, diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index ddd56584131..5a40187bd00 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -15,7 +15,6 @@ use std::io::{BufRead, BufReader, BufWriter, Split, Stdin, Write, stdin, stdout} use std::num::IntErrorKind; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code}; use uucore::i18n::collator::{ @@ -24,7 +23,7 @@ use uucore::i18n::collator::{ use uucore::line_ending::LineEnding; use uucore::{format_usage, show_error, translate}; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum JoinError { #[error("{}", translate!("join-error-io", "error" => .0))] IOError(#[from] std::io::Error), diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index e92a47da3b4..c5c818b9acd 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -8,7 +8,6 @@ use clap::{Arg, ArgAction, Command}; use nix::sys::signal::{self, Signal}; use nix::unistd::Pid; -use std::io::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError}; use uucore::translate; @@ -76,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } else { let sig = (sig as i32) .try_into() - .map_err(|e| Error::from_raw_os_error(e as i32))?; + .map_err(|e| std::io::Error::from_raw_os_error(e as i32))?; Some(sig) }; @@ -254,7 +253,7 @@ fn kill(sig: Option, pids: &[i32]) { for &pid in pids { if let Err(e) = signal::kill(Pid::from_raw(pid), sig) { show!( - Error::from_raw_os_error(e as i32) + std::io::Error::from_raw_os_error(e as i32) .map_err_context(|| { translate!("kill-error-sending-signal", "pid" => pid) }) ); } diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 96e708b2b1a..dd5c399758e 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -18,7 +18,6 @@ use std::borrow::Cow; use std::collections::HashSet; use std::ffi::OsString; use std::fs; -use thiserror::Error; #[cfg(any(unix, target_os = "redox"))] use std::os::unix::fs::symlink; @@ -50,7 +49,7 @@ pub enum OverwriteMode { Force, } -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] pub enum LnError { #[error("{}", translate!("ln-error-target-is-not-directory", "target" => _0.quote()))] TargetIsNotADirectory(PathBuf), diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 392aed0972e..6af986f8e14 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -28,7 +28,6 @@ use std::{ path::{Path, PathBuf}, time::{Duration, SystemTime, UNIX_EPOCH}, }; -use thiserror::Error; #[cfg(unix)] use uucore::libc::{S_IXGRP, S_IXOTH, S_IXUSR}; @@ -60,7 +59,7 @@ use config::{Dereference, Files, Sort}; use dired::DiredOutput; use display::{display_items, display_size, should_display, show_dir_name}; -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] enum LsError { #[error("{}", translate!("ls-error-invalid-line-width", "width" => format!("'{_0}'")))] InvalidLineWidth(String), diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index f0cd78cfe55..9e49aaa44bd 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -28,7 +28,6 @@ use rand::{ rngs::{self, SmallRng}, }; use tempfile::Builder; -use thiserror::Error; static DEFAULT_TEMPLATE: &str = "tmp.XXXXXXXXXX"; @@ -49,7 +48,7 @@ const TMPDIR_ENV_VAR: &str = "TMP"; const FALLBACK_TMPDIR: &str = "/tmp"; -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] enum MkTempError { #[error("{}", translate!("mktemp-error-persist-file", "path" => .0.quote()))] PersistError(PathBuf), diff --git a/src/uu/more/src/more.rs b/src/uu/more/src/more.rs index 0ad3006024c..be7b42cf285 100644 --- a/src/uu/more/src/more.rs +++ b/src/uu/more/src/more.rs @@ -78,7 +78,7 @@ impl std::fmt::Display for MoreError { } } -impl std::error::Error for MoreError {} +impl core::error::Error for MoreError {} const BELL: char = '\x07'; // Printing this character will ring the bell diff --git a/src/uu/mv/src/error.rs b/src/uu/mv/src/error.rs index 721cc799cc9..fb975183457 100644 --- a/src/uu/mv/src/error.rs +++ b/src/uu/mv/src/error.rs @@ -2,11 +2,10 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use thiserror::Error; use uucore::error::UError; use uucore::translate; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum MvError { #[error("{}", translate!("mv-error-no-such-file", "path" => .0.clone()))] NoSuchFile(String), diff --git a/src/uu/mv/src/hardlink.rs b/src/uu/mv/src/hardlink.rs index 8ef687e3562..a7fe47e1252 100644 --- a/src/uu/mv/src/hardlink.rs +++ b/src/uu/mv/src/hardlink.rs @@ -71,8 +71,8 @@ impl std::fmt::Display for HardlinkError { } } -impl std::error::Error for HardlinkError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for HardlinkError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::Io(e) => Some(e), Self::Metadata { error, .. } => Some(error), diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index a7a35f81fc9..f25fa46768b 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -11,13 +11,12 @@ use clap::{Arg, ArgAction, Command}; use libc::{SIG_IGN, SIGHUP, dup2, signal}; use std::env; use std::fs::{File, OpenOptions}; -use std::io::{Error, ErrorKind, IsTerminal}; +use std::io::{ErrorKind, IsTerminal}; use std::os::unix::prelude::*; use std::os::unix::process::CommandExt; use std::path::{Path, PathBuf}; use std::process; use std::sync::LazyLock; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{UError, UResult, set_exit_code}; use uucore::translate; @@ -34,19 +33,19 @@ mod options { pub const CMD: &str = "cmd"; } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum NohupError { #[error("{}", translate!("nohup-error-cannot-detach"))] CannotDetach, #[error("{}", translate!("nohup-error-cannot-replace", "name" => (*_0), "err" => _1))] - CannotReplace(&'static str, #[source] Error), + CannotReplace(&'static str, #[source] std::io::Error), #[error("{}", translate!("nohup-error-open-failed", "path" => NOHUP_OUT.quote(), "err" => _1))] - OpenFailed(i32, #[source] Error), + OpenFailed(i32, #[source] std::io::Error), #[error("{}", translate!("nohup-error-open-failed-both", "first_path" => NOHUP_OUT.quote(), "first_err" => _1, "second_path" => _2.quote(), "second_err" => _3))] - OpenFailed2(i32, #[source] Error, String, Error), + OpenFailed2(i32, #[source] std::io::Error, String, std::io::Error), } impl UError for NohupError { @@ -119,7 +118,7 @@ fn replace_fds() -> UResult<()> { let new_stdin = File::open(Path::new("/dev/null")) .map_err(|e| NohupError::CannotReplace("STDIN", e))?; if unsafe { dup2(new_stdin.as_raw_fd(), 0) } != 0 { - return Err(NohupError::CannotReplace("STDIN", Error::last_os_error()).into()); + return Err(NohupError::CannotReplace("STDIN", std::io::Error::last_os_error()).into()); } } @@ -128,12 +127,14 @@ fn replace_fds() -> UResult<()> { let fd = new_stdout.as_raw_fd(); if unsafe { dup2(fd, 1) } != 1 { - return Err(NohupError::CannotReplace("STDOUT", Error::last_os_error()).into()); + return Err( + NohupError::CannotReplace("STDOUT", std::io::Error::last_os_error()).into(), + ); } } if std::io::stderr().is_terminal() && unsafe { dup2(1, 2) } != 2 { - return Err(NohupError::CannotReplace("STDERR", Error::last_os_error()).into()); + return Err(NohupError::CannotReplace("STDERR", std::io::Error::last_os_error()).into()); } Ok(()) } diff --git a/src/uu/numfmt/src/errors.rs b/src/uu/numfmt/src/errors.rs index d3dcc48732c..5075533b17c 100644 --- a/src/uu/numfmt/src/errors.rs +++ b/src/uu/numfmt/src/errors.rs @@ -4,10 +4,9 @@ // file that was distributed with this source code. use std::fmt::Debug; -use thiserror::Error; use uucore::error::UError; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] #[error("{0}")] pub enum NumfmtError { IoError(String), diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 080e0200e22..daaf2a485b9 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -575,12 +575,12 @@ mod tests { FormatOptions, InvalidModes, NumfmtOptions, Range, RoundMethod, TransformOptions, Unit, handle_args, handle_buffer, parse_unit_size, parse_unit_size_suffix, }; - use std::io::{BufReader, Error, ErrorKind, Read}; + use std::io::{BufReader, ErrorKind, Read}; struct MockBuffer {} impl Read for MockBuffer { - fn read(&mut self, _: &mut [u8]) -> Result { - Err(Error::new(ErrorKind::BrokenPipe, "broken pipe")) + fn read(&mut self, _: &mut [u8]) -> Result { + Err(std::io::Error::new(ErrorKind::BrokenPipe, "broken pipe")) } } diff --git a/src/uu/od/src/mockstream.rs b/src/uu/od/src/mockstream.rs index 8cfb26bc9c7..87afb5a24f4 100644 --- a/src/uu/od/src/mockstream.rs +++ b/src/uu/od/src/mockstream.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. // https://github.com/lazy-bitfield/rust-mockstream/pull/2 -use std::io::{Cursor, Error, ErrorKind, Read, Result}; +use std::io::{Cursor, ErrorKind, Read, Result}; /// `FailingMockStream` mocks a stream which will fail upon read or write /// @@ -73,7 +73,7 @@ impl FailingMockStream { if self.repeat_count > 0 { self.repeat_count -= 1; } - Err(Error::new(self.kind, self.message)) + Err(std::io::Error::new(self.kind, self.message)) } } } diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index def105ae50d..1bd69b7946c 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -15,7 +15,6 @@ use std::io::{Read, Write, stderr, stdin, stdout}; use std::str::Utf8Error; use std::string::FromUtf8Error; use std::time::SystemTime; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::UResult; @@ -185,7 +184,7 @@ impl From for PrError { } } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum PrError { #[error("pr: {msg}")] EncounteredErrors { msg: String }, diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 64a5e2bacbe..419dfecc625 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -17,7 +17,6 @@ use std::path::Path; use clap::{Arg, ArgAction, Command}; use regex::Regex; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError, UUsageError}; use uucore::format_usage; @@ -195,7 +194,7 @@ struct WordRef { filename: OsString, } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum PtxError { #[error("{0}")] ParseError(ParseIntError), diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index f9aba615f51..d10b4a37ac9 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -18,7 +18,6 @@ use std::os::unix::ffi::OsStrExt; use std::os::unix::fs::PermissionsExt; use std::path::MAIN_SEPARATOR; use std::path::Path; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult}; use uucore::parser::shortcut_value_parser::ShortcutValueParser; @@ -29,7 +28,7 @@ mod platform; #[cfg(all(unix, not(target_os = "redox")))] use platform::{safe_remove_dir_recursive, safe_remove_empty_dir, safe_remove_file}; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum RmError { #[error("{}", translate!("rm-error-missing-operand", "util_name" => uucore::execution_phrase()))] MissingOperand, diff --git a/src/uu/runcon/src/errors.rs b/src/uu/runcon/src/errors.rs index 49dc83d16c2..3c07ff768e9 100644 --- a/src/uu/runcon/src/errors.rs +++ b/src/uu/runcon/src/errors.rs @@ -25,7 +25,7 @@ pub(crate) mod error_exit_status { pub const ANOTHER_ERROR: i32 = libc::EXIT_FAILURE; } -#[derive(thiserror::Error, Debug)] +#[derive(Debug, thiserror::Error)] pub(crate) enum Error { #[error("{}", translate!("runcon-error-no-command"))] MissingCommand, @@ -81,7 +81,7 @@ impl Error { } } -pub(crate) fn write_full_error(writer: &mut W, err: &dyn std::error::Error) -> std::fmt::Result +pub(crate) fn write_full_error(writer: &mut W, err: &dyn core::error::Error) -> std::fmt::Result where W: Write, { @@ -110,7 +110,7 @@ impl RunconError { } } -impl std::error::Error for RunconError {} +impl core::error::Error for RunconError {} impl UError for RunconError { fn code(&self) -> i32 { self.code diff --git a/src/uu/seq/src/error.rs b/src/uu/seq/src/error.rs index 2fd92938c10..7f69f007083 100644 --- a/src/uu/seq/src/error.rs +++ b/src/uu/seq/src/error.rs @@ -5,12 +5,11 @@ // spell-checker:ignore numberparse //! Errors returned by seq. use crate::numberparse::ParseNumberError; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::UError; use uucore::translate; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum SeqError { /// An error parsing the input arguments. /// diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 8b321b55d53..e1ce63c78e8 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -47,7 +47,6 @@ use std::path::Path; use std::path::PathBuf; use std::str::Utf8Error; use std::sync::OnceLock; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{FromIo, strip_errno}; use uucore::error::{UError, UResult, USimpleError, UUsageError}; @@ -135,7 +134,7 @@ const MIN_AUTOMATIC_BUF_SIZE: usize = 512 * 1024; // 512 KiB const FALLBACK_AUTOMATIC_BUF_SIZE: usize = 32 * 1024 * 1024; // 32 MiB const MAX_AUTOMATIC_BUF_SIZE: usize = 1024 * 1024 * 1024; // 1 GiB -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum SortError { #[error("{}", format_disorder(.file, .line_number, .line, .silent))] Disorder { diff --git a/src/uu/split/src/filenames.rs b/src/uu/split/src/filenames.rs index 68dc35aa215..fab1825fc95 100644 --- a/src/uu/split/src/filenames.rs +++ b/src/uu/split/src/filenames.rs @@ -41,7 +41,6 @@ use crate::{ use clap::ArgMatches; use std::ffi::{OsStr, OsString}; use std::path::is_separator; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{UResult, USimpleError}; use uucore::translate; @@ -81,7 +80,7 @@ pub struct Suffix { } /// An error when parsing suffix parameters from command-line arguments. -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum SuffixError { /// Invalid suffix length parameter. #[error("{}", translate!("split-error-suffix-not-parsable", "value" => .0.quote()))] diff --git a/src/uu/split/src/number.rs b/src/uu/split/src/number.rs index 58c08d12bac..fcc00ada08a 100644 --- a/src/uu/split/src/number.rs +++ b/src/uu/split/src/number.rs @@ -14,7 +14,6 @@ //! //! [radix]: https://en.wikipedia.org/wiki/Radix //! [positional notation]: https://en.wikipedia.org/wiki/Positional_notation -use std::error::Error; use std::fmt::{self, Display, Formatter, Write}; use uucore::translate; @@ -28,7 +27,7 @@ impl Display for Overflow { } } -impl Error for Overflow {} +impl core::error::Error for Overflow {} /// A number in arbitrary radix expressed in a positional notation. /// diff --git a/src/uu/split/src/platform/unix.rs b/src/uu/split/src/platform/unix.rs index c9e0964cc31..83bba279685 100644 --- a/src/uu/split/src/platform/unix.rs +++ b/src/uu/split/src/platform/unix.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use std::env; use std::ffi::{OsStr, OsString}; -use std::io::{BufWriter, Error, Result}; +use std::io::{BufWriter, Result}; use std::io::{ErrorKind, Write}; use std::path::Path; use std::process::{Child, Command, Stdio}; @@ -141,10 +141,10 @@ pub fn instantiate_current_writer( .truncate(true) .open(Path::new(filename)) .map_err(|e| match e.kind() { - ErrorKind::IsADirectory => Error::other( + ErrorKind::IsADirectory => std::io::Error::other( translate!("split-error-is-a-directory", "dir" => filename.quote()), ), - _ => Error::other( + _ => std::io::Error::other( translate!("split-error-unable-to-open-file", "file" => filename.quote()), ), })? @@ -154,7 +154,7 @@ pub fn instantiate_current_writer( .append(true) .open(Path::new(filename)) .map_err(|_| { - Error::other(translate!( + std::io::Error::other(translate!( "split-error-unable-to-reopen-file", "file" => filename.quote() )) diff --git a/src/uu/split/src/platform/windows.rs b/src/uu/split/src/platform/windows.rs index 3efef2240b9..ef323efe89d 100644 --- a/src/uu/split/src/platform/windows.rs +++ b/src/uu/split/src/platform/windows.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. use std::ffi::OsStr; -use std::io::{BufWriter, Error, Result}; +use std::io::{BufWriter, Result}; use std::io::{ErrorKind, Write}; use std::path::Path; use uucore::display::Quotable; @@ -27,10 +27,10 @@ pub fn instantiate_current_writer( .truncate(true) .open(Path::new(filename)) .map_err(|e| match e.kind() { - ErrorKind::IsADirectory => Error::other( + ErrorKind::IsADirectory => std::io::Error::other( translate!("split-error-is-a-directory", "dir" => filename.quote()), ), - _ => Error::other( + _ => std::io::Error::other( translate!("split-error-unable-to-open-file", "file" => filename.quote()), ), })? @@ -40,7 +40,7 @@ pub fn instantiate_current_writer( .append(true) .open(Path::new(filename)) .map_err(|_| { - Error::other( + std::io::Error::other( translate!("split-error-unable-to-reopen-file", "file" => filename.quote()), ) })? diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 596e6ffb986..2243c69d175 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -19,7 +19,6 @@ use std::fs::{File, metadata}; use std::io; use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Read, Seek, SeekFrom, Write, stdin}; use std::path::Path; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UIoError, UResult, USimpleError, UUsageError}; use uucore::translate; @@ -420,7 +419,7 @@ struct Settings { io_blksize: Option, } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] /// An error when parsing settings from command-line arguments. enum SettingsError { /// Invalid chunking strategy. diff --git a/src/uu/split/src/strategy.rs b/src/uu/split/src/strategy.rs index 6d567637d07..51ee7b65a6e 100644 --- a/src/uu/split/src/strategy.rs +++ b/src/uu/split/src/strategy.rs @@ -7,7 +7,6 @@ use crate::{OPT_BYTES, OPT_LINE_BYTES, OPT_LINES, OPT_NUMBER}; use clap::{ArgMatches, parser::ValueSource}; -use thiserror::Error; use uucore::{ display::Quotable, parser::parse_size::{ParseSizeError, parse_size_u64, parse_size_u64_max}, @@ -55,7 +54,7 @@ impl NumberType { } /// An error due to an invalid parameter to the `-n` command-line option. -#[derive(Debug, PartialEq, Error)] +#[derive(Debug, PartialEq, thiserror::Error)] pub enum NumberTypeError { /// The number of chunks was invalid. /// @@ -196,7 +195,7 @@ pub enum Strategy { } /// An error when parsing a chunking strategy from command-line arguments. -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum StrategyError { /// Invalid number of lines. #[error("{}", translate!("split-error-invalid-number-of-lines", "error" => .0))] diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index df5ee8ff743..51c77e15e24 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -27,10 +27,9 @@ use std::os::unix::fs::{FileTypeExt, MetadataExt}; use std::path::Path; use std::{env, fs}; -use thiserror::Error; use uucore::time::{FormatSystemTimeFallback, format_system_time, system_time_to_sec}; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum StatError { #[error("{}", translate!("stat-error-invalid-quoting-style", "style" => style.clone()))] InvalidQuotingStyle { style: String }, diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 0bf64922bdc..f4b4725d4bb 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -15,7 +15,6 @@ use std::path::PathBuf; use std::process; use tempfile::TempDir; use tempfile::tempdir; -use thiserror::Error; use uucore::error::{UResult, USimpleError, UUsageError}; use uucore::format_usage; use uucore::parser::parse_size::parse_size_u64; @@ -69,7 +68,7 @@ impl TryFrom<&ArgMatches> for ProgramOptions { } } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum ProgramOptionsError { #[error("{}", translate!("stdbuf-error-line-buffering-stdin-meaningless"))] LineBufferingStdinMeaningless, diff --git a/src/uu/tac/src/error.rs b/src/uu/tac/src/error.rs index 97caeb5d8f6..2356d7d095e 100644 --- a/src/uu/tac/src/error.rs +++ b/src/uu/tac/src/error.rs @@ -5,12 +5,11 @@ //! Errors returned by tac during processing of a file. use std::ffi::OsString; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{UError, strip_errno}; use uucore::translate; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum TacError { /// A regular expression given by the user is invalid. #[error("{}", translate!("tac-error-invalid-regex", "error" => .0))] diff --git a/src/uu/tee/src/tee.rs b/src/uu/tee/src/tee.rs index 792f1c8c2fc..0ce0288247f 100644 --- a/src/uu/tee/src/tee.rs +++ b/src/uu/tee/src/tee.rs @@ -7,7 +7,7 @@ use std::ffi::OsString; use std::fs::OpenOptions; -use std::io::{Error, ErrorKind, Read, Result, Write, stderr, stdin, stdout}; +use std::io::{ErrorKind, Read, Result, Write, stderr, stdin, stdout}; use std::path::PathBuf; use uucore::display::Quotable; use uucore::error::{UResult, strip_errno}; @@ -63,10 +63,10 @@ fn tee(options: &Options) -> Result<()> { // This is therefore just a clever way to stop all writers if options.ignore_interrupts { - ignore_interrupts().map_err(|_| Error::from(ErrorKind::Other))?; + ignore_interrupts().map_err(|_| std::io::Error::from(ErrorKind::Other))?; } if options.output_error.is_some() { - disable_pipe_errors().map_err(|_| Error::from(ErrorKind::Other))?; + disable_pipe_errors().map_err(|_| std::io::Error::from(ErrorKind::Other))?; } } let mut writers: Vec = options @@ -104,7 +104,7 @@ fn tee(options: &Options) -> Result<()> { }; if had_open_errors || res.is_err() || output.error_occurred() { - Err(Error::from(ErrorKind::Other)) + Err(std::io::Error::from(ErrorKind::Other)) } else { Ok(()) } @@ -216,7 +216,7 @@ impl MultiWriter { // This error kind will never be raised by the standard // library, so we can use it for early termination of // `copy` - Err(Error::from(ErrorKind::Other)) + Err(std::io::Error::from(ErrorKind::Other)) } else { Ok(()) }, @@ -227,7 +227,7 @@ impl MultiWriter { fn process_error( mode: Option, - e: Error, + e: std::io::Error, writer: &NamedWriter, ignored_errors: &mut usize, ) -> Result<()> { diff --git a/src/uu/test/src/error.rs b/src/uu/test/src/error.rs index cd9c071acb1..c3427871cbc 100644 --- a/src/uu/test/src/error.rs +++ b/src/uu/test/src/error.rs @@ -3,11 +3,10 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use thiserror::Error; use uucore::translate; /// Represents an error encountered while parsing a test expression -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] pub enum ParseError { #[error("{}", translate!("test-error-expected-value"))] ExpectedValue, diff --git a/src/uu/touch/src/error.rs b/src/uu/touch/src/error.rs index 47823cde93d..16d180a5330 100644 --- a/src/uu/touch/src/error.rs +++ b/src/uu/touch/src/error.rs @@ -6,12 +6,11 @@ // spell-checker:ignore (misc) uioerror use filetime::FileTime; use std::path::PathBuf; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{UError, UIoError}; use uucore::translate; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum TouchError { #[error("{}", translate!("touch-error-unable-to-parse-date", "date" => .0.clone()))] InvalidDateFormat(String), diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index bcb688ee7b3..011377f4b40 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -26,7 +26,7 @@ use std::ffi::{OsStr, OsString}; #[cfg(unix)] use std::fs::OpenOptions; use std::fs::{self, File}; -use std::io::{Error, ErrorKind}; +use std::io::ErrorKind; #[cfg(unix)] use std::os::unix::fs::OpenOptionsExt; use std::path::{Path, PathBuf}; @@ -497,7 +497,8 @@ fn touch_file( false }; if is_directory { - let custom_err = Error::other(translate!("touch-error-no-such-file-or-directory")); + let custom_err = + std::io::Error::other(translate!("touch-error-no-such-file-or-directory")); return Err(custom_err.map_err_context( || translate!("touch-error-cannot-touch", "filename" => filename.quote()), )); @@ -628,7 +629,7 @@ fn try_futimens_via_write_fd(path: &Path, atime: FileTime, mtime: FileTime) -> s }, }; - futimens(&file, ×tamps).map_err(|e| Error::from_raw_os_error(e.raw_os_error())) + futimens(&file, ×tamps).map_err(|e| std::io::Error::from_raw_os_error(e.raw_os_error())) } /// Get metadata of the provided path diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index 3ea96ab18e6..dd14c2a67dc 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -17,7 +17,6 @@ use nom::{ }; use std::{ char, - error::Error, fmt::{Debug, Display}, io::{BufRead, Write}, }; @@ -136,7 +135,7 @@ impl Display for BadSequence { } } -impl Error for BadSequence {} +impl core::error::Error for BadSequence {} impl UError for BadSequence {} #[derive(Debug, Clone, Copy)] diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index c6a6829d67b..540ddb75064 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -13,7 +13,6 @@ use std::fs::File; use std::io::{self, BufRead, BufReader}; use string_interner::StringInterner; use string_interner::backend::BucketBackend; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{UError, UResult, USimpleError}; use uucore::{format_usage, show, translate}; @@ -131,7 +130,7 @@ pub fn uu_app() -> Command { ) } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum TsortError { /// The input file is actually a directory. #[error("{input}: {message}", input = .0.maybe_quote(), message = translate!("tsort-error-is-dir"))] @@ -154,7 +153,7 @@ enum TsortError { } // Auxiliary struct, just for printing loop nodes via show! macro -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] #[error("{0}")] struct LoopNode<'a>(&'a str); diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index 840858c6519..4298b820e7e 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -12,7 +12,6 @@ use std::io::{self, BufReader, BufWriter, Read, Stdin, Stdout, Write, stdin, std use std::num::IntErrorKind; use std::path::Path; use std::str::from_utf8; -use thiserror::Error; use uucore::display::Quotable; use uucore::error::{FromIo, UError, UResult, USimpleError, set_exit_code}; use uucore::translate; @@ -20,7 +19,7 @@ use uucore::{format_usage, show}; const DEFAULT_TABSTOP: usize = 8; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum ParseError { #[error("{}", translate!("unexpand-error-invalid-character", "char" => _0.quote()))] InvalidCharacter(String), diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 2355da2a20f..95e7b49cc22 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -4,8 +4,7 @@ // file that was distributed with this source code. // spell-checker:ignore badoption CTYPE use clap::{ - Arg, ArgAction, ArgMatches, Command, builder::ValueParser, error::ContextKind, error::Error, - error::ErrorKind, + Arg, ArgAction, ArgMatches, Command, builder::ValueParser, error::ContextKind, error::ErrorKind, }; use std::ffi::{OsStr, OsString}; use std::fs::File; @@ -606,7 +605,7 @@ fn handle_extract_obs_skip_chars( /// Unfortunately these overrides are necessary, since several GNU tests /// for `uniq` hardcode and require the exact wording of the error message /// and it is not compatible with how Clap formats and displays those error messages. -fn map_clap_errors(clap_error: Error) -> Box { +fn map_clap_errors(clap_error: clap::error::Error) -> Box { let footer = translate!("uniq-error-try-help"); let override_arg_conflict = translate!("uniq-error-group-mutually-exclusive") + "\n" + &footer; let override_group_badoption = translate!("uniq-error-group-badoption") + "\n" + &footer; diff --git a/src/uu/uptime/src/uptime.rs b/src/uu/uptime/src/uptime.rs index 2c610409851..beed08d97e9 100644 --- a/src/uu/uptime/src/uptime.rs +++ b/src/uu/uptime/src/uptime.rs @@ -13,7 +13,6 @@ use jiff::{Timestamp, ToSpan}; #[cfg(unix)] use std::ffi::OsString; use std::io::{self, Write, stdout}; -use thiserror::Error; use uucore::error::{UError, UResult}; use uucore::format_usage; use uucore::libc::time_t; @@ -33,7 +32,7 @@ pub mod options { pub static PRETTY: &str = "pretty"; } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum UptimeError { // io::Error wrapper #[error("{}", translate!("uptime-error-io", "error" => format!("{}", .0)))] diff --git a/src/uu/wc/src/utf8/read.rs b/src/uu/wc/src/utf8/read.rs index 6364c45df17..b76fa30ca74 100644 --- a/src/uu/wc/src/utf8/read.rs +++ b/src/uu/wc/src/utf8/read.rs @@ -5,7 +5,6 @@ // spell-checker:ignore bytestream use super::{Incomplete, str}; use std::io::{self, BufRead}; -use thiserror::Error; use uucore::translate; /// Wraps a `std::io::BufRead` buffered byte stream and decode it as UTF-8. @@ -15,7 +14,7 @@ pub struct BufReadDecoder { incomplete: Incomplete, } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum BufReadDecoderError<'a> { /// Represents one UTF-8 error in the byte stream. /// diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 8b6b8dc4175..10b114ed990 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -23,7 +23,6 @@ use std::{ }; use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser}; -use thiserror::Error; use unicode_width::UnicodeWidthChar; use utf8::{BufReadDecoder, BufReadDecoderError}; use uucore::{display::Quotable, translate}; @@ -345,7 +344,7 @@ impl TotalWhen { } } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] enum WcError { #[error("{}", translate!("wc-error-files-disabled", "extra" => extra.quote()))] FilesDisabled { extra: Cow<'static, OsStr> }, diff --git a/src/uucore/build.rs b/src/uucore/build.rs index 2aa46d24961..120e0270f93 100644 --- a/src/uucore/build.rs +++ b/src/uucore/build.rs @@ -8,7 +8,7 @@ use std::fs::File; use std::io::Write; use std::path::{Path, PathBuf}; -pub fn main() -> Result<(), Box> { +pub fn main() -> Result<(), Box> { let out_dir = env::var("OUT_DIR")?; let mut embedded_file = File::create(Path::new(&out_dir).join("embedded_locales.rs"))?; @@ -63,7 +63,7 @@ pub fn main() -> Result<(), Box> { /// /// Returns an error if the `CARGO_MANIFEST_DIR` environment variable is not set /// or if the current directory structure does not allow determining the project root. -fn project_root() -> Result> { +fn project_root() -> Result> { let manifest_dir = env::var("CARGO_MANIFEST_DIR")?; let uucore_path = Path::new(&manifest_dir); @@ -135,7 +135,7 @@ fn embed_single_utility_locale( project_root: &Path, util_name: &str, locales_to_embed: &(String, Option), -) -> Result<(), Box> { +) -> Result<(), Box> { // Embed utility-specific locales embed_component_locales(embedded_file, locales_to_embed, util_name, |locale| { project_root @@ -171,7 +171,7 @@ fn embed_all_utility_locales( embedded_file: &mut File, project_root: &Path, locales_to_embed: &(String, Option), -) -> Result<(), Box> { +) -> Result<(), Box> { use std::fs; // Discover all uu_* directories @@ -221,7 +221,7 @@ fn embed_all_utility_locales( fn embed_static_utility_locales( embedded_file: &mut File, locales_to_embed: &(String, Option), -) -> Result<(), Box> { +) -> Result<(), Box> { use std::env; writeln!( @@ -294,9 +294,9 @@ fn get_locales_to_embed() -> (String, Option) { fn for_each_locale( locales: &(String, Option), mut f: F, -) -> Result<(), Box> +) -> Result<(), Box> where - F: FnMut(&str) -> Result<(), Box>, + F: FnMut(&str) -> Result<(), Box>, { f(&locales.0)?; if let Some(ref system_locale) = locales.1 { @@ -317,7 +317,7 @@ fn embed_locale_file( locale_key: &str, locale: &str, component: &str, -) -> Result<(), Box> { +) -> Result<(), Box> { use std::fs; if locale_path.exists() || locale_path.is_file() { @@ -359,7 +359,7 @@ fn embed_all_locales_for_component( embedded_file: &mut File, component_name: &str, path_builder: &F, -) -> Result<(), Box> +) -> Result<(), Box> where F: Fn(&str) -> PathBuf, { @@ -391,7 +391,7 @@ fn embed_component_locales( locales: &(String, Option), component_name: &str, path_builder: F, -) -> Result<(), Box> +) -> Result<(), Box> where F: Fn(&str) -> PathBuf, { diff --git a/src/uucore/src/lib/features/backup_control.rs b/src/uucore/src/lib/features/backup_control.rs index f56d131c7d6..944e1de28cf 100644 --- a/src/uucore/src/lib/features/backup_control.rs +++ b/src/uucore/src/lib/features/backup_control.rs @@ -88,7 +88,6 @@ use crate::{ use clap::ArgMatches; use std::{ env, - error::Error, ffi::{OsStr, OsString}, fmt::{Debug, Display}, path::{Path, PathBuf}, @@ -169,7 +168,7 @@ impl UError for BackupError { } } -impl Error for BackupError {} +impl core::error::Error for BackupError {} impl Display for BackupError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/src/uucore/src/lib/features/buf_copy/common.rs b/src/uucore/src/lib/features/buf_copy/common.rs index d771ff6be77..c144159a40a 100644 --- a/src/uucore/src/lib/features/buf_copy/common.rs +++ b/src/uucore/src/lib/features/buf_copy/common.rs @@ -21,7 +21,7 @@ impl std::fmt::Display for Error { } } -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl UError for Error { fn code(&self) -> i32 { diff --git a/src/uucore/src/lib/features/checksum/mod.rs b/src/uucore/src/lib/features/checksum/mod.rs index d18e2adaad8..ccc881d552d 100644 --- a/src/uucore/src/lib/features/checksum/mod.rs +++ b/src/uucore/src/lib/features/checksum/mod.rs @@ -10,7 +10,6 @@ use std::io::{self, Read}; use std::num::IntErrorKind; use os_display::Quotable; -use thiserror::Error; use crate::error::{UError, UResult}; use crate::show_error; @@ -392,7 +391,7 @@ impl SizedAlgoKind { } } -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum ChecksumError { #[error("the --raw option is not supported with multiple files")] RawMultipleFiles, diff --git a/src/uucore/src/lib/features/entries.rs b/src/uucore/src/lib/features/entries.rs index 81c34110aee..a048769cce0 100644 --- a/src/uucore/src/lib/features/entries.rs +++ b/src/uucore/src/lib/features/entries.rs @@ -39,7 +39,6 @@ use libc::{getgrgid, getgrnam, getgroups}; use libc::{getpwnam, getpwuid, group, passwd}; use std::ffi::{CStr, CString}; -use std::io::Error as IOError; use std::io::ErrorKind; use std::io::Result as IOResult; use std::ptr; @@ -68,7 +67,7 @@ pub fn get_groups() -> IOResult> { let mut groups = Vec::new(); loop { let ngroups = match unsafe { getgroups(0, ptr::null_mut()) } { - -1 => return Err(IOError::last_os_error()), + -1 => return Err(std::io::Error::last_os_error()), // Not just optimization; 0 would mess up the next call 0 => return Ok(Vec::new()), n => n, @@ -79,7 +78,7 @@ pub fn get_groups() -> IOResult> { groups.resize(ngroups.try_into().unwrap(), 0); let res = unsafe { getgroups(ngroups, groups.as_mut_ptr()) }; if res == -1 { - let err = IOError::last_os_error(); + let err = std::io::Error::last_os_error(); if err.raw_os_error() == Some(libc::EINVAL) { // Number of groups has increased, retry } else { @@ -299,7 +298,7 @@ macro_rules! f { // errno must be set to zero before the call. We can // use libc::__errno_location() on some platforms. // The same applies for the two cases below. - Err(IOError::new( + Err(std::io::Error::new( ErrorKind::NotFound, format!("No such id: {k}"), )) @@ -326,13 +325,16 @@ macro_rules! f { if !data.is_null() { Ok($st::from_raw(ptr::read(data.cast_const()))) } else { - Err(IOError::new( + Err(std::io::Error::new( ErrorKind::NotFound, format!("No such id: {id}"), )) } } else { - Err(IOError::new(ErrorKind::NotFound, format!("Not found: {k}"))) + Err(std::io::Error::new( + ErrorKind::NotFound, + format!("Not found: {k}"), + )) } } } diff --git a/src/uucore/src/lib/features/format/mod.rs b/src/uucore/src/lib/features/format/mod.rs index 66e4d8bdedd..f172dc1ec01 100644 --- a/src/uucore/src/lib/features/format/mod.rs +++ b/src/uucore/src/lib/features/format/mod.rs @@ -45,7 +45,6 @@ use self::{escape::parse_escape_code, num_format::Formatter}; use crate::{NonUtf8OsStrError, error::UError}; pub use spec::Spec; use std::{ - error::Error, fmt::Display, io::{Write, stdout}, marker::PhantomData, @@ -74,7 +73,7 @@ pub enum FormatError { InvalidEncoding(NonUtf8OsStrError), } -impl Error for FormatError {} +impl core::error::Error for FormatError {} impl UError for FormatError {} impl From for FormatError { diff --git a/src/uucore/src/lib/features/fs.rs b/src/uucore/src/lib/features/fs.rs index d165b8a9f68..70dc9186c54 100644 --- a/src/uucore/src/lib/features/fs.rs +++ b/src/uucore/src/lib/features/fs.rs @@ -21,7 +21,7 @@ use std::fs; use std::fs::read_dir; use std::hash::Hash; use std::io::Stdin; -use std::io::{Error, ErrorKind, Result as IOResult}; +use std::io::{ErrorKind, Result as IOResult}; #[cfg(unix)] use std::os::fd::AsFd; #[cfg(unix)] @@ -427,7 +427,7 @@ pub fn canonicalize>( path_to_follow.push(part.as_os_str()); } if !visited_files.insert((file_info, path_to_follow)) { - return Err(Error::new( + return Err(std::io::Error::new( ErrorKind::InvalidInput, "Too many levels of symbolic links", )); // TODO use ErrorKind::FilesystemLoop when stable @@ -917,7 +917,7 @@ pub fn make_fifo(path: &Path) -> std::io::Result<()> { let name = CString::new(path.to_str().unwrap()).unwrap(); let err = unsafe { mkfifo(name.as_ptr(), 0o666) }; if err == -1 { - Err(Error::from_raw_os_error(err)) + Err(std::io::Error::from_raw_os_error(err)) } else { Ok(()) } diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 0ede0f2875f..3b780d51a96 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -65,8 +65,6 @@ use libc::{ }; #[cfg(unix)] use std::ffi::{CStr, CString}; -#[cfg(not(target_os = "wasi"))] -use std::io::Error as IOError; #[cfg(unix)] use std::mem; #[cfg(windows)] @@ -501,7 +499,7 @@ pub fn read_fs_list() -> UResult> { let find_handle = unsafe { FindFirstVolumeW(volume_name_buf.as_mut_ptr(), volume_name_buf.len() as u32) }; if INVALID_HANDLE_VALUE == find_handle { - let os_err = IOError::last_os_error(); + let os_err = std::io::Error::last_os_error(); let msg = format!("FindFirstVolumeW failed: {os_err}"); return Err(USimpleError::new(EXIT_ERR, msg)); } @@ -522,7 +520,7 @@ pub fn read_fs_list() -> UResult> { volume_name_buf.len() as u32, ) } { - let err = IOError::last_os_error(); + let err = std::io::Error::last_os_error(); if err.raw_os_error() != Some(ERROR_NO_MORE_FILES as i32) { let msg = format!("FindNextVolumeW failed: {err}"); return Err(USimpleError::new(EXIT_ERR, msg)); @@ -638,7 +636,7 @@ impl FsUsage { if 0 == success { let msg = format!( "GetVolumePathNamesForVolumeNameW failed: {}", - IOError::last_os_error() + std::io::Error::last_os_error() ); return Err(USimpleError::new(EXIT_ERR, msg)); } @@ -924,7 +922,7 @@ pub fn statfs(path: &OsStr) -> Result { if statfs_fn(p.as_ptr(), &raw mut buffer) == 0 { Ok(buffer) } else { - let errno = IOError::last_os_error().raw_os_error().unwrap_or(0); + let errno = std::io::Error::last_os_error().raw_os_error().unwrap_or(0); Err(CStr::from_ptr(strerror(errno)) .to_str() .map_err(|_| "Error message contains invalid UTF-8".to_owned())? diff --git a/src/uucore/src/lib/features/parser/parse_size.rs b/src/uucore/src/lib/features/parser/parse_size.rs index 15a6d58b8c5..2ec9f3cec5b 100644 --- a/src/uucore/src/lib/features/parser/parse_size.rs +++ b/src/uucore/src/lib/features/parser/parse_size.rs @@ -42,7 +42,6 @@ pub const IEC_BASES: [u128; 11] = [ 1_267_650_600_228_229_401_496_703_205_376, ]; -use std::error::Error; use std::fmt; use std::num::{IntErrorKind, ParseIntError}; @@ -485,7 +484,7 @@ pub enum ParseSizeError { PhysicalMem(String), } -impl Error for ParseSizeError { +impl core::error::Error for ParseSizeError { fn description(&self) -> &str { match *self { Self::InvalidSuffix(ref s) => s, diff --git a/src/uucore/src/lib/features/perms.rs b/src/uucore/src/lib/features/perms.rs index 79a51b0ccad..b6c88ae1b15 100644 --- a/src/uucore/src/lib/features/perms.rs +++ b/src/uucore/src/lib/features/perms.rs @@ -26,7 +26,6 @@ use crate::features::safe_traversal::{DirFd, SymlinkBehavior}; use std::ffi::CString; use std::fs::Metadata; -use std::io::Error as IOError; use std::io::Result as IOResult; use std::os::unix::fs::MetadataExt; @@ -71,7 +70,7 @@ fn chown>(path: P, uid: uid_t, gid: gid_t, follow: bool) -> IORes if ret == 0 { Ok(()) } else { - Err(IOError::last_os_error()) + Err(std::io::Error::last_os_error()) } } diff --git a/src/uucore/src/lib/features/safe_traversal.rs b/src/uucore/src/lib/features/safe_traversal.rs index 0b7d4f710dc..fae4acf7af5 100644 --- a/src/uucore/src/lib/features/safe_traversal.rs +++ b/src/uucore/src/lib/features/safe_traversal.rs @@ -59,7 +59,7 @@ impl From for SymlinkBehavior { } // Custom error types for better error reporting -#[derive(thiserror::Error, Debug)] +#[derive(Debug, thiserror::Error)] pub enum SafeTraversalError { #[error("{}", translate!("safe-traversal-error-path-contains-null"))] PathContainsNull, diff --git a/src/uucore/src/lib/features/selinux.rs b/src/uucore/src/lib/features/selinux.rs index 28c68a1b6cf..a0b49795345 100644 --- a/src/uucore/src/lib/features/selinux.rs +++ b/src/uucore/src/lib/features/selinux.rs @@ -5,16 +5,14 @@ //! Set of functions to manage SELinux security contexts -use std::error::Error; use std::path::Path; use crate::translate; use selinux::SecurityContext; -use thiserror::Error; use crate::error::UError; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum SeLinuxError { #[error("{}", translate!("selinux-error-not-enabled"))] SELinuxNotEnabled, @@ -63,7 +61,7 @@ pub fn is_selinux_enabled() -> bool { } /// Returns a string describing the error and its causes. -pub fn selinux_error_description(mut error: &dyn Error) -> String { +pub fn selinux_error_description(mut error: &dyn core::error::Error) -> String { let mut description = String::new(); while let Some(source) = error.source() { let error_text = source.to_string(); diff --git a/src/uucore/src/lib/features/smack.rs b/src/uucore/src/lib/features/smack.rs index 375db8859a6..188b298420b 100644 --- a/src/uucore/src/lib/features/smack.rs +++ b/src/uucore/src/lib/features/smack.rs @@ -12,12 +12,10 @@ use std::io::{self, Read, Write}; use std::path::Path; use std::sync::OnceLock; -use thiserror::Error; - use crate::error::{UError, USimpleError, strip_errno}; use crate::translate; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum SmackError { #[error("{}", translate!("smack-error-not-enabled"))] SmackNotEnabled, diff --git a/src/uucore/src/lib/features/systemd_logind.rs b/src/uucore/src/lib/features/systemd_logind.rs index 4c5370838d1..014db249035 100644 --- a/src/uucore/src/lib/features/systemd_logind.rs +++ b/src/uucore/src/lib/features/systemd_logind.rs @@ -49,7 +49,7 @@ mod login { use std::time::SystemTime; /// Get all active sessions - pub fn get_sessions() -> Result, Box> { + pub fn get_sessions() -> Result, Box> { let mut sessions_ptr: *mut *mut libc::c_char = ptr::null_mut(); let result = unsafe { ffi::sd_get_sessions(&raw mut sessions_ptr) }; @@ -81,7 +81,7 @@ mod login { } /// Get UID for a session - pub fn get_session_uid(session_id: &str) -> Result> { + pub fn get_session_uid(session_id: &str) -> Result> { let session_cstring = CString::new(session_id)?; let mut uid: std::os::raw::c_uint = 0; @@ -97,7 +97,7 @@ mod login { } /// Get start time for a session (in microseconds since Unix epoch) - pub fn get_session_start_time(session_id: &str) -> Result> { + pub fn get_session_start_time(session_id: &str) -> Result> { let session_cstring = CString::new(session_id)?; let mut usec: u64 = 0; @@ -115,7 +115,9 @@ mod login { } /// Get TTY for a session - pub fn get_session_tty(session_id: &str) -> Result, Box> { + pub fn get_session_tty( + session_id: &str, + ) -> Result, Box> { let session_cstring = CString::new(session_id)?; let mut tty_ptr: *mut libc::c_char = ptr::null_mut(); @@ -142,7 +144,7 @@ mod login { /// Get remote host for a session pub fn get_session_remote_host( session_id: &str, - ) -> Result, Box> { + ) -> Result, Box> { let session_cstring = CString::new(session_id)?; let mut host_ptr: *mut libc::c_char = ptr::null_mut(); @@ -171,7 +173,7 @@ mod login { /// Get display for a session pub fn get_session_display( session_id: &str, - ) -> Result, Box> { + ) -> Result, Box> { let session_cstring = CString::new(session_id)?; let mut display_ptr: *mut libc::c_char = ptr::null_mut(); @@ -200,7 +202,7 @@ mod login { /// Get type for a session pub fn get_session_type( session_id: &str, - ) -> Result, Box> { + ) -> Result, Box> { let session_cstring = CString::new(session_id)?; let mut type_ptr: *mut libc::c_char = ptr::null_mut(); @@ -228,7 +230,7 @@ mod login { /// Get seat for a session pub fn get_session_seat( session_id: &str, - ) -> Result, Box> { + ) -> Result, Box> { let session_cstring = CString::new(session_id)?; let mut seat_ptr: *mut libc::c_char = ptr::null_mut(); @@ -263,7 +265,7 @@ mod login { /// /// Ideally, both should use the same source (KernelTimestamp) for semantic consistency. /// Consider proposing to GNU coreutils to use systemd's KernelTimestamp property instead. - pub fn get_boot_time() -> Result> { + pub fn get_boot_time() -> Result> { use std::fs; let metadata = fs::metadata("/var/lib/systemd/random-seed") diff --git a/src/uucore/src/lib/features/uptime.rs b/src/uucore/src/lib/features/uptime.rs index 8d33cd081a2..b89506a3713 100644 --- a/src/uucore/src/lib/features/uptime.rs +++ b/src/uucore/src/lib/features/uptime.rs @@ -17,9 +17,8 @@ use crate::translate; use jiff::Timestamp; use jiff::tz::TimeZone; use libc::time_t; -use thiserror::Error; -#[derive(Debug, Error)] +#[derive(Debug, thiserror::Error)] pub enum UptimeError { #[error("{}", translate!("uptime-lib-error-system-uptime"))] SystemUptime, diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 27548688987..d72c045b6f2 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -429,7 +429,7 @@ impl std::fmt::Display for NonUtf8OsStrError { } } -impl std::error::Error for NonUtf8OsStrError {} +impl core::error::Error for NonUtf8OsStrError {} impl error::UError for NonUtf8OsStrError {} /// Converts an `OsStr` to a UTF-8 `&[u8]`. diff --git a/src/uucore/src/lib/mods/clap_localization.rs b/src/uucore/src/lib/mods/clap_localization.rs index fc4f838c216..afb849b2a91 100644 --- a/src/uucore/src/lib/mods/clap_localization.rs +++ b/src/uucore/src/lib/mods/clap_localization.rs @@ -17,7 +17,7 @@ use crate::locale::translate; use clap::error::{ContextKind, ErrorKind}; use clap::{ArgMatches, Command, Error}; -use std::error::Error as StdError; +use core::error::Error as _; use std::ffi::OsString; use std::io::Write as _; diff --git a/src/uucore/src/lib/mods/error.rs b/src/uucore/src/lib/mods/error.rs index d2239d12875..7ef70f570dd 100644 --- a/src/uucore/src/lib/mods/error.rs +++ b/src/uucore/src/lib/mods/error.rs @@ -24,7 +24,7 @@ //! } //! ``` //! [`UResult`] is a simple wrapper around [`Result`] with a custom error trait: [`UError`]. The -//! most important difference with types implementing [`std::error::Error`] is that [`UError`]s +//! most important difference with types implementing [`core::error::Error`] is that [`UError`]s //! can specify the exit code of the program when they are returned from `uumain`: //! * When `Ok` is returned, the code set with [`set_exit_code`] is used as exit code. If //! [`set_exit_code`] was not used, then `0` is used. @@ -56,7 +56,6 @@ use std::{ cell::Cell, - error::Error, fmt::{Display, Formatter}, io::Write, sync::atomic::{AtomicI32, Ordering}, @@ -98,7 +97,7 @@ pub type UResult = Result>; /// Custom errors defined by the utils and `uucore`. /// -/// All errors should implement [`std::error::Error`], [`std::fmt::Display`] and +/// All errors should implement [`core::error::Error`], [`std::fmt::Display`] and /// [`std::fmt::Debug`] and have an additional `code` method that specifies the /// exit code of the program if the error is returned from `uumain`. /// @@ -110,7 +109,6 @@ pub type UResult = Result>; /// error::{UError, UResult} /// }; /// use std::{ -/// error::Error, /// fmt::{Display, Debug}, /// path::PathBuf /// }; @@ -130,7 +128,7 @@ pub type UResult = Result>; /// } /// } /// -/// impl Error for LsError {} +/// impl core::error::Error for LsError {} /// /// impl Display for LsError { /// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -157,7 +155,7 @@ pub type UResult = Result>; /// /// A crate like [`quick_error`](https://crates.io/crates/quick-error) might /// also be used, but will still require an `impl` for the `code` method. -pub trait UError: Error + Send { +pub trait UError: core::error::Error + Send { /// Error code of a custom error. /// /// Set a return value for each variant of an enum-type to associate an @@ -172,7 +170,6 @@ pub trait UError: Error + Send { /// error::UError /// }; /// use std::{ - /// error::Error, /// fmt::{Display, Debug}, /// path::PathBuf /// }; @@ -195,7 +192,7 @@ pub trait UError: Error + Send { /// } /// } /// - /// impl Error for MyError {} + /// impl core::error::Error for MyError {} /// /// impl Display for MyError { /// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -226,7 +223,6 @@ pub trait UError: Error + Send { /// error::UError /// }; /// use std::{ - /// error::Error, /// fmt::{Display, Debug}, /// path::PathBuf /// }; @@ -249,7 +245,7 @@ pub trait UError: Error + Send { /// } /// } /// - /// impl Error for MyError {} + /// impl core::error::Error for MyError {} /// /// impl Display for MyError { /// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -305,7 +301,7 @@ impl USimpleError { } } -impl Error for USimpleError {} +impl core::error::Error for USimpleError {} impl Display for USimpleError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { @@ -340,7 +336,7 @@ impl UUsageError { } } -impl Error for UUsageError {} +impl core::error::Error for UUsageError {} impl Display for UUsageError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { @@ -403,7 +399,7 @@ impl UIoError { impl UError for UIoError {} -impl Error for UIoError {} +impl core::error::Error for UIoError {} impl Display for UIoError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { @@ -659,7 +655,7 @@ impl ExitCode { } } -impl Error for ExitCode {} +impl core::error::Error for ExitCode {} impl Display for ExitCode { fn fmt(&self, _: &mut Formatter<'_>) -> Result<(), std::fmt::Error> { @@ -753,7 +749,7 @@ impl UError for ClapErrorWrapper { } } -impl Error for ClapErrorWrapper {} +impl core::error::Error for ClapErrorWrapper {} // This is abuse of the Display trait impl Display for ClapErrorWrapper { diff --git a/src/uucore/src/lib/mods/locale.rs b/src/uucore/src/lib/mods/locale.rs index 99afc8c0c8a..f813e465b7b 100644 --- a/src/uucore/src/lib/mods/locale.rs +++ b/src/uucore/src/lib/mods/locale.rs @@ -16,10 +16,9 @@ use std::str::FromStr; use std::sync::OnceLock; use os_display::Quotable; -use thiserror::Error; use unic_langid::LanguageIdentifier; -#[derive(Error, Debug)] +#[derive(Debug, thiserror::Error)] pub enum LocalizationError { #[error("I/O error loading '{path}': {source}")] Io { diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index 1ccec792d41..1553d6941bd 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -876,7 +876,7 @@ fn test_version_help_dev_full() { fn test_cat_eintr_handling() { // Test that cat properly handles EINTR (ErrorKind::Interrupted) during I/O operations // This verifies the signal interruption retry logic added in the EINTR handling fix - use std::io::{Error, ErrorKind, Read}; + use std::io::{ErrorKind, Read}; use std::sync::{Arc, Mutex}; // Create a mock reader that simulates EINTR interruptions @@ -893,7 +893,7 @@ fn test_cat_eintr_handling() { let mut count = self.interrupt_count.lock().unwrap(); if *count == 0 { *count += 1; - return Err(Error::new( + return Err(std::io::Error::new( ErrorKind::Interrupted, "Simulated signal interruption", ));