Skip to content

Commit 70d014d

Browse files
committed
fix panic issue when extends.service is not present
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 0588281 commit 70d014d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

loader/extends.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ func applyServiceExtends(ctx context.Context, name string, services map[string]a
6868
)
6969
switch v := extends.(type) {
7070
case map[string]any:
71-
ref = v["service"].(string)
71+
ref, ok = v["service"].(string)
72+
if !ok {
73+
return nil, fmt.Errorf("extends.%s.service is required", name)
74+
}
7275
file = v["file"]
7376
opts.ProcessEvent("extends", v)
7477
case string:

loader/extends_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ services:
184184
assert.NilError(t, err)
185185
}
186186

187+
func TestExtendsWihtMissingService(t *testing.T) {
188+
yaml := `
189+
name: test-extends-port
190+
services:
191+
test:
192+
image: test
193+
extends:
194+
file: testdata/extends/base.yaml
195+
`
196+
abs, err := filepath.Abs(".")
197+
assert.NilError(t, err)
198+
199+
_, err = LoadWithContext(context.Background(), types.ConfigDetails{
200+
ConfigFiles: []types.ConfigFile{
201+
{
202+
Content: []byte(yaml),
203+
Filename: "(inline)",
204+
},
205+
},
206+
WorkingDir: abs,
207+
}, func(options *Options) {
208+
options.ResolvePaths = false
209+
options.SkipValidation = true
210+
})
211+
assert.Error(t, err, "extends.test.service is required")
212+
}
213+
187214
func TestIncludeWithExtends(t *testing.T) {
188215
yaml := `
189216
name: test-include-with-extends

0 commit comments

Comments
 (0)