Skip to content

Commit d340659

Browse files
committed
chore: enrich image push errors with errors from proxy to unregistry
1 parent 6fb68c2 commit d340659

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎pkg/client/image.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,15 @@ func (cli *Client) pushImageToMachine(
238238
proxyEventID := fmt.Sprintf("Proxy to unregistry on %s", boldStyle.Render(machine.Name))
239239
pw.Event(progress.StartingEvent(proxyEventID))
240240

241+
// The proxy runs in a goroutine. Capture the first error in a channel
242+
// so we can surface it alongside the push error if push fails.
243+
proxyErrCh := make(chan error, 1)
241244
// Forward local port 127.0.0.1:PORT to the machine's unregistry over the established client connection.
242245
unregProxy, err := newUnregistryProxy(ctx, unregistryAddr, dialer, func(err error) {
246+
select {
247+
case proxyErrCh <- fmt.Errorf("proxy to unregistry: %w", err):
248+
default:
249+
}
243250
pw.Event(progress.NewEvent(proxyEventID, progress.Error, err.Error()))
244251
})
245252
if err != nil {
@@ -321,6 +328,13 @@ func (cli *Client) pushImageToMachine(
321328
for msg := range pushCh {
322329
if msg.Err != nil {
323330
pw.Event(progress.NewEvent(pushEventID, progress.Error, msg.Err.Error()))
331+
// Include the proxy error (if any) to expose the root cause behind a generic push failure.
332+
select {
333+
case proxyErr := <-proxyErrCh:
334+
return fmt.Errorf("push image: %w", errors.Join(msg.Err, proxyErr))
335+
default:
336+
}
337+
324338
return fmt.Errorf("push image: %w", msg.Err)
325339
}
326340

0 commit comments

Comments
 (0)