Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Disable color output when redirecting stderr #742

Merged
merged 1 commit into from
Jan 4, 2024
Merged

Conversation

konstin
Copy link
Member

@konstin konstin commented Jan 2, 2024

I'm still confused about it, but this seems to do the right thing?

HierarchicalLayer internally has let ansi = io::stderr().is_terminal();, so the logging itself is already correctly uncolored, but errors in the log weren't.

Test command, ran with network deactivated:

RUST_LOG=debug cargo run --bin puffin -- pip-compile -v ./scripts/popular_packages/pypi_8k_downloads.txt 2> log.txt

Before

�[1;31merror�[0m: Request error: error sending request for url (https://pypi.org/simple/apache-airflow-providers-dbt-cloud/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  �[1;31mCaused by�[0m: error sending request for url (https://pypi.org/simple/apache-airflow-providers-dbt-cloud/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  �[1;31mCaused by�[0m: error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  �[1;31mCaused by�[0m: dns error: failed to lookup address information: Temporary failure in name resolution
  �[1;31mCaused by�[0m: failed to lookup address information: Temporary failure in name resolution

After

error: Request error: error sending request for url (https://pypi.org/simple/fissix/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: error sending request for url (https://pypi.org/simple/fissix/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: failed to lookup address information: Temporary failure in name resolution

I'm still confused about it, but this seems to do the right thing?

Test command, ran with network deactivated:

```shell
RUST_LOG=debug cargo run --bin puffin -- pip-compile -v ./scripts/popular_packages/pypi_8k_downloads.txt 2> log.txt
```

**Before**

```
�[1;31merror�[0m: Request error: error sending request for url (https://pypi.org/simple/apache-airflow-providers-dbt-cloud/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  �[1;31mCaused by�[0m: error sending request for url (https://pypi.org/simple/apache-airflow-providers-dbt-cloud/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  �[1;31mCaused by�[0m: error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
  �[1;31mCaused by�[0m: dns error: failed to lookup address information: Temporary failure in name resolution
  �[1;31mCaused by�[0m: failed to lookup address information: Temporary failure in name resolution
  ```

  **After**

  ```
  error: Request error: error sending request for url (https://pypi.org/simple/fissix/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
    Caused by: error sending request for url (https://pypi.org/simple/fissix/): error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
    Caused by: error trying to connect: dns error: failed to lookup address information: Temporary failure in name resolution
    Caused by: dns error: failed to lookup address information: Temporary failure in name resolution
    Caused by: failed to lookup address information: Temporary failure in name resolution
```
@charliermarsh
Copy link
Member

Can we find a way to do this with anstream?

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this if it fixes the issue, but from a quick look at puffin's dependencies, it seems like we're using no fewer than three different terminal coloring libraries? (I see anstream, colored and nu-ansi-term.) It'd be nice to fix that, and I agree that we should pick anstream.

@konstin konstin merged commit 9b77a88 into main Jan 4, 2024
3 checks passed
@konstin konstin deleted the tty-color-redirect branch January 4, 2024 15:43
charliermarsh added a commit that referenced this pull request Jan 7, 2024
## Summary

We can use `anstream` for all color control, rather than going through
`colored`. Note that we still need the `colored` crate, since `colored`
and `anstream` solve different problems. (`anstream` recommends using
`owo-colors` alongside it, but `colored` seems to work fine?)

Resolves the issue raised in
#742 via `anstream` rather than
`colored`.

Closes #782.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants