Skip to content

Commit

Permalink
Replaced quick_error with thiserror and added some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AnirbanHalder654322 committed Jun 21, 2024
1 parent 4a8c460 commit 2b94a69
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ rlimit = "0.10.1"
rand_pcg = "0.3.1"
xattr = { workspace = true }


# Specfically used in test_uptime::test_uptime_with_file_containing_valid_boot_time_utmpx_record
# to create a deserialize a utmpx struct into a binary file
[target.'cfg(all(target_family= "unix",not(target_os = "macos")))'.dev-dependencies]
serde = { version = "1.0.202", features = ["derive"] }
bincode = { version = "1.3.3" }
Expand Down
2 changes: 1 addition & 1 deletion src/uu/uptime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/uptime.rs"
chrono = { workspace = true }
clap = { workspace = true }
uucore = { workspace = true, features = ["libc", "utmpx"] }
quick-error = { workspace = true }
thiserror = {workspace = true}

[[bin]]
name = "uptime"
Expand Down
28 changes: 11 additions & 17 deletions src/uu/uptime/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use crate::options;
use crate::uu_app;
use chrono::{Local, TimeZone, Utc};
use clap::ArgMatches;
use quick_error::quick_error;
use std::ffi::OsString;
use std::fs;
use std::io;
use std::os::unix::fs::FileTypeExt;
use thiserror::Error;
use uucore::error::set_exit_code;
use uucore::error::UError;
use uucore::show_error;
Expand All @@ -28,25 +28,19 @@ use uucore::libc::getloadavg;
extern "C" {
fn GetTickCount() -> uucore::libc::uint32_t;
}
quick_error! {
#[derive(Debug)]
pub enum UptimeError {
#[derive(Debug, Error)]
pub enum UptimeError {
// io::Error wrapper
IoErr(err: io::Error) {
display("couldn't get boot time: {}",err)
#[error("couldn't get boot time: {0}")]
IoErr(#[from] io::Error),

}
TargetIsDir{
display("couldn't get boot time: Is a directory")
}
TargetIsFifo{
display("couldn't get boot time: Illegal seek")
}
#[error("couldn't get boot time: Is a directory")]
TargetIsDir,

ExtraOperandError(err: String){
display("extra operand '{}'",err)
}
}
#[error("couldn't get boot time: Illegal seek")]
TargetIsFifo,
#[error("extra operand '{0}'")]
ExtraOperandError(String),
}
impl UError for UptimeError {
fn code(&self) -> i32 {
Expand Down

0 comments on commit 2b94a69

Please sign in to comment.