Fix #5158

With this fix, I've been able to successfully complete a `Pkg.publish` call via an automatic pull request generation, but I'm not 100% sure that the error code checks.