@@ -87,8 +87,20 @@ func removeNonExistentEnvFilesV2(path string) preprocessFunc {
87
87
}
88
88
}
89
89
90
- // panicky_parseV2 parses version 2 compose files (can panic on proj.Parse())
91
- func panicky_parseV2 (path string , interpolate bool ) (* project.Project , error ) {
90
+ // parseCapturingPanics parses version 2 compose files while capturing panics
91
+ func parseCapturingPanics (proj * project.Project ) (err error ) {
92
+ defer func () {
93
+ if r := recover (); r != nil {
94
+ err = fmt .Errorf ("recovered from panic in compose Project.Parse: %q" , r )
95
+ logrus .Error (err )
96
+ }
97
+ }()
98
+ err = proj .Parse ()
99
+ return err
100
+ }
101
+
102
+ // parseV2 parses version 2 compose files
103
+ func parseV2 (path string , interpolate bool ) (* project.Project , error ) {
92
104
context := project.Context {}
93
105
context .ComposeFiles = []string {path }
94
106
context .ResourceLookup = new (lookup.FileResourceLookup )
@@ -114,7 +126,7 @@ func panicky_parseV2(path string, interpolate bool) (*project.Project, error) {
114
126
proj := project .NewProject (& context , nil , & parseOptions )
115
127
originalLevel := logrus .GetLevel ()
116
128
logrus .SetLevel (logrus .FatalLevel ) // TODO: this is a hack to prevent libcompose from printing errors to the console.
117
- err = proj . Parse ( )
129
+ err = parseCapturingPanics ( proj )
118
130
logrus .SetLevel (originalLevel ) // TODO: this is a hack to prevent libcompose from printing errors to the console.
119
131
if err != nil {
120
132
err := fmt .Errorf ("failed to load docker compose file at path %s Error: %q" , path , err )
@@ -124,18 +136,6 @@ func panicky_parseV2(path string, interpolate bool) (*project.Project, error) {
124
136
return proj , nil
125
137
}
126
138
127
- // parseV2 parses version 2 compose files while capturing panics
128
- func parseV2 (path string , interpolate bool ) (result * project.Project , err error ) {
129
- defer func () {
130
- if r := recover (); r != nil {
131
- logrus .Errorf ("recovered from panic in panicky_parseV2: %q" , r )
132
- err = fmt .Errorf ("panicky_parseV2 failed: %q" , r )
133
- }
134
- }()
135
- result , err = panicky_parseV2 (path , interpolate )
136
- return result , err
137
- }
138
-
139
139
// ConvertToIR loads a compose file to IR
140
140
func (c * v1v2Loader ) ConvertToIR (composefilepath string , serviceName string , parseNetwork bool ) (ir irtypes.IR , err error ) {
141
141
proj , err := parseV2 (composefilepath , true )
0 commit comments