Skip to content

fix: return error and stop spinner on domain delete failure#211

Open
eliajhmauve wants to merge 1 commit intozeabur:mainfrom
eliajhmauve:fix/domain-delete-error-handling
Open

fix: return error and stop spinner on domain delete failure#211
eliajhmauve wants to merge 1 commit intozeabur:mainfrom
eliajhmauve:fix/domain-delete-error-handling

Conversation

@eliajhmauve
Copy link
Copy Markdown
Contributor

Problem

domain delete has two related issues in runDeleteDomainNonInteractive:

1. Spinner not stopped on API error

Both ListDomains and RemoveDomain call return err before s.Stop(), leaving the spinner running after an error. This corrupts terminal output — the spinner animation continues rendering on top of the error message.

2. Deletion failure returns nil (exit code 0)

When RemoveDomain returns false (the API-level "failed" signal), the code logs a warning and returns nil:

if !deleteResult {
    f.Log.Warnf("Delete domain %s failed", opts.domainName)
    return nil  // exit code 0
}

Callers (scripts, CI/CD pipelines) have no way to detect that the deletion did not actually succeed.

Fix

  • Call s.Stop() before each return err in the error paths
  • Replace f.Log.Warnf(...); return nil with return fmt.Errorf(...) so failures propagate correctly

Files changed

  • internal/cmd/domain/delete/delete.go — 3-line change

Two issues in domain/delete:

1. When RemoveDomain returns false (API-level failure), the code logged
   a warning and returned nil (exit code 0), making it impossible for
   callers to detect the failure.

2. Both ListDomains and RemoveDomain error paths returned early without
   calling s.Stop(), leaving the spinner running and corrupting terminal
   output.

Fix: call s.Stop() before returning errors, and return fmt.Errorf
instead of nil when deleteResult is false.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

Warning

Rate limit exceeded

@eliajhmauve has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 34 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 28 minutes and 34 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00e17069-f37a-41a6-881e-6429321d69cd

📥 Commits

Reviewing files that changed from the base of the PR and between 76b8768 and 94d9533.

📒 Files selected for processing (1)
  • internal/cmd/domain/delete/delete.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes domain delete CLI behavior so terminal output isn’t corrupted by a lingering spinner on API errors, and so domain deletion failures correctly propagate as errors (non-zero exit).

Changes:

  • Stop the spinner before returning on ListDomains/RemoveDomain error paths.
  • Return an error (instead of nil) when the API reports deletion failed (deleteResult == false).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 126 to 133
s := spinner.New(cmdutil.SpinnerCharSet, cmdutil.SpinnerInterval,
spinner.WithColor(cmdutil.SpinnerColor),
spinner.WithSuffix(fmt.Sprintf(" Deleting selected domain: %s ...", opts.domainName)))
s.Start()
deleteResult, err := f.ApiClient.RemoveDomain(context.Background(), opts.domainName)
if err != nil {
s.Stop()
return err
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runDeleteDomainNonInteractive can call RemoveDomain with an empty opts.domainName when the command is run non-interactively without --domain, leading to a potentially confusing API error (or unintended server behavior). Add an explicit check (e.g., return a --domain is required error) before starting the spinner / calling the API.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@pan93412 pan93412 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to resolve Copilot's suggestion (or explain why their suggestion is invalid)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants