Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resolver): recover panic during resolve #6511

Merged
merged 7 commits into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pkg/resolver/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package file

import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -46,6 +47,14 @@ func NewResolver(

// Resolve - replace or modifies in-memory content before parsing
func (r *Resolver) Resolve(fileContent []byte, path string, resolveCount int, resolvedFilesCache map[string]ResolvedFile) []byte {
// handle panic during resolve process
defer func() {
if r := recover(); r != nil {
err := fmt.Errorf("panic: %v", r)
log.Err(err).Msg("Recovered from panic during file resolve")
}
}()

if utils.Contains(filepath.Ext(path), []string{".yml", ".yaml"}) {
return r.yamlResolve(fileContent, path, resolveCount, resolvedFilesCache)
}
Expand All @@ -59,11 +68,11 @@ func (r *Resolver) Resolve(fileContent []byte, path string, resolveCount int, re
obj, _ = r.walk(fileContent, obj, obj, path, resolveCount, resolvedFilesCache)

b, err := r.marshler(obj)
if err != nil {
return fileContent
if err == nil {
return b
}

return b
return fileContent
}

func (r *Resolver) walk(
Expand Down
Loading