Fix panic in buildx debug when solving fails
Closes #3822 Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
This commit is contained in:
+13
-5
@@ -220,16 +220,24 @@ func containerConfigFromError(solveErr *errdefs.SolveError, cfg *InvokeConfig) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// When a solve fails before its inputs/mounts have been resolved (for
|
||||||
|
// example, when computing the cache key for an exec op fails because an
|
||||||
|
// input source cannot be found), MountIDs/InputIDs may be empty or shorter
|
||||||
|
// than the declared mount list. Guard against that so callers (such as the
|
||||||
|
// debug adapter) get a clean error instead of an index-out-of-range panic.
|
||||||
|
ids := solveErr.MountIDs
|
||||||
|
if cfg.Initial {
|
||||||
|
ids = solveErr.InputIDs
|
||||||
|
}
|
||||||
|
if len(ids) < len(exec.Mounts) {
|
||||||
|
return nil, errors.Errorf("cannot start debug container: failing step has no mount results available (got %d of %d)", len(ids), len(exec.Mounts))
|
||||||
|
}
|
||||||
var mounts []gateway.Mount
|
var mounts []gateway.Mount
|
||||||
for i, mnt := range exec.Mounts {
|
for i, mnt := range exec.Mounts {
|
||||||
rid := solveErr.MountIDs[i]
|
|
||||||
if cfg.Initial {
|
|
||||||
rid = solveErr.InputIDs[i]
|
|
||||||
}
|
|
||||||
mounts = append(mounts, gateway.Mount{
|
mounts = append(mounts, gateway.Mount{
|
||||||
Selector: mnt.Selector,
|
Selector: mnt.Selector,
|
||||||
Dest: mnt.Dest,
|
Dest: mnt.Dest,
|
||||||
ResultID: rid,
|
ResultID: ids[i],
|
||||||
Readonly: mnt.Readonly,
|
Readonly: mnt.Readonly,
|
||||||
MountType: mnt.MountType,
|
MountType: mnt.MountType,
|
||||||
CacheOpt: mnt.CacheOpt,
|
CacheOpt: mnt.CacheOpt,
|
||||||
|
|||||||
Reference in New Issue
Block a user