From cc911b4e09d86ff8d704dd9250a5895db28b36e7 Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Wed, 24 Jul 2024 14:22:07 +0200 Subject: [PATCH] fix: do not indicate timeout when context is canceled When a user quits nctl while it is waiting for create/delete, we should only show "timeout waiting for ..." if the context deadline is reached. If the contact was simply canceled we should just exit without a special message. --- create/create.go | 14 ++++++++++---- delete/delete.go | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/create/create.go b/create/create.go index b0eacbd..a121892 100644 --- a/create/create.go +++ b/create/create.go @@ -218,11 +218,17 @@ func (w *waitStage) watch(ctx context.Context, client *api.Client) error { return nil } case <-ctx.Done(): - msg := "timeout waiting for %s" - w.spinner.StopFailMessage(format.ProgressMessagef("", msg, w.kind)) - _ = w.spinner.StopFail() + switch ctx.Err() { + case context.DeadlineExceeded: + msg := "timeout waiting for %s" + w.spinner.StopFailMessage(format.ProgressMessagef("", msg, w.kind)) + _ = w.spinner.StopFail() - return fmt.Errorf(msg, w.kind) + return fmt.Errorf(msg, w.kind) + case context.Canceled: + _ = w.spinner.StopFail() + return nil + } } } } diff --git a/delete/delete.go b/delete/delete.go index 7d819f1..f397c1b 100644 --- a/delete/delete.go +++ b/delete/delete.go @@ -147,11 +147,17 @@ func (d *deleter) waitForDeletion(ctx context.Context, client *api.Client) error return fmt.Errorf("unable to get %s %q: %w", d.kind, d.mg.GetName(), err) } case <-ctx.Done(): - msg := "timeout waiting for %s" - spinner.StopFailMessage(format.ProgressMessagef("", msg, d.kind)) - _ = spinner.StopFail() + switch ctx.Err() { + case context.DeadlineExceeded: + msg := "timeout waiting for %s" + spinner.StopFailMessage(format.ProgressMessagef("", msg, d.kind)) + _ = spinner.StopFail() - return fmt.Errorf("timeout waiting for %s", d.kind) + return fmt.Errorf(msg, d.kind) + case context.Canceled: + _ = spinner.StopFail() + return nil + } } } }