Gpg 2.2.12 Has Different Exit Code on Failure to Import Key Than 2.2.4

I am trying to connect a bunch of gpg --keyserver attempts with or in order to try several servers, but this is being foiled by the fact that gpg v2.2.12 seems to erroneously return exit code 0 (success) when it fails to import a key:

$ gpg --version
gpg (GnuPG) 2.2.12
...
$ gpg --keyserver hkps://keys.openpgp.org --recv-keys "SOME_KEY"
gpg: key SOME_KEY: new key but contains no user ID - skipped
gpg: Total number processed: 1
gpg:           w/o user IDs: 1 
$ echo $?
0

It seems incorrect that this would have an exit code of 0, and gpg v2.2.4 seems to agree with me:

$ gpg --version
gpg (GnuPG) 2.2.4
...
$ gpg --keyserver hkps://keys.openpgp.org --recv-keys "SOME_KEY"
gpg: key SOME_KEY: no user ID
gpg: Total number processed: 1
$ echo $?
2

If you're curious why I am referring to 2 gpg's, one is on my main system (Ubuntu), the other is what happens in the container I am using (debian, from the base image of buildpack-deps:buster). Both systems believe these respective versions to be the latest. I would prefer the latter behavior to the former, is there any way to have gpg 2.2.12 behave that way?

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article