Skip to content

[cli] Fix rotate-key profile saving without an existing config#20184

Open
plutohan wants to merge 1 commit into
aptos-labs:mainfrom
plutohan:plutohan/issue-9547-rotate-key-no-default-profile
Open

[cli] Fix rotate-key profile saving without an existing config#20184
plutohan wants to merge 1 commit into
aptos-labs:mainfrom
plutohan:plutohan/issue-9547-rotate-key-no-default-profile

Conversation

@plutohan

@plutohan plutohan commented Jul 3, 2026

Copy link
Copy Markdown

Description

Fixes #9547. aptos key rotate-key --save-to-profile <name> failed with a config error when no config file (or default profile) existed, following the solution sketched in the issue:

  1. The profile-name verification now only loads the config when one exists.
  2. Saving starts from a fresh CliConfig when none exists; save() already creates the .aptos folder and config file.
  3. The new profile no longer requires the current (default) profile; it falls back to an empty base profile when there is none, while still surfacing real config errors.

How Has This Been Tested?

cargo check -p aptos passes. Manually traced all three failure paths against CliConfig/ProfileOptions in aptos-cli-common.

Key Areas to Review

The ConfigNotFoundError match when building the new profile: other errors still propagate, only the missing-profile case falls back to defaults.

Type of Change

  • Bug fix

Which Components or Systems Does This Change Impact?

  • Aptos CLI/SDK

Checklist

  • I have read and followed the CONTRIBUTING doc
  • I have performed a self-review of my own code

Note

Low Risk
Localized CLI post-rotation config path; no on-chain or auth logic changes, with explicit propagation of non-missing-config errors.

Overview
Fixes aptos key rotate-key --save-to-profile when there is no .aptos config or default profile yet.

Pre-rotation checks only load config to reject duplicate profile names when a config file already exists; missing config is allowed.

After a successful rotation, saving uses an existing config or CliConfig::default(), then config.save() creates the file. The new profile copies settings from the current profile when profile() succeeds, and uses ProfileConfig::default() only when the error is ConfigNotFoundError; other config errors still fail.

Reviewed by Cursor Bugbot for commit efd904f. Bugbot is set up for automated code reviews on this repo. Configure here.

@plutohan plutohan requested a review from a team as a code owner July 3, 2026 08:50
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.

[CLI] rotate-key can't save new profile if no default profile

1 participant