chore: add a workaround for slog calls in config.Load leaking to stderr

Ayman Bagabas created

Change summary

internal/cmd/root.go | 9 +++++++++
1 file changed, 9 insertions(+)

Detailed changes

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.