Skip to content

Commit

Permalink
Improved errors handling for HCL functions (#3544)
Browse files Browse the repository at this point in the history
* Improved multi error handling

* multi error handling

* Lint error fixes
  • Loading branch information
denis256 authored Nov 11, 2024
1 parent 8f096d3 commit a4e26e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/config_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ func extractSopsErrors(err error) *errors.MultiError {
}

// append the original error if no group results were found
if errs == nil {
if errs.Len() == 0 {
errs = errs.Append(err)
}

Expand Down
12 changes: 12 additions & 0 deletions internal/errors/multierror.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,23 @@ func (errs *MultiError) Append(appendErrs ...error) *MultiError {
errs = &MultiError{inner: new(multierror.Error)}
}

if errs.inner == nil {
errs.inner = new(multierror.Error)
}

return &MultiError{inner: multierror.Append(errs.inner, appendErrs...)}
}

// Len implements sort.Interface function for length.
func (errs *MultiError) Len() int {
if errs == nil {
errs = &MultiError{inner: new(multierror.Error)}
}

if errs.inner == nil {
errs.inner = new(multierror.Error)
}

return len(errs.inner.Errors)
}

Expand Down
2 changes: 2 additions & 0 deletions test/integration_sops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ func TestSopsDecryptOnMissing(t *testing.T) {
require.Error(t, err)

assert.Contains(t, errorOut, "Encountered error while evaluating locals in file ./terragrunt.hcl")
assert.Contains(t, errorOut, "./missing.yaml: no such file")

}

0 comments on commit a4e26e2

Please sign in to comment.