From 7220bea2b7db604d151c8c92e9637ce7cea968a6 Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Mon, 11 Mar 2024 19:41:46 -0700 Subject: [PATCH] Fix `runsc --debug` config output. For non-string flags, `reflect.Value.String()` returns something like `` or `` rather than the stringified version of the value. So we convert the `reflect.Value` to an `interface{}` first so that stringification works as expected. PiperOrigin-RevId: 614879158 --- runsc/config/config.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/runsc/config/config.go b/runsc/config/config.go index 822bcd93b..d97ba3aab 100644 --- a/runsc/config/config.go +++ b/runsc/config/config.go @@ -404,9 +404,15 @@ func (c *Config) Log() { st := obj.Type() for i := 0; i < st.NumField(); i++ { f := st.Field(i) - val := obj.Field(i).String() - if val == "" { + var val any + if strVal := obj.Field(i).String(); strVal == "" { val = "(empty)" + } else if !f.IsExported() { + // Cannot convert to `interface{}` for non-exported fields, + // so just use `strVal`. + val = fmt.Sprintf("%s (unexported)", strVal) + } else { + val = obj.Field(i).Interface() } if flagName, hasFlag := f.Tag.Lookup("flag"); hasFlag { log.Debugf("Config.%s (--%s): %v", f.Name, flagName, val)