Skip to content

toSecret' "return nil, nil" is error-prone #790

Description

@machine424

here

func toSecret(secretManager SecretManager, text Secret, file, ref string) (SecretReader, error) {
if text != "" {
return NewInlineSecret(string(text)), nil
}
if file != "" {
return NewFileSecret(file), nil
}
if ref != "" {
if secretManager == nil {
return nil, errors.New("cannot use secret ref without manager")
}
return &refSecret{
ref: ref,
manager: secretManager,
}, nil
}
return nil, nil

because the error is nil, we may/would be moving nils around, leading to nil pointer dereference

may be the cause of prometheus/prometheus#16622

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions