Skip to content

Commit 53b8c63

Browse files
idsulikndeloof
authored andcommitted
fix(extends): fix extends related logs
Signed-off-by: Suleiman Dibirov <[email protected]>
1 parent 3336f59 commit 53b8c63

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

loader/extends.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,17 @@ func applyServiceExtends(ctx context.Context, name string, services map[string]a
8282
)
8383

8484
if file != nil {
85-
filename = file.(string)
86-
services, processor, err = getExtendsBaseFromFile(ctx, ref, filename, opts, tracker)
85+
refFilename := file.(string)
86+
services, processor, err = getExtendsBaseFromFile(ctx, name, ref, filename, refFilename, opts, tracker)
8787
post = append(post, processor)
8888
if err != nil {
8989
return nil, err
9090
}
91+
filename = refFilename
9192
} else {
9293
_, ok := services[ref]
9394
if !ok {
94-
return nil, fmt.Errorf("cannot extend service %q in %s: service not found", name, filename)
95+
return nil, fmt.Errorf("cannot extend service %q in %s: service %q not found", name, filename, ref)
9596
}
9697
}
9798

@@ -127,17 +128,17 @@ func applyServiceExtends(ctx context.Context, name string, services map[string]a
127128
return merged, nil
128129
}
129130

130-
func getExtendsBaseFromFile(ctx context.Context, name string, path string, opts *Options, ct *cycleTracker) (map[string]any, PostProcessor, error) {
131+
func getExtendsBaseFromFile(ctx context.Context, name, ref string, path, refPath string, opts *Options, ct *cycleTracker) (map[string]any, PostProcessor, error) {
131132
for _, loader := range opts.ResourceLoaders {
132-
if !loader.Accept(path) {
133+
if !loader.Accept(refPath) {
133134
continue
134135
}
135-
local, err := loader.Load(ctx, path)
136+
local, err := loader.Load(ctx, refPath)
136137
if err != nil {
137138
return nil, nil, err
138139
}
139140
localdir := filepath.Dir(local)
140-
relworkingdir := loader.Dir(path)
141+
relworkingdir := loader.Dir(refPath)
141142

142143
extendsOpts := opts.clone()
143144
// replace localResourceLoader with a new flavour, using extended file base path
@@ -157,9 +158,15 @@ func getExtendsBaseFromFile(ctx context.Context, name string, path string, opts
157158
return nil, nil, err
158159
}
159160
services := source["services"].(map[string]any)
160-
_, ok := services[name]
161+
_, ok := services[ref]
161162
if !ok {
162-
return nil, nil, fmt.Errorf("cannot extend service %q in %s: service not found", name, path)
163+
return nil, nil, fmt.Errorf(
164+
"cannot extend service %q in %s: service %q not found in %s",
165+
name,
166+
path,
167+
ref,
168+
refPath,
169+
)
163170
}
164171

165172
var remotes []paths.RemoteResource
@@ -173,7 +180,7 @@ func getExtendsBaseFromFile(ctx context.Context, name string, path string, opts
173180

174181
return services, processor, nil
175182
}
176-
return nil, nil, fmt.Errorf("cannot read %s", path)
183+
return nil, nil, fmt.Errorf("cannot read %s", refPath)
177184
}
178185

179186
func deepClone(value any) any {

0 commit comments

Comments
 (0)