From 093e58de2ffc8243e6ff929f50a2aaa6ef60848b Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Thu, 1 Apr 2021 17:44:50 -0600 Subject: slightly fancier errors --- Cargo.lock | 207 +++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 3 +- src/main.rs | 7 +- src/makefile/command_line.rs | 6 +- src/makefile/conditional.rs | 10 +-- src/makefile/functions.rs | 49 +++++----- src/makefile/macro.rs | 12 +-- src/makefile/mod.rs | 36 ++++---- src/makefile/pattern.rs | 7 +- src/makefile/target.rs | 6 +- src/makefile/token.rs | 8 +- 11 files changed, 274 insertions(+), 77 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c8f9b6f..4402612 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,20 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "addr2line" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "0.7.15" @@ -18,12 +33,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "anyhow" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" - [[package]] name = "arrayref" version = "0.3.6" @@ -53,6 +62,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "backtrace" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.0" @@ -109,6 +132,33 @@ dependencies = [ "vec_map", ] +[[package]] +name = "color-eyre" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b29030875fd8376e4a28ef497790d5b4a7843d8d1396bf08ce46f5eec562c5c" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6eee477a4a8a72f4addd4de416eb56d54bc307b284d6601bafdee1f4ea462d1" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -146,6 +196,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "eyre" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "221239d1d5ea86bf5d6f91c9d6bc3646ffe471b08ff9b0f91c44f115ac969d2b" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "funty" version = "1.1.0" @@ -174,6 +234,12 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" + [[package]] name = "glob" version = "0.3.0" @@ -198,6 +264,21 @@ dependencies = [ "libc", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "jane-eyre" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ccd957c837e264dcbc6e75b58fcf85fd329a66e4836f820779c40563a2d0be0" +dependencies = [ + "color-eyre", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -227,9 +308,10 @@ checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7" name = "makers" version = "0.1.0" dependencies = [ - "anyhow", "dirs", + "eyre", "glob", + "jane-eyre", "lazy_static", "nom", "regex", @@ -243,6 +325,16 @@ version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + [[package]] name = "nom" version = "6.1.2" @@ -256,6 +348,30 @@ dependencies = [ "version_check", ] +[[package]] +name = "object" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" + +[[package]] +name = "once_cell" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" + +[[package]] +name = "owo-colors" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" + +[[package]] +name = "pin-project-lite" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" + [[package]] name = "ppv-lite86" version = "0.2.10" @@ -414,12 +530,27 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "rustc-demangle" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" + [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "sharded-slab" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" +dependencies = [ + "lazy_static", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -496,6 +627,68 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-error" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "705096c6f83bf68ea5d357a6aa01829ddbdac531b357b45abeca842938085baa" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + [[package]] name = "unicode-segmentation" version = "1.7.1" diff --git a/Cargo.toml b/Cargo.toml index 6cbf820..4c5ffbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,9 +11,10 @@ keywords = ["build", "make"] categories = ["development-tools"] [dependencies] -anyhow = "1.0.40" dirs = "3.0.1" +eyre = "0.6.5" glob = "0.3.0" +jane-eyre = "0.3.0" lazy_static = "1.4.0" nom = "6.1.2" regex = "1.4.5" diff --git a/src/main.rs b/src/main.rs index d5a13b2..2948818 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,13 +17,14 @@ clippy::todo )] #![allow(clippy::non_ascii_literal)] +#![allow(clippy::missing_docs_in_private_items)] use std::env::current_dir; use std::fs::metadata; use std::io::stdin; use std::path::PathBuf; -use anyhow::bail; +use eyre::{bail, Result}; mod args; mod makefile; @@ -31,7 +32,9 @@ mod makefile; use args::Args; use makefile::Makefile; -fn main() -> anyhow::Result<()> { +fn main() -> Result<()> { + jane_eyre::install()?; + let mut args = Args::from_env_and_args(); // If no makefile is specified, try some options. if args.makefile.is_empty() { diff --git a/src/makefile/command_line.rs b/src/makefile/command_line.rs index aaf964a..8756bc9 100644 --- a/src/makefile/command_line.rs +++ b/src/makefile/command_line.rs @@ -3,6 +3,8 @@ use std::fmt; use std::io; use std::process::{Command, ExitStatus}; +use eyre::bail; + use crate::makefile::target::Target; use crate::makefile::token::{Token, TokenString}; use crate::makefile::Makefile; @@ -69,7 +71,7 @@ impl CommandLine { } } - pub fn execute(&self, file: &Makefile, target: &Target) -> anyhow::Result<()> { + pub fn execute(&self, file: &Makefile, target: &Target) -> eyre::Result<()> { let ignore_error = self.ignore_errors || file.args.ignore_errors || file.special_target_has_prereq(".IGNORE", &target.name); @@ -94,7 +96,7 @@ impl CommandLine { if errored { // apparently there was an error. do we care? if !ignore_error { - anyhow::bail!("error from command execution!"); + bail!("error from command execution!"); } } diff --git a/src/makefile/conditional.rs b/src/makefile/conditional.rs index 0b4de01..149638e 100644 --- a/src/makefile/conditional.rs +++ b/src/makefile/conditional.rs @@ -1,4 +1,4 @@ -use anyhow::bail; +use eyre::{bail, Result}; use super::token::TokenString; @@ -83,8 +83,8 @@ fn decode_condition_args(line_body: &str) -> Option<(TokenString, TokenString)> impl Line { pub fn from( line: &str, - expand_macro: impl Fn(&TokenString) -> anyhow::Result, - ) -> anyhow::Result> { + expand_macro: impl Fn(&TokenString) -> Result, + ) -> Result> { Ok(Some(if let Some(line) = line.strip_prefix("ifeq ") { match decode_condition_args(line) { Some((arg1, arg2)) => Self::IfEqual(arg1, arg2), @@ -117,8 +117,8 @@ impl Line { &self, current_state: Option<&State>, is_macro_defined: impl Fn(&str) -> bool, - expand_macro: impl Fn(&TokenString) -> anyhow::Result, - ) -> anyhow::Result { + expand_macro: impl Fn(&TokenString) -> Result, + ) -> Result { Ok(match self { Self::IfEqual(arg1, arg2) => { let arg1 = expand_macro(arg1)?; diff --git a/src/makefile/functions.rs b/src/makefile/functions.rs index 97f05b6..a4d206f 100644 --- a/src/makefile/functions.rs +++ b/src/makefile/functions.rs @@ -1,8 +1,10 @@ +use eyre::{bail, Result}; + use super::pattern::r#match; use super::r#macro::{Set as MacroSet, Source as MacroSource}; use super::token::TokenString; -pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> anyhow::Result { +pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> Result { match name { "filter" => { assert_eq!(args.len(), 2); @@ -53,21 +55,15 @@ pub fn expand_call(name: &str, args: &[TokenString], macros: &MacroSet) -> anyho "shell" => todo!(), // fallback - _ => anyhow::bail!("function not implemented: {}", name), + _ => bail!("function not implemented: {}", name), } } // Text Functions mod text { - use super::r#match; - use super::MacroSet; - use super::TokenString; + use super::*; - pub fn filter( - macros: &MacroSet, - patterns: &TokenString, - text: &TokenString, - ) -> anyhow::Result { + pub fn filter(macros: &MacroSet, patterns: &TokenString, text: &TokenString) -> Result { let patterns = macros.expand(patterns)?; let patterns = patterns.split_whitespace().collect::>(); let text = macros.expand(text)?; @@ -88,7 +84,7 @@ mod text { macros: &MacroSet, patterns: &TokenString, text: &TokenString, - ) -> anyhow::Result { + ) -> Result { let patterns = macros.expand(patterns)?; let patterns = patterns.split_whitespace().collect::>(); let text = macros.expand(text)?; @@ -105,7 +101,7 @@ mod text { Ok(result_pieces.join(" ")) } - pub fn sort(macros: &MacroSet, words: &TokenString) -> anyhow::Result { + pub fn sort(macros: &MacroSet, words: &TokenString) -> Result { let words = macros.expand(words)?; let mut words = words.split_whitespace().collect::>(); words.sort_unstable(); @@ -120,12 +116,11 @@ mod file_name { use std::ffi::OsStr; use std::path::Path; - use anyhow::Context; + use eyre::WrapErr; - use super::MacroSet; - use super::TokenString; + use super::*; - pub fn notdir(macros: &MacroSet, words: &TokenString) -> anyhow::Result { + pub fn notdir(macros: &MacroSet, words: &TokenString) -> Result { let words = macros.expand(words)?; let words = words .split_whitespace() @@ -139,7 +134,7 @@ mod file_name { Ok(words.join(" ")) } - pub fn basename(macros: &MacroSet, words: &TokenString) -> anyhow::Result { + pub fn basename(macros: &MacroSet, words: &TokenString) -> Result { let words = macros.expand(words)?; let words = words .split_whitespace() @@ -157,7 +152,7 @@ mod file_name { macros: &MacroSet, prefix: &TokenString, targets: &TokenString, - ) -> anyhow::Result { + ) -> Result { let prefix = macros.expand(prefix)?; let targets = macros.expand(targets)?; let results = targets @@ -167,7 +162,7 @@ mod file_name { Ok(results.join(" ")) } - pub fn wildcard(macros: &MacroSet, pattern: &TokenString) -> anyhow::Result { + pub fn wildcard(macros: &MacroSet, pattern: &TokenString) -> Result { let pattern = macros.expand(pattern)?; let home_dir = env::var("HOME") .ok() @@ -190,16 +185,14 @@ mod file_name { // foreach mod foreach { - use super::MacroSet; - use super::MacroSource; - use super::TokenString; + use super::*; pub fn foreach( macros: &MacroSet, var: &TokenString, list: &TokenString, text: &TokenString, - ) -> anyhow::Result { + ) -> Result { let var = macros.expand(var)?; let list = macros.expand(list)?; let words = list.split_whitespace(); @@ -217,14 +210,12 @@ mod foreach { // call mod call { - use super::MacroSet; - use super::MacroSource; - use super::TokenString; + use super::*; pub fn call<'a>( macros: &MacroSet, args: impl Iterator, - ) -> anyhow::Result { + ) -> Result { let args = args .map(|arg| macros.expand(arg)) .collect::, _>>()?; @@ -244,9 +235,9 @@ mod test { use crate::makefile::r#macro::{Set as MacroSet, Source as MacroSource}; - type R = anyhow::Result<()>; + type R = Result<()>; - fn call(name: &str, args: &[TokenString], macros: &MacroSet) -> anyhow::Result { + fn call(name: &str, args: &[TokenString], macros: &MacroSet) -> Result { super::expand_call(name, args, macros) } diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs index f18060f..e760282 100644 --- a/src/makefile/macro.rs +++ b/src/makefile/macro.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::env; use std::fmt; -use anyhow::Context; +use eyre::{bail, Result, WrapErr}; use regex::Regex; use super::functions; @@ -16,9 +16,9 @@ pub enum Source { Builtin, } -pub trait LookupInternal: for<'a> Fn(&'a str) -> anyhow::Result {} +pub trait LookupInternal: for<'a> Fn(&'a str) -> Result {} -impl Fn(&'a str) -> anyhow::Result> LookupInternal for F {} +impl Fn(&'a str) -> Result> LookupInternal for F {} #[derive(Clone)] pub struct Set<'parent, 'lookup> { @@ -51,13 +51,13 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { } } - fn lookup_internal(&self, name: &str) -> anyhow::Result { + fn lookup_internal(&self, name: &str) -> Result { if let Some(lookup) = self.lookup_internal { lookup(name) } else if let Some(parent) = self.parent { parent.lookup_internal(name) } else { - anyhow::bail!("no lookup possible") + bail!("no lookup possible") } } @@ -80,7 +80,7 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { self.data.remove(name) } - pub fn expand(&self, text: &TokenString) -> anyhow::Result { + pub fn expand(&self, text: &TokenString) -> Result { let mut result = String::new(); for token in text.tokens() { match token { diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index 1fb5935..af8ca81 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -7,7 +7,7 @@ use std::io::{BufRead, BufReader}; use std::path::Path; use std::rc::Rc; -use anyhow::{bail, Context}; +use eyre::{bail, eyre, Context, Result}; use lazy_static::lazy_static; use regex::Regex; @@ -133,7 +133,7 @@ impl<'a> Makefile<'a> { } } - pub fn and_read_file(&mut self, path: impl AsRef) -> anyhow::Result<()> { + pub fn and_read_file(&mut self, path: impl AsRef) -> Result<()> { let file = File::open(path); // TODO handle errors let file = file.context("couldn't open makefile!")?; @@ -141,7 +141,7 @@ impl<'a> Makefile<'a> { self.and_read(file_reader) } - pub fn and_read(&mut self, source: impl BufRead) -> anyhow::Result<()> { + pub fn and_read(&mut self, source: impl BufRead) -> Result<()> { let mut lines_iter = source .lines() .enumerate() @@ -235,12 +235,12 @@ impl<'a> Makefile<'a> { &mut self, line_tokens: &TokenString, line_number: usize, - lines_iter: &mut impl Iterator)>, - ) -> anyhow::Result<()> { + lines_iter: &mut impl Iterator)>, + ) -> Result<()> { let mut lines_iter = lines_iter.peekable(); let (targets, not_targets) = line_tokens .split_once(':') - .with_context(|| format!("read_rule couldn't find a ':' on line {}", line_number))?; + .ok_or_else(|| eyre!("read_rule couldn't find a ':' on line {}", line_number))?; let targets = self.expand_macros(&targets, None)?; let targets = targets.split_whitespace().collect::>(); let (prerequisites, mut commands) = match not_targets.split_once(';') { @@ -350,10 +350,10 @@ impl<'a> Makefile<'a> { Ok(()) } - fn read_macro(&mut self, line_tokens: &TokenString, line_number: usize) -> anyhow::Result<()> { + fn read_macro(&mut self, line_tokens: &TokenString, line_number: usize) -> Result<()> { let (name, mut value) = line_tokens .split_once('=') - .with_context(|| format!("read_rule couldn't find a ':' on line {}", line_number))?; + .ok_or_else(|| eyre!("read_rule couldn't find a ':' on line {}", line_number))?; let name = self.expand_macros(&name, None)?; // GNUisms are annoying, but popular let mut expand_value = false; @@ -418,7 +418,7 @@ impl<'a> Makefile<'a> { } } - pub fn get_target(&self, name: &str) -> anyhow::Result>> { + pub fn get_target(&self, name: &str) -> Result>> { // TODO implement .POSIX let follow_gnu = true; @@ -513,19 +513,23 @@ impl<'a> Makefile<'a> { } let targets = self.targets.borrow(); - Ok(Rc::clone(targets.get(name).context("Target not found!")?)) + Ok(Rc::clone( + targets + .get(name) + .ok_or_else(|| eyre!("Target not found!"))?, + )) } - pub fn update_target(&self, name: &str) -> anyhow::Result<()> { + pub fn update_target(&self, name: &str) -> Result<()> { self.get_target(name)?.borrow().update(self) } - fn expand_macros(&self, text: &TokenString, target: Option<&Target>) -> anyhow::Result { + fn expand_macros(&self, text: &TokenString, target: Option<&Target>) -> Result { let target = target.cloned(); let lookup_internal = move |name: &str| { let target = target .as_ref() - .context("internal macro but no current target!")?; + .ok_or_else(|| eyre!("internal macro but no current target!"))?; let macro_pieces = if name.starts_with('@') { // The $@ shall evaluate to the full target name of the // current target. @@ -564,7 +568,7 @@ impl<'a> Makefile<'a> { .map(|x| { Path::new(&x) .parent() - .context("no parent") + .ok_or_else(|| eyre!("no parent")) .map(|x| x.to_string_lossy().into()) }) .collect::>()? @@ -574,7 +578,7 @@ impl<'a> Makefile<'a> { .map(|x| { Path::new(&x) .file_name() - .context("no filename") + .ok_or_else(|| eyre!("no filename")) .map(|x| x.to_string_lossy().into()) }) .collect::>()? @@ -695,7 +699,7 @@ mod test { use super::*; - type R = anyhow::Result<()>; + type R = Result<()>; fn empty_makefile(args: &Args) -> Makefile { Makefile { diff --git a/src/makefile/pattern.rs b/src/makefile/pattern.rs index 6648851..b47c75d 100644 --- a/src/makefile/pattern.rs +++ b/src/makefile/pattern.rs @@ -1,6 +1,7 @@ +use eyre::Result; use regex::{Captures, Regex}; -fn compile_pattern(pattern: &str) -> anyhow::Result { +fn compile_pattern(pattern: &str) -> Result { let mut result = String::new(); for c in pattern.chars() { if c == '%' { @@ -24,7 +25,7 @@ fn compile_pattern(pattern: &str) -> anyhow::Result { Ok(Regex::new(&result)?) } -pub fn r#match<'a>(pattern: &str, text: &'a str) -> anyhow::Result>> { +pub fn r#match<'a>(pattern: &str, text: &'a str) -> Result>> { Ok(compile_pattern(pattern)?.captures(text)) } @@ -32,7 +33,7 @@ pub fn r#match<'a>(pattern: &str, text: &'a str) -> anyhow::Result; + type R = Result<()>; #[test] fn pattern_backslashes() -> R { diff --git a/src/makefile/target.rs b/src/makefile/target.rs index 64fdb7d..615c9e9 100644 --- a/src/makefile/target.rs +++ b/src/makefile/target.rs @@ -3,6 +3,8 @@ use std::fmt; use std::fs::metadata; use std::time::SystemTime; +use eyre::Result; + use crate::makefile::command_line::CommandLine; use super::Makefile; @@ -50,7 +52,7 @@ impl Target { exists && newer_than_all_dependencies } - pub fn update(&self, file: &Makefile) -> anyhow::Result<()> { + pub fn update(&self, file: &Makefile) -> Result<()> { for prereq in &self.prerequisites { file.update_target(prereq)?; } @@ -62,7 +64,7 @@ impl Target { Ok(()) } - fn execute_commands(&self, file: &Makefile) -> anyhow::Result<()> { + fn execute_commands(&self, file: &Makefile) -> Result<()> { for command in &self.commands { command.execute(file, self)?; } diff --git a/src/makefile/token.rs b/src/makefile/token.rs index 16403ff..076ac60 100644 --- a/src/makefile/token.rs +++ b/src/makefile/token.rs @@ -1,7 +1,7 @@ use std::fmt; use std::str::FromStr; -use anyhow::Context; +use eyre::WrapErr; use nom::{ branch::alt, bytes::complete::{tag, take_till1, take_while1}, @@ -252,16 +252,16 @@ fn full_text_tokens(input: &str) -> IResult<&str, TokenString> { all_consuming(tokens_but_not(vec![]))(input) } -pub fn tokenize(input: &str) -> anyhow::Result { +pub fn tokenize(input: &str) -> eyre::Result { let (_, result) = full_text_tokens(input) .finish() - .map_err(|err| anyhow::anyhow!(err.to_string())) + .map_err(|err| eyre::eyre!(err.to_string())) .with_context(|| format!("couldn't parse {:?}", input))?; Ok(result) } impl FromStr for TokenString { - type Err = anyhow::Error; + type Err = eyre::Error; fn from_str(s: &str) -> Result { tokenize(s) -- cgit v1.2.3