Skip to content

ref: Replace failure with std::error::Error #264

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

Merged
merged 15 commits into from
Sep 24, 2020
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

**Breaking Changes**:

- Usage of `failure` was removed, and all Error types were changed to only implement `std::error::Error` and related traits.
- `symbolic-proguard` was removed in favor of the `proguard` crate. Proguard is still supported via `symbolic-cabi` and the python API however.

## 7.5.0

**Changes**:
Expand Down
2 changes: 1 addition & 1 deletion examples/addr2line/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.32"
clap = "2.33.0"
failure = "0.1.7"
symbolic = { path = "../../symbolic", features = ["demangle"] }
16 changes: 4 additions & 12 deletions examples/addr2line/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
use std::borrow::Borrow;

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

use symbolic::common::{ByteView, Name};
use symbolic::debuginfo::{Function, Object};
use symbolic::demangle::Demangle;

fn print_error(error: &Error) {
eprintln!("Error: {}", error);

for cause in error.iter_causes() {
eprintln!(" caused by {}", cause);
}
}

fn print_name<'a, N: Borrow<Name<'a>>>(name: Option<N>, matches: &ArgMatches<'_>) {
match name.as_ref().map(Borrow::borrow) {
None => print!("??"),
Expand All @@ -36,7 +28,7 @@ fn print_range(start: u64, len: Option<u64>, matches: &ArgMatches<'_>) {
}
}

fn resolve(function: &Function<'_>, addr: u64, matches: &ArgMatches<'_>) -> Result<bool, Error> {
fn resolve(function: &Function<'_>, addr: u64, matches: &ArgMatches<'_>) -> Result<bool> {
if function.address > addr || function.address + function.size <= addr {
return Ok(false);
}
Expand Down Expand Up @@ -76,7 +68,7 @@ fn resolve(function: &Function<'_>, addr: u64, matches: &ArgMatches<'_>) -> Resu
Ok(false)
}

fn execute(matches: &ArgMatches<'_>) -> Result<(), Error> {
fn execute(matches: &ArgMatches<'_>) -> Result<()> {
let path = matches.value_of("path").unwrap_or("a.out");
let view = ByteView::open(path).context("failed to open file")?;
let object = Object::parse(&view).context("failed to parse file")?;
Expand Down Expand Up @@ -127,6 +119,6 @@ fn main() {

match execute(&matches) {
Ok(()) => (),
Err(e) => print_error(&e),
Err(e) => eprintln!("{:?}", e),
};
}
2 changes: 1 addition & 1 deletion examples/dump_cfi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.32"
clap = "2.33.0"
failure = "0.1.7"
symbolic = { path = "../../symbolic", features = ["minidump"] }
16 changes: 4 additions & 12 deletions examples/dump_cfi/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use std::path::Path;

use anyhow::Result;
use clap::{App, Arg, ArgMatches};
use failure::Error;

use symbolic::common::{ByteView, DSymPathExt};
use symbolic::debuginfo::Object;
use symbolic::minidump::cfi::AsciiCfiWriter;

fn print_error(error: &Error) {
eprintln!("Error: {:#?}", error);

for cause in error.iter_causes() {
eprintln!(" caused by {}", cause);
}
}

fn dump_cfi<P: AsRef<Path>>(path: P) -> Result<(), Error> {
fn dump_cfi<P: AsRef<Path>>(path: P) -> Result<()> {
let path = path.as_ref();

let dsym_path = path.resolve_dsym();
Expand All @@ -36,7 +28,7 @@ fn dump_cfi<P: AsRef<Path>>(path: P) -> Result<(), Error> {
Ok(())
}

fn execute(matches: &ArgMatches<'_>) -> Result<(), Error> {
fn execute(matches: &ArgMatches<'_>) -> Result<()> {
let path = matches.value_of("path").unwrap();
dump_cfi(path)
}
Expand All @@ -56,6 +48,6 @@ fn main() {

match execute(&matches) {
Ok(()) => (),
Err(e) => print_error(&e),
Err(e) => eprintln!("{:?}", e),
};
}
1 change: 0 additions & 1 deletion examples/dump_sources/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ edition = "2018"

[dependencies]
clap = "2.33.0"
failure = "0.1.7"
symbolic = { path = "../../symbolic" }
26 changes: 10 additions & 16 deletions examples/dump_sources/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use std::path::Path;

use clap::{App, Arg, ArgMatches};
use failure::Error;

use symbolic::common::{ByteView, DSymPathExt};
use symbolic::debuginfo::sourcebundle::SourceBundleWriter;
use symbolic::debuginfo::Archive;

fn print_error(error: &Error) {
fn print_error(mut error: &dyn std::error::Error) {
println!("Error: {}", error);

for cause in error.iter_causes() {
println!(" caused by {}", cause);
while let Some(source) = error.source() {
println!(" caused by {}", source);
error = source;
}
}

fn write_object_sources(path: &Path, output_path: &Path) -> Result<(), Error> {
fn write_object_sources(path: &Path, output_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
println!("Inspecting {}", path.display());

let dsym_path = path.resolve_dsym();
Expand All @@ -34,7 +34,7 @@ fn write_object_sources(path: &Path, output_path: &Path) -> Result<(), Error> {
}
Err(e) => {
print!(" - ");
print_error(&e.into());
print_error(&e);
continue;
}
}
Expand All @@ -43,18 +43,15 @@ fn write_object_sources(path: &Path, output_path: &Path) -> Result<(), Error> {
Ok(())
}

fn execute(matches: &ArgMatches<'_>) -> Result<(), Error> {
fn execute(matches: &ArgMatches<'_>) {
let output_path = Path::new(matches.value_of("output").unwrap());
for path in matches.values_of("paths").unwrap_or_default() {
match write_object_sources(Path::new(&path), &output_path) {
Ok(()) => (),
Err(e) => print_error(&e),
if let Err(e) = write_object_sources(Path::new(&path), &output_path) {
print_error(e.as_ref());
}

println!();
}

Ok(())
}

fn main() {
Expand All @@ -79,8 +76,5 @@ fn main() {
)
.get_matches();

match execute(&matches) {
Ok(()) => (),
Err(e) => print_error(&e),
};
execute(&matches);
}
1 change: 0 additions & 1 deletion examples/minidump_stackwalk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ edition = "2018"

[dependencies]
clap = "2.33.0"
failure = "0.1.7"
symbolic = { path = "../../symbolic", features = ["minidump", "symcache", "demangle"] }
walkdir = "2.3.1"
6 changes: 3 additions & 3 deletions examples/minidump_stackwalk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use std::io::Cursor;
use std::path::Path;

use clap::{App, Arg, ArgMatches};
use failure::Error;
use walkdir::WalkDir;

use symbolic::common::{Arch, ByteView, InstructionInfo, SelfCell};
use symbolic::debuginfo::{Archive, FileFormat, Object};
use symbolic::demangle::Demangle;
use symbolic::minidump::cfi::CfiCache;
use symbolic::minidump::processor::{CodeModuleId, FrameInfoMap, ProcessState, StackFrame};
use symbolic::symcache::{LineInfo, SymCache, SymCacheWriter};
use symbolic::symcache::{LineInfo, SymCache, SymCacheError, SymCacheWriter};

type SymCaches<'a> = BTreeMap<CodeModuleId, SelfCell<ByteView<'a>, SymCache<'a>>>;
type Error = Box<dyn std::error::Error>;

fn collect_referenced_objects<P, F, T>(
path: P,
Expand Down Expand Up @@ -124,7 +124,7 @@ fn symbolize<'a>(
frame: &StackFrame,
arch: Arch,
crashing: bool,
) -> Result<Option<Vec<LineInfo<'a>>>, Error> {
) -> Result<Option<Vec<LineInfo<'a>>>, SymCacheError> {
let module = match frame.module() {
Some(module) => module,
None => return Ok(None),
Expand Down
1 change: 0 additions & 1 deletion examples/object_debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ edition = "2018"

[dependencies]
clap = "2.33.0"
failure = "0.1.7"
symbolic = { path = "../../symbolic" }
26 changes: 10 additions & 16 deletions examples/object_debug/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use std::path::Path;

use clap::{App, Arg, ArgMatches};
use failure::Error;

use symbolic::common::{ByteView, DSymPathExt};
use symbolic::debuginfo::Archive;

fn print_error(error: &Error) {
fn print_error(mut error: &dyn std::error::Error) {
println!("Error: {}", error);

for cause in error.iter_causes() {
println!(" caused by {}", cause);
while let Some(source) = error.source() {
println!(" caused by {}", source);
error = source;
}
}

fn inspect_object<P: AsRef<Path>>(path: P) -> Result<(), Error> {
fn inspect_object<P: AsRef<Path>>(path: P) -> Result<(), Box<dyn std::error::Error>> {
let path = path.as_ref();
println!("Inspecting {}", path.display());

Expand Down Expand Up @@ -42,7 +42,7 @@ fn inspect_object<P: AsRef<Path>>(path: P) -> Result<(), Error> {
}
Err(e) => {
print!(" - ");
print_error(&e.into());
print_error(&e);
continue;
}
}
Expand All @@ -51,17 +51,14 @@ fn inspect_object<P: AsRef<Path>>(path: P) -> Result<(), Error> {
Ok(())
}

fn execute(matches: &ArgMatches<'_>) -> Result<(), Error> {
fn execute(matches: &ArgMatches<'_>) {
for path in matches.values_of("paths").unwrap_or_default() {
match inspect_object(path) {
Ok(()) => (),
Err(e) => print_error(&e),
if let Err(e) = inspect_object(path) {
print_error(e.as_ref())
}

println!();
}

Ok(())
}

fn main() {
Expand All @@ -78,8 +75,5 @@ fn main() {
)
.get_matches();

match execute(&matches) {
Ok(()) => (),
Err(e) => print_error(&e),
};
execute(&matches);
}
2 changes: 1 addition & 1 deletion examples/symcache_debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.32"
clap = "2.33.0"
failure = "0.1.7"
symbolic = { path = "../../symbolic", features = ["symcache", "demangle"] }
8 changes: 4 additions & 4 deletions examples/symcache_debug/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use std::io::{Cursor, Write};
use std::path::Path;
use std::u64;

use anyhow::{anyhow, Result};
use clap::{App, Arg, ArgMatches};
use failure::{err_msg, Error};

use symbolic::common::{Arch, ByteView, DSymPathExt, Language};
use symbolic::debuginfo::Archive;
use symbolic::demangle::Demangle;
use symbolic::symcache::{SymCache, SymCacheWriter};

fn execute(matches: &ArgMatches) -> Result<(), Error> {
fn execute(matches: &ArgMatches) -> Result<()> {
let buffer;
let symcache;

Expand Down Expand Up @@ -53,7 +53,7 @@ fn execute(matches: &ArgMatches) -> Result<(), Error> {

let obj = match obj {
Some(obj) => obj,
None => return Err(err_msg(format!("did not find architecture {}", arch))),
None => return Err(anyhow!("did not find architecture {}", arch)),
};

let writer = SymCacheWriter::write_object(obj, Cursor::new(Vec::new()))?;
Expand All @@ -73,7 +73,7 @@ fn execute(matches: &ArgMatches) -> Result<(), Error> {
buffer = ByteView::open(file_path)?;
symcache = SymCache::parse(&buffer)?;
} else {
return Err(err_msg("No debug file or sym cache provided"));
return Err(anyhow!("No debug file or sym cache provided"));
}

// report
Expand Down
1 change: 0 additions & 1 deletion examples/unreal_engine_crash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ edition = "2018"

[dependencies]
clap = "2.33.0"
failure = "0.1.7"
symbolic = { path = "../../symbolic", features = ["unreal"] }
3 changes: 1 addition & 2 deletions examples/unreal_engine_crash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use std::fs::File;
use std::io::Read;

use clap::{App, Arg, ArgMatches};
use failure::Error;

use symbolic::unreal::{Unreal4Crash, Unreal4FileType};

fn execute(matches: &ArgMatches) -> Result<(), Error> {
fn execute(matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
let crash_file_path = matches.value_of("crash_file_path").unwrap();

let mut file = File::open(crash_file_path)?;
Expand Down
1 change: 0 additions & 1 deletion symbolic-cabi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ crate-type = ["cdylib"]

[dependencies]
serde_json = "1.0.40"
failure = "0.1.5"
apple-crash-report-parser = { version = "0.4.0", features = ["with_serde"] }
symbolic = { version = "7.5.0", path = "../symbolic", features = ["debuginfo", "demangle", "minidump", "proguard", "sourcemap", "symcache", "unreal-serde"] }
proguard = { version = "4.0.1", features = ["uuid"] }
Loading