From 40c426a95088174708be1d97d0f5bb1e48855427 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Sun, 22 Mar 2026 12:52:44 +0300 Subject: [PATCH] chore: add a workaround for slog calls in config.Load leaking to stderr --- internal/cmd/root.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 26684aae09a475a50eceeb0daafccacfb45584df..62f5d90b74531081ff4473c1ca3612cdbfc52ae0 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -157,6 +157,15 @@ const defaultVersionTemplate = `{{with .DisplayName}}{{printf "%s " .}}{{end}}{{ ` func Execute() { + // FIXME: config.Load uses slog internally during provider resolution, + // but the file-based logger isn't set up until after config is loaded + // (because the log path depends on the data directory from config). + // This creates a window where slog calls in config.Load leak to + // stderr. We discard early logs here as a workaround. The proper + // fix is to remove slog calls from config.Load and have it return + // warnings/diagnostics instead of logging them as a side effect. + slog.SetDefault(slog.New(slog.DiscardHandler)) + // NOTE: very hacky: we create a colorprofile writer with STDOUT, then make // it forward to a bytes.Buffer, write the colored heartbit to it, and then // finally prepend it in the version template.