on main help sign in
chore: add a workaround for slog calls in config.Load leaking to stderr
commit40c426a95088174708be1d97d0f5bb1e48855427 authorAyman Bagabas <ayman.bagabas@gmail.com> dateSun 22 Mar 2026, 12:52 (7 months ago) parent9a63da5
1 file changed+9
internal/cmd/root.go+9
internal/cmd/root.go+9
@@ -157,6 +157,15 @@ const defaultVersionTemplate = `{{with .DisplayName}}{{printf "%s " .}}{{end}}{{
157157`
158158
159159func Execute() {
160+ // FIXME: config.Load uses slog internally during provider resolution,
161+ // but the file-based logger isn't set up until after config is loaded
162+ // (because the log path depends on the data directory from config).
163+ // This creates a window where slog calls in config.Load leak to
164+ // stderr. We discard early logs here as a workaround. The proper
165+ // fix is to remove slog calls from config.Load and have it return
166+ // warnings/diagnostics instead of logging them as a side effect.
167+ slog.SetDefault(slog.New(slog.DiscardHandler))
168+
160169 // NOTE: very hacky: we create a colorprofile writer with STDOUT, then make
161170 // it forward to a bytes.Buffer, write the colored heartbit to it, and then
162171 // finally prepend it in the version template.