Skip to content

Commit

Permalink
fix: recover from panic in compose library parse function
Browse files Browse the repository at this point in the history
Signed-off-by: Harikrishnan Balagopal <[email protected]>
  • Loading branch information
HarikrishnanBalagopal committed Oct 18, 2024
1 parent e02fdfb commit 8b2d2d1
Showing 1 changed file with 14 additions and 2 deletions.
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 @@ func removeNonExistentEnvFilesV2(path string) preprocessFunc {
}
}

// 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 @@ func parseV2(path string, interpolate bool) (*project.Project, error) {
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)
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

0 comments on commit 8b2d2d1

Please sign in to comment.