Skip to content

Fix warnings not being printed #560

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

Merged
merged 1 commit into from
Apr 16, 2025

Conversation

JoaquinTrinanes
Copy link
Contributor

Since a few days ago (so I assume starting at direnv 2.36.0), the DIRENV_LOG_FORMAT environment variable is not set by default. This breaks nix-direnv every time it's called with strict_env due to an unbound variable error.

Even if the variable was accessed safely, warnings won't be rendered anymore because it's empty and we skip printing anything when that happens.

With this approach, we use the stdlib log_status, and just wrap it around ANSI escapes for the yellow color.

This has the advantage of delegating the logging format logic back to direnv, but it might be possible that at some point in the future direnv sanitizes the strings and breaks this solution. However, the alternative is to keep relying on DIRENV_LOG_FORMAT, which will break by default, and in doing so we would also be ignoring the new log_format option in direnv.toml.


Other thing I tried to get colored logs "idiomatically" was to embed them inside the log_status arguments, not around it:

log_status "$(printf "%b" $color_warning)${_NIX_DIRENV_LOG_PREFIX}${msg}$(printf "%b" $color_normal)"

This makes the output look like this (note that the direnv: prefix is not colored):
image

But it would be a valid alternative if, for example, the behaviour at direnv/direnv#884 is restored.

@JoaquinTrinanes JoaquinTrinanes changed the title Fix warnings not beint printed Fix warnings not being printed Apr 16, 2025
@Mic92 Mic92 merged commit 74adaf6 into nix-community:master Apr 16, 2025
6 checks passed
@JoaquinTrinanes JoaquinTrinanes deleted the fix/invalid-warnings branch April 16, 2025 12:13
@lf- lf- mentioned this pull request May 8, 2025
@StabbarN
Copy link

StabbarN commented Jun 7, 2025

I had to add

[global]
log_format = "direnv: %s"

in my direnv.toml to get the warning color.

I'm unsure why but I hope it helps someone.

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