From d164c97ad2b70a28e564a7c1ae57ef852b1b88de Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Mon, 12 Jan 2026 20:55:05 +0530 Subject: [PATCH] Fix multi-line error messages in compact tool output The truncate_for_display() function now takes only the first line of input before truncating. This prevents multi-line error messages (like str_replace failures) from breaking the compact single-line format. Added tests for multi-line input handling. --- crates/g3-core/src/streaming.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/g3-core/src/streaming.rs b/crates/g3-core/src/streaming.rs index 72bd0e6..e96ee77 100644 --- a/crates/g3-core/src/streaming.rs +++ b/crates/g3-core/src/streaming.rs @@ -223,9 +223,11 @@ pub fn log_stream_error( error!("=== END STREAM ERROR ==="); } -/// Truncate a string value for display, respecting UTF-8 boundaries +/// Truncate a string value for display, respecting UTF-8 boundaries. +/// Takes only the first line to avoid multi-line output in compact display. pub fn truncate_for_display(s: &str, max_len: usize) -> String { - if s.len() <= max_len { + let s = s.lines().next().unwrap_or(s); + if s.chars().count() <= max_len { s.to_string() } else { let truncated: String = s.char_indices().take(max_len).map(|(_, c)| c).collect(); @@ -420,6 +422,9 @@ mod tests { fn test_truncate_for_display() { assert_eq!(truncate_for_display("short", 10), "short"); assert_eq!(truncate_for_display("this is long", 5), "this ..."); + // Multi-line input should only use first line + assert_eq!(truncate_for_display("first line\nsecond line", 20), "first line"); + assert_eq!(truncate_for_display("❌ Error\nDetails here", 10), "❌ Error"); } #[test]