From c05f72244edb9f7cd7566f4457d2052ff02e6791 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 2 Mar 2026 20:44:19 +0100 Subject: Lock stderr before writing errors --- oryxc/src/errors.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/oryxc/src/errors.rs b/oryxc/src/errors.rs index b9b5955..b2bab4e 100644 --- a/oryxc/src/errors.rs +++ b/oryxc/src/errors.rs @@ -10,11 +10,13 @@ use std::fmt::{ Display, Formatter, }; +use std::io::Write; use std::ops::Deref; use std::path::Path; use std::sync::OnceLock; use std::{ env, + io, process, }; @@ -145,24 +147,28 @@ impl OryxError { const ERRORBEG: &str = "\x1b[31;1m"; const FMTEND: &str = "\x1b[0m"; - eprintln!( - "{FNAMEBEG}{}:{line}:{col}:{FMTEND} {ERRORBEG}error:{FMTEND} {self}", + let mut handle = io::stderr().lock(); + let _ = write!( + handle, + "{FNAMEBEG}{}:{line}:{col}:{FMTEND} {ERRORBEG}error:{FMTEND} {self}\n", filename.as_ref().display() ); - eprintln!(" {line:>4} │ {errbeg}{ERRORBEG}{errmid}{FMTEND}{errend}"); + let _ = write!( + handle, + " {line:>4} │ {errbeg}{ERRORBEG}{errmid}{FMTEND}{errend}\n" + ); for _ in 0..nspaces(line) { - eprint!(" "); + let _ = write!(handle, " "); } - eprint!("│ "); + let _ = write!(handle, "│ "); for _ in 1..col { - eprint!(" "); + let _ = write!(handle, " "); } - eprint!("{ERRORBEG}"); + let _ = write!(handle, "{ERRORBEG}"); for _ in 0..errmid.width().max(1) { - eprint!("^"); + let _ = write!(handle, "^"); } - eprint!("{FMTEND}"); - eprintln!(); + let _ = write!(handle, "{FMTEND}\n"); } } -- cgit v1.2.3