From df8c213a74dc237ca1982834510964c79d25d1f8 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Sun, 22 Sep 2024 01:35:47 +0100 Subject: [PATCH 1/2] Use eyre for error handling, fixes #96 --- Cargo.toml | 2 +- src/error.rs | 34 +++++++++------------------------- src/hello.rs | 5 +++-- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5393ccb..7fc6d23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ anstream = "0.6.4" clap = { version = "4.4.7", features = ["derive", "wrap_help"] } clap-verbosity-flag = "2.1.0" colorchoice-clap = "1.0.3" +eyre = "0.6.12" owo-colors = "3.5.0" proc-exit = "2.0.1" -thiserror = "1.0.39" tracing = "0.1.37" tracing-log = { version = "0.1.3", default-features = false, features = ["log-tracer", "std"] } tracing-subscriber = "0.3.16" diff --git a/src/error.rs b/src/error.rs index 37bda36..90ad1d0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,36 +1,20 @@ -use std::{ - io::{Error as IoError, Write}, - result::Result as StdResult, -}; +use std::io::Write; use anstream::{eprintln, stderr, stdout}; +use eyre::Result as EyreResult; use owo_colors::OwoColorize; use proc_exit::Code; -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[error("You cannot use cliche")] - World, - #[error("{0}")] - Io(#[from] IoError), -} - -impl Error { - fn print(&self) { - eprintln!("{}: {self}", "error".red().bold()); - } - - fn code(&self) -> Code { - Code::FAILURE - } -} - -pub type Result = StdResult; +pub type Result = EyreResult; pub fn finish(result: Result) { let code = if let Some(e) = result.err() { - e.print(); - e.code() + // Use `e.is::()` to check for a specific error + // in order to wrap all instances of it. + let err = e; + + eprintln!("{}: {err}", "error".red().bold()); + Code::FAILURE } else { Code::SUCCESS }; diff --git a/src/hello.rs b/src/hello.rs index 7a82bff..fc075c9 100644 --- a/src/hello.rs +++ b/src/hello.rs @@ -2,10 +2,11 @@ use std::io::Write; use anstream::{println, stdout}; use clap::Parser; +use eyre::eyre; use owo_colors::OwoColorize; use tracing::{debug, instrument}; -use crate::error::{Error, Result}; +use crate::error::Result; /// Say hello to someone #[derive(Debug, Parser)] @@ -18,7 +19,7 @@ impl Hello { #[instrument(name = "hello", skip_all)] pub fn run(self) -> Result { if self.name == "world" { - return Err(Error::World); + return Err(eyre!("You cannot use cliche")); } println!("Hello, {}!", self.name.yellow()); From bca4d297578ce7fa6b1be46a42a2d339b43e9d3e Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Fri, 21 Mar 2025 05:15:20 +0000 Subject: [PATCH 2/2] Wait for status checks --- .github/workflows/lint.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 87b1a43..1c93b65 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,6 +4,17 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: + ci: + runs-on: ubuntu-latest + permissions: + checks: read + needs: [lockfile, lint] + steps: + - name: Wait for checks + uses: poseidon/wait-for-status-checks@v0.6.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + match_pattern: test lockfile: runs-on: ubuntu-latest steps: