From f80650e8ce55212d9e576e4838a799bade41cd14 Mon Sep 17 00:00:00 2001 From: Ed Overton Date: Fri, 16 Feb 2024 12:10:55 -0500 Subject: [PATCH] fix: improve accumulation failure message For accumulation errors when the file load fails due to malformed YAML and the base load fails due to a timeout, report both errors. Previously only the malformed YAML error was returned, masking the git repo timeout. --- api/internal/target/kusttarget.go | 9 ++++++++- api/internal/utils/errtimeout.go | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/internal/target/kusttarget.go b/api/internal/target/kusttarget.go index eefa1ac63..44c82bc59 100644 --- a/api/internal/target/kusttarget.go +++ b/api/internal/target/kusttarget.go @@ -425,7 +425,14 @@ func (kt *KustTarget) accumulateResources( } ldr, err := kt.ldr.New(path) if err != nil { - if kusterr.IsMalformedYAMLError(errF) { // Some error occurred while tyring to decode YAML file + // If accumulateFile found malformed YAML and there was a failure + // loading the resource as a base, then the resource is likely a + // file. The loader failure message is unnecessary, and could be + // confusing. Report only the file load error. + // + // However, a loader timeout implies there is a git repo at the + // path. In that case, both errors could be important. + if kusterr.IsMalformedYAMLError(errF) && !utils.IsErrTimeout(err) { return nil, errF } return nil, errors.WrapPrefixf( diff --git a/api/internal/utils/errtimeout.go b/api/internal/utils/errtimeout.go index c1761d2c6..a0d861c7b 100644 --- a/api/internal/utils/errtimeout.go +++ b/api/internal/utils/errtimeout.go @@ -15,11 +15,11 @@ type errTimeOut struct { cmd string } -func NewErrTimeOut(d time.Duration, c string) errTimeOut { - return errTimeOut{duration: d, cmd: c} +func NewErrTimeOut(d time.Duration, c string) *errTimeOut { + return &errTimeOut{duration: d, cmd: c} } -func (e errTimeOut) Error() string { +func (e *errTimeOut) Error() string { return fmt.Sprintf("hit %s timeout running '%s'", e.duration, e.cmd) }