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 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
14 changes: 13 additions & 1 deletion transformer/compose/v1v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ func removeNonExistentEnvFilesV2(path string) preprocessFunc {
}
}

// parseCapturingPanics parses version 2 compose files while capturing panics
func parseCapturingPanics(proj *project.Project) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("recovered from panic in compose Project.Parse: %q", r)
logrus.Error(err)
}
}()
err = proj.Parse()
return err
}

// parseV2 parses version 2 compose files
func parseV2(path string, interpolate bool) (*project.Project, error) {
context := project.Context{}
Expand Down Expand Up @@ -114,7 +126,7 @@ func parseV2(path string, interpolate bool) (*project.Project, error) {
proj := project.NewProject(&context, nil, &parseOptions)
originalLevel := logrus.GetLevel()
logrus.SetLevel(logrus.FatalLevel) // TODO: this is a hack to prevent libcompose from printing errors to the console.
err = proj.Parse()
err = parseCapturingPanics(proj)
logrus.SetLevel(originalLevel) // TODO: this is a hack to prevent libcompose from printing errors to the console.
if err != nil {
err := fmt.Errorf("failed to load docker compose file at path %s Error: %q", path, err)
Expand Down
Loading