clif-util: Use anyhow::Error for errors instead of String

Also does the same for `cranelift-filetests`.
This commit is contained in:
Nick Fitzgerald
2020-09-14 16:23:30 -07:00
parent 9fea412333
commit 31cbbd1d20
43 changed files with 415 additions and 443 deletions

View File

@@ -4,10 +4,10 @@
//! normalizing formatting and removing comments.
use crate::utils::read_to_string;
use crate::CommandResult;
use anyhow::{Context, Result};
use cranelift_reader::parse_functions;
pub fn run(files: &[String]) -> CommandResult {
pub fn run(files: &[String]) -> Result<()> {
for (i, f) in files.iter().enumerate() {
if i != 0 {
println!();
@@ -17,9 +17,10 @@ pub fn run(files: &[String]) -> CommandResult {
Ok(())
}
fn cat_one(filename: &str) -> CommandResult {
let buffer = read_to_string(&filename).map_err(|e| format!("{}: {}", filename, e))?;
let items = parse_functions(&buffer).map_err(|e| format!("{}: {}", filename, e))?;
fn cat_one(filename: &str) -> Result<()> {
let buffer = read_to_string(&filename)?;
let items =
parse_functions(&buffer).with_context(|| format!("failed to parse {}", filename))?;
for (idx, func) in items.into_iter().enumerate() {
if idx != 0 {