Skip to content

Commit

Permalink
replace failure with anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
arcnmx committed Aug 5, 2021
1 parent 8ec1815 commit 7affb88
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 127 deletions.
117 changes: 13 additions & 104 deletions 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 @@ -12,7 +12,7 @@ screenstub-ddc = { path = "ddc" }
screenstub-x = { path = "x" }
input-linux = { version = "^0.5.0", features = ["with-tokio"] }
tokio = { version = "^1.0.0", default-features = false, features = ["process", "rt-multi-thread"] }
failure = "^0.1.1"
anyhow = "^1.0.42"
futures = { version = "^0.3.5", features = ["thread-pool"] }
clap = "^2.30.0"
env_logger = "^0.8.1"
Expand Down Expand Up @@ -41,3 +41,4 @@ members = [
[patch.crates-io]
#qapi = { path = "../qapi-rs/qapi" }
qapi = { git = "https://github.com/arcnmx/qapi-rs.git", branch = "codegen-from-impls" }
ddc-hi = { git = "https://github.com/arcnmx/ddc-hi-rs.git", branch = "master" }
5 changes: 2 additions & 3 deletions ddc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ edition = "2018"

[dependencies]
ddcutil = { version = "^0.0.3", optional = true }
ddc-hi = { version = "^0.3.0", optional = true }
ddc-hi = { version = "^0.4.0", optional = true }
mccs = { version = "^0.1.0", optional = true }
failure = "^0.1.1"
failure_derive = "^0.1.1"
anyhow = "^1.0.42"

[features]
with-ddcutil = ["ddcutil"]
Expand Down
2 changes: 1 addition & 1 deletion ddc/src/ddc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;
use ddc_hi::{Display, Query, Ddc};
use crate::{SearchDisplay, DdcMonitor, FEATURE_CODE_INPUT};
use failure::Error;
use anyhow::Error;

pub struct Monitor {
display: Display,
Expand Down
2 changes: 1 addition & 1 deletion ddc/src/ddcutil.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::mem::replace;
use std::fmt;
use failure::Error;
use anyhow::Error;
use ddcutil::{DisplayInfo, Display, FeatureInfo};
use crate::{DdcError, DdcMonitor, SearchDisplay, FEATURE_CODE_INPUT};

Expand Down
18 changes: 14 additions & 4 deletions ddc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt;
use failure::{Error, format_err};
use anyhow::{Error, format_err};

#[cfg(feature = "ddcutil")]
pub mod ddcutil;
Expand All @@ -9,14 +9,24 @@ pub mod ddc;

pub const FEATURE_CODE_INPUT: u8 = 0x60;

#[derive(failure_derive::Fail, Debug)]
#[derive(Debug)]
pub enum DdcError {
#[fail(display = "Display not found")]
DisplayNotFound,
#[fail(display = "Feature code not found")]
FeatureCodeNotFound,
}

impl fmt::Display for DdcError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let msg = match self {
DdcError::DisplayNotFound => "Display not found",
DdcError::FeatureCodeNotFound => "Feature code not found",
};
f.write_str(msg)
}
}

impl std::error::Error for DdcError { }

#[derive(Debug, Clone, Default, PartialEq)]
pub struct SearchDisplay {
pub backend_id: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion qemu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2018"

[dependencies]
futures = "^0.3.5"
failure = "^0.1.1"
anyhow = "^1.0.42"
log = "^0.4.1"
tokio = { version = "^1.0.0", default-features = false, features = ["time", "sync"] }
qapi = { version = "^0.8.0", features = ["qmp", "qga", "async-tokio-net", "async-tokio-spawn"] }
2 changes: 1 addition & 1 deletion qemu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io;
use std::sync::{Mutex, Arc, Weak};
use std::future::Future;
use failure::{Error, format_err};
use anyhow::{Error, format_err};
use futures::{TryFutureExt, StreamExt};
use futures::future;
use tokio::net::UnixStream;
Expand Down
2 changes: 1 addition & 1 deletion src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::OsStr;
use std::future::Future;
use std::process::{Stdio, ExitStatus};
use tokio::process::Command;
use failure::{Error, format_err};
use anyhow::{Error, format_err};

pub struct Builder {
child: Option<Command>,
Expand Down
2 changes: 1 addition & 1 deletion src/grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use std::io;
use futures::channel::mpsc as un_mpsc;
use futures::{Sink, SinkExt, StreamExt, FutureExt, stream, future};
use failure::Error;
use anyhow::Error;
use input::{InputEvent, InputId};
use uinput::{UInputSink, EvdevHandle, Evdev};
use config::ConfigInputEvent;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::Arc;
use std::io::{self, Write};
use futures::channel::{mpsc, oneshot};
use futures::{future, TryFutureExt, FutureExt, StreamExt, SinkExt};
use failure::{Error, format_err};
use anyhow::{Error, format_err};
use log::{warn, error};
use clap::{Arg, App, SubCommand, AppSettings};
use input::{InputId, Key, RelativeAxis, AbsoluteAxis, InputEvent, EventKind};
Expand Down
2 changes: 1 addition & 1 deletion src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::pin::Pin;
use futures::{future, FutureExt, SinkExt, TryFutureExt};
use futures::channel::mpsc as un_mpsc;
use std::sync::Mutex;
use failure::{Error, format_err};
use anyhow::{Error, format_err};
use config::{ConfigEvent, ConfigGrab, ConfigGrabMode, ConfigInputEvent, ConfigQemuRouting, ConfigQemuDriver};
use qapi::qga::{guest_shutdown, GuestShutdownMode};
use input::{self, InputEvent, RelativeAxis, InputId};
Expand Down
4 changes: 2 additions & 2 deletions src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::time::{Duration, Instant};
use input::{InputEvent, EventRef, KeyEvent, Key, RelativeAxis, AbsoluteAxis};
use futures::channel::mpsc;
use futures::{StreamExt, SinkExt, Future, FutureExt, TryFutureExt};
use failure::{Error, format_err};
use anyhow::{Error, Context};
use config::ConfigQemuRouting;
use config::keymap::Keymaps;
use qapi::{qmp, Any};
Expand Down Expand Up @@ -269,7 +269,7 @@ impl<U: UInputCommands> RouteUInput<U> {
let res = async move {
while let Some(e) = events.next().await {
uinput.send(e).await
.map_err(|e| format_err!("uinput write failed: {:?}", e))?;
.context("uinput write failed")?;
}
Ok(())
}.await;
Expand Down
2 changes: 1 addition & 1 deletion src/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
use std::sync::{Arc, Mutex as StdMutex};
use futures::lock::Mutex;
use tokio::time::{Duration, Instant, sleep_until};
use failure::{Error, format_err};
use anyhow::{Error, format_err};
use qemu::Qemu;
use config::{ConfigSource, ConfigMonitor, ConfigDdcMethod};
use crate::exec::exec;
Expand Down
2 changes: 1 addition & 1 deletion src/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Mutex;
use tokio::time::{Duration, Instant, timeout_at};
use tokio::task::JoinHandle;
use futures::{Future, future};
use failure::Error;
use anyhow::Error;

pub struct Spawner {
handles: Mutex<Vec<JoinHandle<()>>>,
Expand Down
Loading

0 comments on commit 7affb88

Please sign in to comment.