Skip to content

Commit

Permalink
fix: do not indicate timeout when context is canceled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ctrox committed Jul 24, 2024
1 parent 6a76b1e commit cc911b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}

0 comments on commit cc911b4

Please sign in to comment.