From 620fcde411530b6939463307d5dee9fc50a0b4d5 Mon Sep 17 00:00:00 2001 From: Otavio Rampinelli Date: Fri, 23 Oct 2026 14:36:02 -0300 Subject: [PATCH 1/2] fix: closed pipe no longer crash cli --- crates/gargoyle-cli/src/checks.rs | 19 ++++++++++--------- crates/gargoyle-cli/src/ingest.rs | 3 ++- crates/gargoyle-cli/src/init.rs | 11 ++++++----- crates/gargoyle-cli/src/main.rs | 2 +- crates/gargoyle-cli/src/output.rs | 12 +++++++++++- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/crates/gargoyle-cli/src/checks.rs b/crates/gargoyle-cli/src/checks.rs index 0fdde28..5a03dbb 100644 --- a/crates/gargoyle-cli/src/checks.rs +++ b/crates/gargoyle-cli/src/checks.rs @@ -6,7 +6,7 @@ use gargoyle_core::{Check, CheckError, CheckSpec, load_checks}; use serde::Serialize; use crate::exit::Exit; -use crate::output::print_json; +use crate::output::{out, print_json}; pub(crate) fn list(dir: &Path, json: bool) -> anyhow::Result { let checks = match load_checks(dir) { @@ -20,18 +20,18 @@ pub(crate) fn list(dir: &Path, json: bool) -> anyhow::Result { } else if checks.is_empty() { eprintln!("No checks found in {}", dir.display()); } else { - print_table(&checks); + print_table(&checks)?; } Ok(Exit::Clean) } -pub(crate) fn validate(dir: &Path) -> Exit { +pub(crate) fn validate(dir: &Path) -> anyhow::Result { match load_checks(dir) { Ok(checks) => { - println!("{} checks valid in {}", checks.len(), dir.display()); - Exit::Clean + out!("{} checks valid in {}", checks.len(), dir.display())?; + Ok(Exit::Clean) } - Err(errors) => report(&errors), + Err(errors) => Ok(report(&errors)), } } @@ -42,7 +42,7 @@ fn report(errors: &[CheckError]) -> Exit { Exit::Config } -fn print_table(checks: &[Check]) { +fn print_table(checks: &[Check]) -> anyhow::Result<()> { let width = checks .iter() .map(|c| c.id().as_str().len()) @@ -50,14 +50,15 @@ fn print_table(checks: &[Check]) { .unwrap_or(0); for check in checks { let spec = &check.spec; - println!( + out!( "{:) -> anyhow::Result< } else { "findings" }; - println!("ok: {} {noun} for {}", output.findings.len(), task.id); + out!("ok: {} {noun} for {}", output.findings.len(), task.id)?; Ok(Exit::Clean) } Err(problems) => { diff --git a/crates/gargoyle-cli/src/init.rs b/crates/gargoyle-cli/src/init.rs index 927c003..b454ea2 100644 --- a/crates/gargoyle-cli/src/init.rs +++ b/crates/gargoyle-cli/src/init.rs @@ -9,6 +9,7 @@ use anyhow::Context; use gargoyle_core::{CONFIG_FILE, ChecksConfig}; use crate::exit::Exit; +use crate::output::out; const CONFIG_TEMPLATE: &str = include_str!("../templates/gargoyle.toml"); @@ -42,11 +43,11 @@ pub(crate) fn run(root: &Path, force: bool, skill: bool) -> anyhow::Result // init can run again any time, it only fills in what's missing let config_path = root.join(CONFIG_FILE); if config_path.exists() && !force { - println!("kept {CONFIG_FILE}, use --force to overwrite it"); + out!("kept {CONFIG_FILE}, use --force to overwrite it")?; } else { fs::write(&config_path, CONFIG_TEMPLATE) .with_context(|| format!("writing {}", config_path.display()))?; - println!("created {CONFIG_FILE}"); + out!("created {CONFIG_FILE}")?; } // never overwrite a check, you may have edited it @@ -56,11 +57,11 @@ pub(crate) fn run(root: &Path, force: bool, skill: bool) -> anyhow::Result for (name, text) in BUILT_IN_CHECKS { let path = checks_dir.join(name); if root.join(&path).exists() { - println!("kept {}", path.display()); + out!("kept {}", path.display())?; continue; } fs::write(root.join(&path), text).with_context(|| format!("writing {}", path.display()))?; - println!("created {}", path.display()); + out!("created {}", path.display())?; } if skill { @@ -74,7 +75,7 @@ pub(crate) fn run(root: &Path, force: bool, skill: bool) -> anyhow::Result fn add_skill(root: &Path) -> anyhow::Result<()> { // windows only finds npx through its .cmd shim let npx = if cfg!(windows) { "npx.cmd" } else { "npx" }; - println!("\nadding the /gargoyle skill with npx {SKILLS_CLI} add {SKILL_SOURCE}"); + out!("\nadding the /gargoyle skill with npx {SKILLS_CLI} add {SKILL_SOURCE}")?; let status = Command::new(npx) .args(["--yes", SKILLS_CLI, "add", SKILL_SOURCE]) .current_dir(root) diff --git a/crates/gargoyle-cli/src/main.rs b/crates/gargoyle-cli/src/main.rs index a0940d4..926a312 100644 --- a/crates/gargoyle-cli/src/main.rs +++ b/crates/gargoyle-cli/src/main.rs @@ -164,7 +164,7 @@ fn run(cli: &Cli) -> anyhow::Result { Err(exit) => Ok(exit), }, Command::Checks(ChecksCommand::Validate { source }) => match checks_dir(source) { - Ok(dir) => Ok(checks::validate(&dir)), + Ok(dir) => checks::validate(&dir), Err(exit) => Ok(exit), }, Command::Diff { base } => diff::run(base.as_deref()), diff --git a/crates/gargoyle-cli/src/output.rs b/crates/gargoyle-cli/src/output.rs index 26216a4..c257ba5 100644 --- a/crates/gargoyle-cli/src/output.rs +++ b/crates/gargoyle-cli/src/output.rs @@ -1,9 +1,19 @@ -//! helpers for writting results to stdout +//! helpers for writing results to stdout use std::io::Write; use serde::Serialize; +/// like `println!`, but a closed pipe comes back as an error instead of a panic, +/// so `gargoyle checks list | head -1` exits cleanly +macro_rules! out { + ($($arg:tt)*) => {{ + use std::io::Write as _; + writeln!(std::io::stdout().lock(), $($arg)*) + }}; +} +pub(crate) use out; + /// writes pretty json plus a trailing newline to stdout pub(crate) fn print_json(value: &impl Serialize) -> anyhow::Result<()> { let mut stdout = std::io::stdout().lock(); From a81130bd0310b867e6d95b98b4498ae92c31ca79 Mon Sep 17 00:00:00 2001 From: Otavio Rampinelli Date: Fri, 23 Oct 2026 14:36:16 -0300 Subject: [PATCH 2/2] docs: fixed typos --- crates/gargoyle-core/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/gargoyle-core/src/lib.rs b/crates/gargoyle-core/src/lib.rs index fb244b8..2e66684 100644 --- a/crates/gargoyle-core/src/lib.rs +++ b/crates/gargoyle-core/src/lib.rs @@ -1,8 +1,8 @@ -//! gargoyle is an deterministic review engine +//! gargoyle is a deterministic review engine //! -//! this crate owns evey step of a review that doesnt need a model -//! loading checks, building the review pla, validating findings, -//! fingerprinting and dedupe, it does no network i/o and never prints +//! this crate owns every step of a review that doesn't need a model: +//! loading checks, building the review plan, validating findings, +//! fingerprinting and dedup, it does no network i/o and never prints mod check; mod confidence;