Skip to content

Commit abe0178

Browse files
authored
fix: use stderr for diagnostic data (#782)
1 parent d6a4251 commit abe0178

File tree

8 files changed

+25
-28
lines changed

8 files changed

+25
-28
lines changed

src/compile/algebra.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub const DEBUG: bool = false;
1717
macro_rules! dbgln {
1818
($($arg:tt)*) => {
1919
if DEBUG {
20-
println!($($arg)*); // Allow println
20+
eprintln!($($arg)*);
2121
}
2222
}
2323
}

src/compile/invert/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) const DEBUG: bool = false;
3232
macro_rules! dbgln {
3333
($($arg:tt)*) => {
3434
if crate::compile::invert::DEBUG {
35-
println!($($arg)*); // Allow println
35+
eprintln!($($arg)*);
3636
}
3737
}
3838
}

src/compile/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,7 @@ impl Compiler {
26062606
}
26072607
fn emit_diagnostic_impl(&mut self, diagnostic: Diagnostic) {
26082608
if self.print_diagnostics {
2609-
println!("{}", diagnostic.report()); // Allow println
2609+
eprintln!("{}", diagnostic.report());
26102610
} else {
26112611
self.diagnostics.insert(diagnostic);
26122612
}

src/compile/optimize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) const DEBUG: bool = false;
77
macro_rules! dbgln {
88
($($arg:tt)*) => {
99
if DEBUG {
10-
println!($($arg)*); // Allow println
10+
eprintln!($($arg)*);
1111
}
1212
}
1313
}

src/main.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static PRESSED_CTRL_C: AtomicBool = AtomicBool::new(false);
3636
static WATCH_CHILD: Lazy<Mutex<Option<Child>>> = Lazy::new(Default::default);
3737

3838
fn fail<T>(e: UiuaError) -> T {
39-
println!("{}", e.report());
39+
eprintln!("{}", e.report());
4040
exit(1)
4141
}
4242

@@ -72,7 +72,7 @@ fn main() {
7272
if let Some(ch) = &mut *child {
7373
_ = ch.kill();
7474
*child = None;
75-
println!("# Program interrupted");
75+
eprintln!("# Program interrupted");
7676
print_watching();
7777
} else {
7878
match App::try_parse().ok().and_then(|app| app.command) {
@@ -316,7 +316,7 @@ fn main() {
316316
.load_file(path)
317317
});
318318
if let Err(e) = &res {
319-
println!("{}", e.report());
319+
eprintln!("{}", e.report());
320320
}
321321
rt.print_reports();
322322
if res.is_err() {
@@ -529,7 +529,7 @@ fn run(
529529
let res = rt.compile_run(|comp| comp.mode(mode).print_diagnostics(true).load_file(path));
530530
if let Err(e) = &res {
531531
print_stack(&rt.take_stack(), !no_color);
532-
println!("{}", e.report());
532+
eprintln!("{}", e.report());
533533
}
534534
rt.print_reports();
535535
if res.is_err() {
@@ -629,7 +629,7 @@ impl WatchArgs {
629629
let mut watcher = notify::recommended_watcher(send)?;
630630
watcher.watch(Path::new("."), RecursiveMode::Recursive)?;
631631

632-
println!("Watching for changes... (end with ctrl+C, use `uiua help` to see options)");
632+
eprintln!("Watching for changes... (end with ctrl+C, use `uiua help` to see options)");
633633

634634
let config = FormatConfig::from_source(format_config_source, initial_path.as_deref()).ok();
635635
#[cfg(feature = "audio")]
@@ -709,14 +709,14 @@ impl WatchArgs {
709709
sleep(Duration::from_millis((i as u64 + 1) * 10))
710710
} else {
711711
clear_watching();
712-
println!("{}", e.report());
712+
eprintln!("{}", e.report());
713713
print_watching();
714714
return Ok(());
715715
}
716716
}
717717
}
718718
}
719-
println!("Failed to format file after {TRIES} tries");
719+
eprintln!("Failed to format file after {TRIES} tries");
720720
Ok(())
721721
};
722722
if let Some(path) = initial_path {
@@ -1042,7 +1042,7 @@ fn clear_watching() {
10421042
}
10431043

10441044
fn clear_watching_with(s: &str, end: &str) {
1045-
print!(
1045+
eprint!(
10461046
"\r{}{}",
10471047
s.repeat(terminal_size::terminal_size().map_or(10, |(w, _)| w.0 as usize)),
10481048
end,
@@ -1364,7 +1364,7 @@ fn update_modules(modules: &[PathBuf]) -> io::Result<()> {
13641364
.collect::<io::Result<_>>()?;
13651365
for (path, canonical) in modules.iter().zip(canonical) {
13661366
env::set_current_dir(&canonical)?;
1367-
println!("{} {}", "Updating".bold().bright_green(), path.display());
1367+
eprintln!("{} {}", "Updating".bold().bright_green(), path.display());
13681368
Command::new("git").args(["pull"]).spawn()?.wait()?;
13691369
}
13701370
Ok(())
@@ -1379,7 +1379,7 @@ fn check(path: Option<PathBuf>) -> UiuaResult {
13791379
let message_length = format!("Checking {} ({}/{})", path.display(), i + 1, path_count)
13801380
.chars()
13811381
.count();
1382-
print!(
1382+
eprint!(
13831383
"\r{} {} ({}/{}){}",
13841384
"Checking".bold().bright_green(),
13851385
path.display(),
@@ -1390,7 +1390,7 @@ fn check(path: Option<PathBuf>) -> UiuaResult {
13901390
stdout().flush().unwrap();
13911391
let mut comp = Compiler::with_backend(NativeSys);
13921392
if let Err(e) = comp.load_file(path) {
1393-
println!("\n{}", e.report());
1393+
eprintln!("\n{}", e.report());
13941394
} else {
13951395
successes += 1;
13961396
}
@@ -1410,7 +1410,7 @@ fn check(path: Option<PathBuf>) -> UiuaResult {
14101410
} else {
14111411
Color::BrightYellow
14121412
};
1413-
println!(
1413+
eprintln!(
14141414
"\r{}{}",
14151415
message.color(color),
14161416
" ".repeat(width.saturating_sub(message.chars().count()))

src/run.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl Uiua {
276276
/// Print all pending reports
277277
pub fn print_reports(&mut self) {
278278
for report in self.take_reports() {
279-
println!("{report}"); // Allow println
279+
eprintln!("{report}");
280280
}
281281
}
282282
/// Take the assembly
@@ -793,8 +793,7 @@ impl Uiua {
793793
if self.rt.time_instrs {
794794
let end_time = self.rt.backend.now();
795795
let padding = self.rt.call_stack.len().saturating_sub(1) * 2;
796-
#[rustfmt::skip]
797-
println!( // Allow println
796+
eprintln!(
798797
" ⏲{:padding$}{:.2}ms - {}",
799798
"",
800799
end_time - self.rt.last_time,

src/run_prim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ mod tests {
20522052
{
20532053
continue;
20542054
}
2055-
println!("{prim} example:\n{}", ex.input); // Allow println
2055+
eprintln!("{prim} example:\n{}", ex.input);
20562056
let mut env = Uiua::with_backend(SafeSys::with_thread_spawning());
20572057
match env.run_str(&ex.input) {
20582058
Ok(mut comp) => {

src/sys/native.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,17 +1215,16 @@ impl SysBackend for NativeSys {
12151215
return Ok(true);
12161216
}
12171217
match env.span() {
1218-
#[rustfmt::skip]
1219-
Span::Code(span) => println!( // Allow println
1218+
Span::Code(span) => eprintln!(
12201219
"{} at {span} {}",
12211220
"&b".truecolor(237, 94, 106),
12221221
"(press enter to continue)".bright_black()
12231222
),
12241223
Span::Builtin => {}
12251224
}
1226-
println!(); // Allow println
1225+
eprintln!();
12271226
print_stack(env.stack(), true);
1228-
println!(); // Allow println
1227+
eprintln!();
12291228
_ = stdin().read_line(&mut String::new());
12301229
Ok(true)
12311230
}
@@ -1244,8 +1243,7 @@ pub fn print_stack(stack: &[Value], color: bool) {
12441243
)
12451244
.send();
12461245
_ = Request::ClearBeforeNext.send();
1247-
#[rustfmt::skip]
1248-
println!( // Allow println
1246+
eprintln!(
12491247
"{} value{} displayed in window",
12501248
stack.len(),
12511249
if stack.len() == 1 { "" } else { "s" }
@@ -1257,7 +1255,7 @@ pub fn print_stack(stack: &[Value], color: bool) {
12571255
}
12581256
if stack.len() == 1 || !color {
12591257
for value in stack {
1260-
println!("{}", value.show()); // Allow println
1258+
eprintln!("{}", value.show());
12611259
}
12621260
return;
12631261
}
@@ -1276,6 +1274,6 @@ pub fn print_stack(stack: &[Value], color: bool) {
12761274
5 => (w, b, w),
12771275
_ => unreachable!(),
12781276
};
1279-
println!("{}", value.show().truecolor(r, g, b)); // Allow println
1277+
eprintln!("{}", value.show().truecolor(r, g, b));
12801278
}
12811279
}

0 commit comments

Comments
 (0)