Error handling for GPG Subkeys
Problem to solve
When a GPG key has subkeys beneath it, any one of those subkeys can raise a validation error and cause the entire key to be unable to save. When this happens, no error message is displayed in the UI. We discovered this while testing #195666 (closed)
https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/gpg_key.rb#L122
def generate_subkeys gpg_subkeys = Gitlab::Gpg.subkeys_from_key(key) gpg_subkeys[primary_keyid]&.each do |subkey_data| subkeys.create!(keyid: subkey_data[:keyid], fingerprint: subkey_data[:fingerprint]) ## This may not save properly and will not return an error to be shown to the user end end
Proposal
In the case of #195666 (closed), the error was due to the last subkey: "Fingerprint has already been taken and Keyid has already been taken." This should be shown in the UI in the same way existing errors are shown: