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: recover from panic in compose library parse function #1197

Merged
Merged
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions transformer/compose/v1v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
}
}

// parseV2 parses version 2 compose files
func parseV2(path string, interpolate bool) (*project.Project, error) {
// panicky_parseV2 parses version 2 compose files (can panic on proj.Parse())
func panicky_parseV2(path string, interpolate bool) (*project.Project, error) {

Check failure on line 91 in transformer/compose/v1v2.go

View workflow job for this annotation

GitHub Actions / Build and test

don't use underscores in Go names; func panicky_parseV2 should be panickyParseV2 (golint)
context := project.Context{}
context.ComposeFiles = []string{path}
context.ResourceLookup = new(lookup.FileResourceLookup)
Expand Down Expand Up @@ -124,6 +124,18 @@
return proj, nil
}

// parseV2 parses version 2 compose files while capturing panics
func parseV2(path string, interpolate bool) (result *project.Project, err error) {
defer func() {
if r := recover(); r != nil {
logrus.Errorf("recovered from panic in panicky_parseV2: %q", r)
err = fmt.Errorf("panicky_parseV2 failed: %q", r)
}
}()
result, err = panicky_parseV2(path, interpolate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it sufficient to wrap only err = proj.Parse() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return result, err
}

// ConvertToIR loads a compose file to IR
func (c *v1v2Loader) ConvertToIR(composefilepath string, serviceName string, parseNetwork bool) (ir irtypes.IR, err error) {
proj, err := parseV2(composefilepath, true)
Expand Down
Loading