code.gitea.io/gitea@v1.21.7/models/user/error.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package user 5 6 import ( 7 "fmt" 8 9 "code.gitea.io/gitea/modules/util" 10 ) 11 12 // ErrUserAlreadyExist represents a "user already exists" error. 13 type ErrUserAlreadyExist struct { 14 Name string 15 } 16 17 // IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists. 18 func IsErrUserAlreadyExist(err error) bool { 19 _, ok := err.(ErrUserAlreadyExist) 20 return ok 21 } 22 23 func (err ErrUserAlreadyExist) Error() string { 24 return fmt.Sprintf("user already exists [name: %s]", err.Name) 25 } 26 27 // Unwrap unwraps this error as a ErrExist error 28 func (err ErrUserAlreadyExist) Unwrap() error { 29 return util.ErrAlreadyExist 30 } 31 32 // ErrUserNotExist represents a "UserNotExist" kind of error. 33 type ErrUserNotExist struct { 34 UID int64 35 Name string 36 KeyID int64 37 } 38 39 // IsErrUserNotExist checks if an error is a ErrUserNotExist. 40 func IsErrUserNotExist(err error) bool { 41 _, ok := err.(ErrUserNotExist) 42 return ok 43 } 44 45 func (err ErrUserNotExist) Error() string { 46 return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID) 47 } 48 49 // Unwrap unwraps this error as a ErrNotExist error 50 func (err ErrUserNotExist) Unwrap() error { 51 return util.ErrNotExist 52 } 53 54 // ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error. 55 type ErrUserProhibitLogin struct { 56 UID int64 57 Name string 58 } 59 60 // IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin 61 func IsErrUserProhibitLogin(err error) bool { 62 _, ok := err.(ErrUserProhibitLogin) 63 return ok 64 } 65 66 func (err ErrUserProhibitLogin) Error() string { 67 return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name) 68 } 69 70 // Unwrap unwraps this error as a ErrPermission error 71 func (err ErrUserProhibitLogin) Unwrap() error { 72 return util.ErrPermissionDenied 73 } 74 75 // ErrUserInactive represents a "ErrUserInactive" kind of error. 76 type ErrUserInactive struct { 77 UID int64 78 Name string 79 } 80 81 // IsErrUserInactive checks if an error is a ErrUserInactive 82 func IsErrUserInactive(err error) bool { 83 _, ok := err.(ErrUserInactive) 84 return ok 85 } 86 87 func (err ErrUserInactive) Error() string { 88 return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name) 89 } 90 91 // Unwrap unwraps this error as a ErrPermission error 92 func (err ErrUserInactive) Unwrap() error { 93 return util.ErrPermissionDenied 94 } 95 96 // ErrUserIsNotLocal represents a "ErrUserIsNotLocal" kind of error. 97 type ErrUserIsNotLocal struct { 98 UID int64 99 Name string 100 } 101 102 func (err ErrUserIsNotLocal) Error() string { 103 return fmt.Sprintf("user is not local type [uid: %d, name: %s]", err.UID, err.Name) 104 } 105 106 // IsErrUserIsNotLocal 107 func IsErrUserIsNotLocal(err error) bool { 108 _, ok := err.(ErrUserIsNotLocal) 109 return ok 110 } 111 112 type ErrUsernameNotChanged struct { 113 UID int64 114 Name string 115 } 116 117 func (err ErrUsernameNotChanged) Error() string { 118 return fmt.Sprintf("username hasn't been changed[uid: %d, name: %s]", err.UID, err.Name) 119 } 120 121 // IsErrUsernameNotChanged 122 func IsErrUsernameNotChanged(err error) bool { 123 _, ok := err.(ErrUsernameNotChanged) 124 return ok 125 }