Skip to content

Fix panic in api-key delete#3339

Open
Steven Gagniere (sgagniere) wants to merge 1 commit intomainfrom
apie-987
Open

Fix panic in api-key delete#3339
Steven Gagniere (sgagniere) wants to merge 1 commit intomainfrom
apie-987

Conversation

@sgagniere
Copy link
Copy Markdown
Member

Release Notes

Breaking Changes

  • PLACEHOLDER

New Features

  • PLACEHOLDER

Bug Fixes

  • Fix a bug causing confluent api-key delete to crash if it encounters an error saving while updating the config file

Checklist

  • I have successfully built and used a custom CLI binary, without linter issues from this PR.
  • I have clearly specified in the What section below whether this PR applies to Confluent Cloud, Confluent Platform, or both.
  • I have verified this PR in Confluent Cloud pre-prod or production environment, if applicable.
  • I have verified this PR in Confluent Platform on-premises environment, if applicable.
  • I have attached manual CLI verification results or screenshots in the Test & Review section below.
  • I have added appropriate CLI integration or unit tests for any new or updated commands and functionality.
  • I confirm that this PR introduces no breaking changes or backward compatibility issues.
  • I have indicated the potential customer impact if something goes wrong in the Blast Radius section below.
  • I have put checkmarks below confirming that the feature associated with this PR is enabled in:
    • Confluent Cloud prod
    • Confluent Cloud stag
    • Confluent Platform
    • Check this box if the feature is enabled for certain organizations only

What

The delete command displays a multierror. But there are multiple error variables, and the code was incorrectly calling the .Error() method on a nil error instead of the multierror, causing it to panic.

Blast Radius

Zero. The only change is in the output logic for an error.

References

Test & Review

https://docs.google.com/document/d/1RN9nCxfpDSCTSZILBIn4pDOUS-GyEJ1gjt5_waxi1Q4/edit?usp=sharing

Copilot AI review requested due to automatic review settings April 29, 2026 00:35
@sgagniere Steven Gagniere (sgagniere) requested a review from a team as a code owner April 29, 2026 00:35
@confluent-cla-assistant
Copy link
Copy Markdown

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

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 a panic in the confluent api-key delete command by ensuring the returned error message is derived from the aggregated multierror rather than a potentially-nil error value, particularly when local state (config/keystore) updates fail.

Changes:

  • Use errs.Error() (the aggregated multierror) instead of err.Error() when constructing the final user-facing error for api-key delete.

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

Comment on lines 48 to +50
errs := multierror.Append(err, c.deleteKeysFromKeyStore(deletedIds))
if errs.ErrorOrNil() != nil {
return errors.NewErrorWithSuggestions(err.Error(), errors.ApiKeyNotFoundSuggestions)
return errors.NewErrorWithSuggestions(errs.Error(), errors.ApiKeyNotFoundSuggestions)
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

errs can include failures from deleteKeysFromKeyStore (which ultimately calls Config.Save()), not just API-key-not-found/forbidden errors. Wrapping all aggregated errors with errors.ApiKeyNotFoundSuggestions will produce misleading guidance when the underlying failure is a local config/keystore write error. Consider branching on the error source (e.g., only attach ApiKeyNotFoundSuggestions when the delete API call failed; otherwise return/wrap the config-save error with a more relevant message/suggestions).

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

Choose a reason for hiding this comment

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

This is a valid point, but the purpose of the PR is just to triage the panic.

Comment on lines 48 to +50
errs := multierror.Append(err, c.deleteKeysFromKeyStore(deletedIds))
if errs.ErrorOrNil() != nil {
return errors.NewErrorWithSuggestions(err.Error(), errors.ApiKeyNotFoundSuggestions)
return errors.NewErrorWithSuggestions(errs.Error(), errors.ApiKeyNotFoundSuggestions)
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

There’s no automated regression test covering the scenario described in the PR (API delete succeeds but updating the local config/keystore fails), which previously caused a panic. Please add a unit/integration test that forces Config.Save()/keystore.DeleteAPIKey to error and asserts api-key delete returns a non-nil error (and does not crash).

Copilot uses AI. Check for mistakes.
@sonarqube-confluent
Copy link
Copy Markdown

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.

3 participants