fix(logging): address Copilot review findings

- Normalize nil logger to DiscardHandler in NewLogIgnorePluginLoadErrorFilterFunc
- Normalize nil logger to DiscardHandler in newWaitValue and cmdGetDryRunFlagStrategy
- Fix inverted errNoValue condition in processDependencyConditions: ErrNoValue
  means the condition key is absent (normal case), so warn only on real errors
- Initialize NewConfiguration with a discard logger handler so SDK consumers
  get nil-safe behavior without additional setup

Signed-off-by: JaeguKim <rlaworn1993@gmail.com>
pull/31833/head
JaeguKim 5 months ago
parent 10e993a5ec
commit 1f7901388c

@ -55,8 +55,8 @@ func processDependencyConditions(reqs []*chart.Dependency, cvals common.Values,
break
}
logger.Warn("returned non-bool value", "path", c, "chart", r.Name)
} else if errors.As(err, &errNoValue) {
// this is a real error
} else if !errors.As(err, &errNoValue) {
// ErrNoValue means the condition key is absent, which is normal; warn on real errors only
logger.Warn("the method PathValue returned error", slog.Any("error", err))
}
}

@ -162,6 +162,9 @@ func LoadDir(dirname string) (Plugin, error) {
// NewLogIgnorePluginLoadErrorFilterFunc returns an ErrorFilterFunc that logs
// plugin load errors using the provided logger and ignores them.
func NewLogIgnorePluginLoadErrorFilterFunc(logger *slog.Logger) ErrorFilterFunc {
if logger == nil {
logger = slog.New(slog.DiscardHandler)
}
return func(pluginYAML string, err error) error {
logger.Warn("failed to load plugin (ignoring)", slog.String("plugin_yaml", pluginYAML), slog.Any("error", err))
return nil

@ -157,6 +157,7 @@ func ConfigurationSetLogger(h slog.Handler) ConfigurationOption {
func NewConfiguration(options ...ConfigurationOption) *Configuration {
c := &Configuration{}
c.SetLogger(slog.NewTextHandler(io.Discard, nil))
for _, o := range options {
o(c)

@ -72,6 +72,9 @@ type waitValue struct {
func newWaitValue(defaultValue kube.WaitStrategy, ws *kube.WaitStrategy, logger *slog.Logger) *waitValue {
*ws = defaultValue
if logger == nil {
logger = slog.New(slog.DiscardHandler)
}
return &waitValue{ws: ws, logger: logger}
}

@ -43,6 +43,9 @@ func addDryRunFlag(cmd *cobra.Command) {
// Determine the `action.DryRunStrategy` given -dry-run=<value>` flag (or absence of)
// Legacy usage of the flag: boolean values, and `--dry-run` (without value) are supported, and log warnings emitted
func cmdGetDryRunFlagStrategy(cmd *cobra.Command, isTemplate bool, logger *slog.Logger) (action.DryRunStrategy, error) {
if logger == nil {
logger = slog.New(slog.DiscardHandler)
}
f := cmd.Flag("dry-run")
v := f.Value.String()

Loading…
Cancel
Save