Skip to content

Commit 8b63db4

Browse files
committed
Catch not found/verified email error
1 parent 47eb429 commit 8b63db4

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

models/error.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ func (err ErrKeyNameAlreadyUsed) Error() string {
260260
return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
261261
}
262262

263+
// ErrGPGEmailNotFound represents a "ErrGPGEmailNotFound" kind of error.
264+
type ErrGPGEmailNotFound struct {
265+
Email string
266+
}
267+
268+
// IsErrGPGEmailNotFound checks if an error is a ErrGPGEmailNotFound.
269+
func IsErrGPGEmailNotFound(err error) bool {
270+
_, ok := err.(ErrGPGEmailNotFound)
271+
return ok
272+
}
273+
274+
func (err ErrGPGEmailNotFound) Error() string {
275+
return fmt.Sprintf("failed to found email or is not confirmed : %s", err.Email)
276+
}
277+
263278
// ErrGPGKeyParsing represents a "ErrGPGKeyParsing" kind of error.
264279
type ErrGPGKeyParsing struct {
265280
ParseError error

models/gpg_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func parseGPGKey(ownerID int64, e *openpgp.Entity) (*GPGKey, error) {
219219
}
220220
}
221221
if emails[n] == nil {
222-
return nil, fmt.Errorf("Failed to found email or is not confirmed : %s", ident.UserId.Email)
222+
return nil, ErrGPGEmailNotFound{ident.UserId.Email}
223223
}
224224
n++
225225
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ add_new_gpg_key = Add GPG Key
361361
ssh_key_been_used = Public key content has already been used.
362362
ssh_key_name_used = Public key with same name already exists.
363363
gpg_key_id_used = Public GPG key with same id already exists.
364+
gpg_key_email_not_found = The email attached to the GPG key couldn't be found or is not yet confirmed: %s
364365
subkeys = Subkeys
365366
key_id = Key ID
366367
key_name = Key Name

routers/user/setting.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ func SettingsKeysPost(ctx *context.Context, form auth.AddKeyForm) {
377377
case models.IsErrGPGKeyIDAlreadyUsed(err):
378378
ctx.Data["Err_Content"] = true
379379
ctx.RenderWithErr(ctx.Tr("settings.gpg_key_id_used"), tplSettingsKeys, &form)
380+
case models.IsErrGPGEmailNotFound(err):
381+
ctx.Data["Err_Content"] = true
382+
ctx.RenderWithErr(ctx.Tr("settings.gpg_key_email_not_found", err.(models.ErrGPGEmailNotFound).Email), tplSettingsKeys, &form)
380383
default:
381384
ctx.Handle(500, "AddPublicKey", err)
382385
}

0 commit comments

Comments
 (0)