Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error output from rustdoc is stripped of color #326

Closed
jyn514 opened this issue Jan 25, 2023 · 6 comments · Fixed by #360
Closed

Error output from rustdoc is stripped of color #326

jyn514 opened this issue Jan 25, 2023 · 6 comments · Fixed by #360
Labels
C-bug Category: doesn't meet expectations

Comments

@jyn514
Copy link

jyn514 commented Jan 25, 2023

Steps to reproduce the bug with the above code

  1. Create any cargo project (e.g. cargo new --lib example)
  2. Modify it so it doesn't compile (e.g. echo x > src/lib.rs)
  3. Run cargo semver-checks check-release

Actual Behaviour

The errors are printed without color:

Screenshot 2023-01-25 at 11 15 04 AM

Expected Behaviour

The errors are printed with color, just like cargo doc:

Screenshot 2023-01-25 at 11 15 47 AM

Generated System Information

Software version

cargo-semver-checks 0.16.2

Operating system

macOS 13.1 (Darwin 22.2.0)

Command-line

/Users/jyn/.local/lib/cargo/bin/cargo-semver-checks semver-checks --bugreport 

cargo version

> cargo -V 
cargo 1.68.0-nightly (a5d47a725 2023-01-16)

Compile time information

  • Profile: release
  • Target triple: aarch64-apple-darwin
  • Family: unix
  • OS: macos
  • Architecture: aarch64
  • Pointer width: 64
  • Endian: little
  • CPU features: aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh
  • Host: aarch64-apple-darwin

Build Configuration

; env | grep CARGO_
CARGO_HOME=/Users/jyn/.local/lib/cargo
CARGO_TARGET_DIR=/Users/jyn/.local/lib/cargo/target

Additional Context

I see that you're passing --json=diagnostic-rendered-ansi, so I'm not sure where the color stripping happens. Maybe cargo doesn't think it's being output to a terminal and you need to pass --color explicitly?

@jyn514 jyn514 added the C-bug Category: doesn't meet expectations label Jan 25, 2023
@jyn514
Copy link
Author

jyn514 commented Jan 25, 2023

Interestingly, this works fine when I pass -v, it's only the default output that has color stripped.

@obi1kenobi
Copy link
Owner

Thanks for the two bug reports, much appreciated! I also suspect "cargo doesn't think it's printing to a terminal" as the cause. Will look into it!

@tonowak
Copy link
Collaborator

tonowak commented Feb 9, 2023

I've looked into it a bit more:

Depending on whether we want silenced output or not (so whether we use e.g. --verbose or not), we capture the output (by pipe'ing) or we don't:

let stderr = if self.silence {
. When we don't capture, everything is fine. Otherwise, cargo doc sees that it's being piped and disables colors. An easy solution would be to pass --color=always to the cargo doc command (I've checked it and it works), or we could somehow try to capture the output in some other ways.

Is is OK to use --color=always? Honestly I don't even where to look for a terminal emulator without colors, to test whether it would work on machines without color.

@jyn514
Copy link
Author

jyn514 commented Feb 9, 2023

You can use atty::is(atty::Stream::Stdout) to detect if you're outputting to a terminal or not.

@tonowak
Copy link
Collaborator

tonowak commented Feb 9, 2023

I've implemented the suggestion in #360.

@obi1kenobi
Copy link
Owner

This will be out in the next release, ETA ~half an hour or so.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: doesn't meet expectations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants