Cannot remove identity directory

I’m trying to follow the steps to have an encrypted identity file on 0.10.0 and ran into the following error:

❯ dfx identity remove mainnet
Removing identity "mainnet".
Error: Cannot remove identity directory at '/Users/moritz/.config/dfx/identity/mainnet'.
Caused by:
  Directory not empty (os error 66)

The directory still contains a wallets.json (which is good because I would have no idea how to get the principal to the wallet) file and after the command the identity is not present when running dfx identity list.

When running the import command, the following error appears and the identity is not imported:

❯ dfx identity import mainnet ~/mainnet.pem
Please enter a passphrase for your identity: [hidden]
Encryption complete.
Error: Directory not empty (os error 66)

I was able to complete the process by moving wallet.json out of the mainnet folder and rerunning the import command. After completion I moved the wallet.json back into the mainnet folder.

@ericswanson @Severin

I see the problem in the code. If you remove wallets.json from the directory manually, it should work. Once you created an encrypted identity, you then have to either re-add the wallet for the identity or (not sure if this works) put the wallets.json back to where it was.

Edit: Ah, I see you already managed to do it. I’ll see if I can fix it in the code.

1 Like

Thanks for the quick response! A little bit OT but is there a way to “find” your wallet if you loose that wallet.json?

I don’t think there is generally. In some cases, you can still see the canister you created in some GUI, e.g. when creating it through the NNS. From there you may be able to recover the address.

I’m just thinking how it would be safest to update the remove command. I’ll probably end up listing the previously configured wallets when removing the file. If you have a better idea, let me know!

wdym by “listing”? in the terminal?

Something like this:

1 Like

Solution PR is here: fix: identities with configured wallets are not broken anymore and re… by sesi200 · Pull Request #2196 · dfinity/sdk · GitHub. If you have any strong opinions on the chosen approach, feel free to comment @cryptoschindler.

1 Like

I think this should work fine, but maybe add it to the release notes or docs? Sometimes people skip over console output.