From 431afd21eea8c1871239e97ff25c6f198a1c2830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Juki=C4=87?= Date: Mon, 13 Oct 2025 11:30:35 +0200 Subject: [PATCH 1/8] fix color coding of errors --- src/build/mod.rs | 60 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 71484ade..10c92ddd 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -5,11 +5,8 @@ use std::process::Command; use std::time::SystemTime; use color_eyre::{ - Section, - { - eyre::{eyre, WrapErr}, - Result, - }, + eyre::{eyre, WrapErr}, + Help, Result, }; use fs_err as fs; use serde::{Deserialize, Serialize}; @@ -61,6 +58,40 @@ struct CargoPackage { name: String, } +#[derive(Debug)] +struct CommandExecutionError { + program: String, + args: Vec, + exit_code: Option, + stdout: String, + stderr: String, +} +impl std::fmt::Display for CommandExecutionError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + writeln!( + f, + "Command `{} {:?}` failed with exit code {:?}", + self.program, self.args, self.exit_code + )?; + if !self.stdout.is_empty() { + writeln!(f, "Stdout:")?; + write!(f, "{}", self.stdout)?; + if !self.stdout.ends_with('\n') { + writeln!(f)?; + } + } + if !self.stderr.is_empty() { + writeln!(f, "Stderr:")?; + write!(f, "{}", self.stderr)?; + if !self.stderr.ends_with('\n') { + writeln!(f)?; + } + } + Ok(()) + } +} +impl std::error::Error for CommandExecutionError {} + pub fn make_fake_kill_chan() -> BroadcastRecvBool { let (_send_to_kill, recv_kill) = tokio::sync::broadcast::channel(1); recv_kill @@ -260,16 +291,17 @@ pub fn run_command(cmd: &mut Command, verbose: bool) -> Result>(), - output.status.code(), - String::from_utf8_lossy(&output.stdout), - String::from_utf8_lossy(&output.stderr), - )) + exit_code: output.status.code(), + stdout: String::from_utf8_lossy(&output.stdout).to_string(), + stderr: String::from_utf8_lossy(&output.stderr).to_string(), + } + .into()) } } From 3d80d0493b81c51544eb4d9dea16643d00c1bf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Juki=C4=87?= Date: Mon, 13 Oct 2025 18:17:22 +0200 Subject: [PATCH 2/8] debug to display --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 041525ea..df463c20 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1463,7 +1463,7 @@ async fn main() -> Result<()> { } if let Err(e) = result { - error!("{:?}", e); + error!("{e}"); std::process::exit(1); }; Ok(()) From b82b9914ac4d7d29adc38457b845f9b9b28afdb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Juki=C4=87?= Date: Mon, 13 Oct 2025 18:31:01 +0200 Subject: [PATCH 3/8] Revert "debug to display" This reverts commit 3d80d0493b81c51544eb4d9dea16643d00c1bf61. --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index df463c20..041525ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1463,7 +1463,7 @@ async fn main() -> Result<()> { } if let Err(e) = result { - error!("{e}"); + error!("{:?}", e); std::process::exit(1); }; Ok(()) From 78851113a24ed343ca93eaab6daee2f33b98c565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Juki=C4=87?= Date: Tue, 14 Oct 2025 09:55:52 +0200 Subject: [PATCH 4/8] add error attr, remove manual display formatting --- src/build/mod.rs | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 10c92ddd..a219c9e4 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -58,7 +58,8 @@ struct CargoPackage { name: String, } -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] +#[error("Command `{program}` {args:?} failed with exit code {exit_code:?}\nstdout: {stdout}\nstderr: {stderr}")] struct CommandExecutionError { program: String, args: Vec, @@ -66,31 +67,6 @@ struct CommandExecutionError { stdout: String, stderr: String, } -impl std::fmt::Display for CommandExecutionError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!( - f, - "Command `{} {:?}` failed with exit code {:?}", - self.program, self.args, self.exit_code - )?; - if !self.stdout.is_empty() { - writeln!(f, "Stdout:")?; - write!(f, "{}", self.stdout)?; - if !self.stdout.ends_with('\n') { - writeln!(f)?; - } - } - if !self.stderr.is_empty() { - writeln!(f, "Stderr:")?; - write!(f, "{}", self.stderr)?; - if !self.stderr.ends_with('\n') { - writeln!(f)?; - } - } - Ok(()) - } -} -impl std::error::Error for CommandExecutionError {} pub fn make_fake_kill_chan() -> BroadcastRecvBool { let (_send_to_kill, recv_kill) = tokio::sync::broadcast::channel(1); From ed0c3d92892d4bc49604df97ddb7438e1073b63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Juki=C4=87?= Date: Thu, 23 Oct 2025 13:29:15 +0200 Subject: [PATCH 5/8] ai generated changes fix the issue --- src/logging.rs | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 58 +++++++++++++++++---------- 2 files changed, 142 insertions(+), 20 deletions(-) create mode 100644 src/logging.rs diff --git a/src/logging.rs b/src/logging.rs new file mode 100644 index 00000000..dd1acb7c --- /dev/null +++ b/src/logging.rs @@ -0,0 +1,104 @@ +use std::fmt; + +use tracing::Subscriber; +use tracing_subscriber::{ + fmt::{self as tracing_fmt, FmtContext, FormatEvent, FormatFields}, + registry::LookupSpan, +}; + +fn restore_ansi_sequences(input: &str, scratch: &mut String) -> bool { + if !input.contains("\\x") { + return false; + } + + scratch.clear(); + scratch.reserve(input.len()); + let bytes = input.as_bytes(); + let mut i = 0; + while i < bytes.len() { + if i + 4 <= bytes.len() && bytes[i] == b'\\' && bytes[i + 1] == b'x' { + let code = &bytes[i + 2..i + 4]; + match code { + b"1b" | b"1B" => { + scratch.push('\x1b'); + i += 4; + continue; + } + b"07" => { + scratch.push('\x07'); + i += 4; + continue; + } + b"08" => { + scratch.push('\x08'); + i += 4; + continue; + } + b"0c" | b"0C" => { + scratch.push('\x0c'); + i += 4; + continue; + } + b"7f" | b"7F" => { + scratch.push('\x7f'); + i += 4; + continue; + } + _ => {} + } + } + scratch.push(bytes[i] as char); + i += 1; + } + true +} + +pub struct AnsiPreservingFormatter { + inner: F, +} + +struct AnsiEscapeRestorer<'a> { + writer: tracing_fmt::format::Writer<'a>, + scratch: String, +} + +impl<'a> fmt::Write for AnsiEscapeRestorer<'a> { + fn write_str(&mut self, s: &str) -> fmt::Result { + if restore_ansi_sequences(s, &mut self.scratch) { + self.writer.write_str(&self.scratch) + } else { + self.writer.write_str(s) + } + } + + fn write_char(&mut self, c: char) -> fmt::Result { + self.writer.write_char(c) + } +} + +impl AnsiPreservingFormatter { + pub fn new(inner: F) -> Self { + Self { inner } + } +} + +impl FormatEvent for AnsiPreservingFormatter +where + S: Subscriber + for<'span> LookupSpan<'span>, + N: for<'a> FormatFields<'a> + 'static, + F: FormatEvent, +{ + fn format_event( + &self, + ctx: &FmtContext<'_, S, N>, + writer: tracing_fmt::format::Writer<'_>, + event: &tracing::Event<'_>, + ) -> fmt::Result { + let mut adapter = AnsiEscapeRestorer { + writer, + scratch: String::new(), + }; + let proxy = tracing_fmt::format::Writer::new(&mut adapter); + self.inner.format_event(ctx, proxy, event) + } +} diff --git a/src/main.rs b/src/main.rs index 0e385aaf..66e178b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,14 @@ use serde::Deserialize; use tracing::{error, instrument, warn, Level}; use tracing_error::ErrorLayer; use tracing_subscriber::{ - filter, fmt, layer::SubscriberExt, prelude::*, util::SubscriberInitExt, EnvFilter, + filter, + fmt::{self as tracing_fmt}, + layer::SubscriberExt, + prelude::*, + util::SubscriberInitExt, + EnvFilter, }; +use tracing_subscriber::fmt::format::PrettyFields; use kit::{ boot_fake_node, boot_real_node, build, build_start_package, chain, connect, dev_ui, @@ -32,6 +38,9 @@ const STDERR_LOG_LEVEL_DEFAULT: &str = "error"; const FILE_LOG_LEVEL_DEFAULT: &str = "debug"; const RUST_LOG: &str = "RUST_LOG"; +mod logging; +use logging::AnsiPreservingFormatter; + #[derive(Debug, Deserialize)] struct Commit { sha: String, @@ -120,31 +129,40 @@ fn init_tracing(log_path: PathBuf) -> tracing_appender::non_blocking::WorkerGuar .add_directive("hyper=off".parse().unwrap()) .add_directive("reqwest=off".parse().unwrap()); - tracing_subscriber::registry() - .with( - fmt::layer() + let stdout_fields = PrettyFields::new().display_messages(); + let stderr_fields = PrettyFields::new().display_messages(); + + let stdout_layer = tracing_fmt::layer() + .event_format(AnsiPreservingFormatter::new( + tracing_fmt::format() .without_time() - .with_writer(std::io::stdout) - .with_ansi(true) .with_level(false) - .with_target(false) - .fmt_fields(fmt::format::PrettyFields::new()) - .with_filter(stdout_filter), - ) - .with( - fmt::layer() - .with_file(true) - .with_line_number(true) + .with_target(false), + )) + .fmt_fields(stdout_fields) + .with_writer(std::io::stdout) + .with_ansi(true) + .with_filter(stdout_filter); + + let stderr_layer = tracing_fmt::layer() + .event_format(AnsiPreservingFormatter::new( + tracing_fmt::format() .without_time() - .with_writer(std::io::stderr) - .with_ansi(true) .with_level(true) .with_target(false) - .fmt_fields(fmt::format::PrettyFields::new()) - .with_filter(stderr_filter), - ) + .with_file(true) + .with_line_number(true), + )) + .fmt_fields(stderr_fields) + .with_writer(std::io::stderr) + .with_ansi(true) + .with_filter(stderr_filter); + + tracing_subscriber::registry() + .with(stdout_layer) + .with(stderr_layer) .with( - fmt::layer() + tracing_fmt::layer() .with_writer(non_blocking) .with_ansi(false) .json() From 943b0024d30b983719a59c4fcc12f98ff256a14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Juki=C4=87?= Date: Thu, 23 Oct 2025 13:31:34 +0200 Subject: [PATCH 6/8] Revert "fix color coding of errors" This reverts commit 431afd21eea8c1871239e97ff25c6f198a1c2830. --- src/build/mod.rs | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index b0e1a1fc..5bab10fd 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -5,8 +5,11 @@ use std::process::Command; use std::time::SystemTime; use color_eyre::{ - eyre::{eyre, WrapErr}, - Help, Result, + Section, + { + eyre::{eyre, WrapErr}, + Result, + }, }; use fs_err as fs; use serde::{Deserialize, Serialize}; @@ -58,16 +61,6 @@ struct CargoPackage { name: String, } -#[derive(Debug, thiserror::Error)] -#[error("Command `{program}` {args:?} failed with exit code {exit_code:?}\nstdout: {stdout}\nstderr: {stderr}")] -struct CommandExecutionError { - program: String, - args: Vec, - exit_code: Option, - stdout: String, - stderr: String, -} - pub fn make_fake_kill_chan() -> BroadcastRecvBool { let (_send_to_kill, recv_kill) = tokio::sync::broadcast::channel(1); recv_kill @@ -267,17 +260,16 @@ pub fn run_command(cmd: &mut Command, verbose: bool) -> Result>(), - exit_code: output.status.code(), - stdout: String::from_utf8_lossy(&output.stdout).to_string(), - stderr: String::from_utf8_lossy(&output.stderr).to_string(), - } - .into()) + output.status.code(), + String::from_utf8_lossy(&output.stdout), + String::from_utf8_lossy(&output.stderr), + )) } } From 6548947a18f439a5caf09e9f75b27be6e53a746a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 23 Oct 2025 11:33:38 +0000 Subject: [PATCH 7/8] Format Rust code using rustfmt --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 66e178b4..f3cb39f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use fs_err as fs; use serde::Deserialize; use tracing::{error, instrument, warn, Level}; use tracing_error::ErrorLayer; +use tracing_subscriber::fmt::format::PrettyFields; use tracing_subscriber::{ filter, fmt::{self as tracing_fmt}, @@ -20,7 +21,6 @@ use tracing_subscriber::{ util::SubscriberInitExt, EnvFilter, }; -use tracing_subscriber::fmt::format::PrettyFields; use kit::{ boot_fake_node, boot_real_node, build, build_start_package, chain, connect, dev_ui, From 86fa890073e4b4fa2da731ab9643c1cd6442a63f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurij=20Juki=C4=87?= Date: Thu, 23 Oct 2025 13:37:49 +0200 Subject: [PATCH 8/8] change formatting for cleaner diff --- src/main.rs | 59 +++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/src/main.rs b/src/main.rs index f3cb39f7..4f96df66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,38 +129,35 @@ fn init_tracing(log_path: PathBuf) -> tracing_appender::non_blocking::WorkerGuar .add_directive("hyper=off".parse().unwrap()) .add_directive("reqwest=off".parse().unwrap()); - let stdout_fields = PrettyFields::new().display_messages(); - let stderr_fields = PrettyFields::new().display_messages(); - - let stdout_layer = tracing_fmt::layer() - .event_format(AnsiPreservingFormatter::new( - tracing_fmt::format() - .without_time() - .with_level(false) - .with_target(false), - )) - .fmt_fields(stdout_fields) - .with_writer(std::io::stdout) - .with_ansi(true) - .with_filter(stdout_filter); - - let stderr_layer = tracing_fmt::layer() - .event_format(AnsiPreservingFormatter::new( - tracing_fmt::format() - .without_time() - .with_level(true) - .with_target(false) - .with_file(true) - .with_line_number(true), - )) - .fmt_fields(stderr_fields) - .with_writer(std::io::stderr) - .with_ansi(true) - .with_filter(stderr_filter); - tracing_subscriber::registry() - .with(stdout_layer) - .with(stderr_layer) + .with( + tracing_fmt::layer() + .event_format(AnsiPreservingFormatter::new( + tracing_fmt::format() + .without_time() + .with_level(false) + .with_target(false), + )) + .fmt_fields(PrettyFields::new().display_messages()) + .with_writer(std::io::stdout) + .with_ansi(true) + .with_filter(stdout_filter), + ) + .with( + tracing_fmt::layer() + .event_format(AnsiPreservingFormatter::new( + tracing_fmt::format() + .without_time() + .with_level(true) + .with_target(false) + .with_file(true) + .with_line_number(true), + )) + .fmt_fields(PrettyFields::new().display_messages()) + .with_writer(std::io::stderr) + .with_ansi(true) + .with_filter(stderr_filter), + ) .with( tracing_fmt::layer() .with_writer(non_blocking)