Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use anyhow instead of failure for errors #511

Merged
merged 2 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 2 additions & 66 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ build="build.rs"
edition="2021"

[dependencies]
anyhow = "1"
clap = {version="3.1", features=["wrap_help", "cargo", "derive"]}
clap_complete="3.1"
console = "0.15"
ctrlc = "3"
indicatif = "0.16"
env_logger = "0.9"
failure = "0.1.8"
goblin = "0.5.3"
inferno = "0.11.7"
lazy_static = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/dump_traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use log::error;
// Simple example of showing how to use the rust API to
// print out stack traces from a python program

fn print_python_stacks(pid: remoteprocess::Pid) -> Result<(), failure::Error> {
fn print_python_stacks(pid: remoteprocess::Pid) -> Result<(), anyhow::Error> {
// Create a new PythonSpy object with the default config options
let config = py_spy::Config::default();
let mut process = py_spy::PythonSpy::new(pid, &config)?;
Expand Down
2 changes: 1 addition & 1 deletion src/binary_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::fs::File;
use std::path::Path;

use failure::Error;
use anyhow::Error;
use goblin;
use goblin::Object;
use memmap::Mmap;
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{ArgEnum, Arg, Command, crate_description, crate_name, crate_version, PossibleValue};
use clap::{ArgEnum, Arg, Command, crate_description, crate_name, crate_version, PossibleValue, value_parser};
use remoteprocess::Pid;

/// Options on how to collect samples from a python process
Expand Down Expand Up @@ -260,7 +260,7 @@ impl Config {
.about("Generate shell completions")
.hide(true)
.arg(Arg::new("shell")
.possible_values(clap_complete::Shell::possible_values())
.value_parser(value_parser!(clap_complete::Shell))
.help("Shell type"));

// add native unwinding if appropriate
Expand Down
2 changes: 1 addition & 1 deletion src/console_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::io::{Read, Write};
use std::sync::{Mutex, Arc, atomic};
use std::thread;

use anyhow::Error;
use console::{Term, style};
use failure::Error;

use crate::config::Config;
use crate::stack_trace::{StackTrace, Frame};
Expand Down
2 changes: 1 addition & 1 deletion src/cython.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std;
use std::collections::{BTreeMap, HashMap};
use regex::Regex;

use failure::Error;
use anyhow::Error;
use lazy_static::lazy_static;

use crate::utils::resolve_filename;
Expand Down
2 changes: 1 addition & 1 deletion src/dump.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Error;
use console::{Term, style};
use failure::Error;

use crate::config::Config;
use crate::python_spy::PythonSpy;
Expand Down
2 changes: 1 addition & 1 deletion src/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use std;
use std::collections::HashMap;


use failure::Error;
use anyhow::Error;
use inferno::flamegraph::{Direction, Options};

use crate::stack_trace::StackTrace;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! # Example:
//!
//! ```rust,no_run
//! fn print_python_stacks(pid: py_spy::Pid) -> Result<(), failure::Error> {
//! fn print_python_stacks(pid: py_spy::Pid) -> Result<(), anyhow::Error> {
//! // Create a new PythonSpy object with the default config options
//! let config = py_spy::Config::default();
//! let mut process = py_spy::PythonSpy::new(pid, &config)?;
Expand All @@ -25,7 +25,7 @@
//! }
//! ```
#[macro_use]
extern crate failure;
extern crate anyhow;
#[macro_use]
extern crate log;

Expand Down
9 changes: 4 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[macro_use]
extern crate failure;
extern crate anyhow;
#[macro_use]
extern crate log;

Expand Down Expand Up @@ -30,7 +30,7 @@ use std::sync::Arc;
use std::time::Duration;

use console::style;
use failure::Error;
use anyhow::Error;

use stack_trace::{StackTrace, Frame};
use console_viewer::ConsoleViewer;
Expand All @@ -40,7 +40,7 @@ use chrono::{SecondsFormat, Local};

#[cfg(unix)]
fn permission_denied(err: &Error) -> bool {
err.iter_chain().any(|cause| {
err.chain().any(|cause| {
if let Some(ioerror) = cause.downcast_ref::<std::io::Error>() {
ioerror.kind() == std::io::ErrorKind::PermissionDenied
} else if let Some(remoteprocess::Error::IOError(ioerror)) = cause.downcast_ref::<remoteprocess::Error>() {
Expand Down Expand Up @@ -439,12 +439,11 @@ fn main() {
}

eprintln!("Error: {}", err);
for (i, suberror) in err.iter_chain().enumerate() {
for (i, suberror) in err.chain().enumerate() {
if i > 0 {
eprintln!("Reason: {}", suberror);
}
}
eprintln!("{}", err.backtrace());
std::process::exit(1);
}
}
2 changes: 1 addition & 1 deletion src/native_stack_trace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use failure::Error;
use anyhow::Error;

use cpp_demangle::{DemangleOptions, BorrowedSymbol};
use remoteprocess::{self, Pid};
Expand Down
2 changes: 1 addition & 1 deletion src/python_data_access.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std;

use failure::Error;
use anyhow::Error;

use remoteprocess::ProcessMemory;
use crate::python_interpreters::{StringObject, BytesObject, InterpreterState, Object, TypeObject, TupleObject, ListObject};
Expand Down
2 changes: 1 addition & 1 deletion src/python_spy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use regex::Regex;
#[cfg(windows)]
use regex::RegexBuilder;

use failure::{Error, ResultExt};
use anyhow::{Error, Result, Context};
use lazy_static::lazy_static;
use remoteprocess::{Process, ProcessMemory, Pid, Tid};
use proc_maps::{get_process_maps, MapRange};
Expand Down
2 changes: 1 addition & 1 deletion src/python_threading.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use failure::Error;
use anyhow::Error;

use crate::python_bindings::{v3_6_6, v3_7_0, v3_8_0, v3_9_5, v3_10_0};
use crate::python_interpreters::{InterpreterState, Object, TypeObject};
Expand Down
2 changes: 1 addition & 1 deletion src/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::{Mutex, Arc};
use std::time::Duration;
use std::thread;

use failure::Error;
use anyhow::Error;

use remoteprocess::Pid;

Expand Down
2 changes: 1 addition & 1 deletion src/speedscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::io::Write;
use crate::stack_trace;
use remoteprocess::{Tid, Pid};

use failure::{Error};
use anyhow::{Error};
use serde_derive::{Deserialize, Serialize};
use serde_json;

Expand Down
2 changes: 1 addition & 1 deletion src/stack_trace.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std;
use std::sync::Arc;

use failure::{Error, ResultExt};
use anyhow::{Context, Error, Result};

use remoteprocess::{ProcessMemory, Pid, Process};
use serde_derive::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use lazy_static::lazy_static;
use regex::bytes::Regex;
use std;

use failure::{Error};
use anyhow::{Error};


#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down