error.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package db
  5. import (
  6. "fmt"
  7. )
  8. // ErrBlockedDomain is GIN specific code; required for signup domain blocking
  9. type ErrBlockedDomain struct {
  10. Email string
  11. }
  12. // IsErrBlockedDomain is GIN specific code
  13. func IsErrBlockedDomain(err error) bool {
  14. _, ok := err.(ErrBlockedDomain)
  15. return ok
  16. }
  17. // Error is GIN specific code
  18. func (err ErrBlockedDomain) Error() string {
  19. // don't inform the user of the blocked domain
  20. return fmt.Sprintf("user sign up failed")
  21. }
  22. // ____ ___
  23. // | | \______ ___________
  24. // | | / ___// __ \_ __ \
  25. // | | /\___ \\ ___/| | \/
  26. // |______//____ >\___ >__|
  27. // \/ \/
  28. type ErrUserOwnRepos struct {
  29. UID int64
  30. }
  31. func IsErrUserOwnRepos(err error) bool {
  32. _, ok := err.(ErrUserOwnRepos)
  33. return ok
  34. }
  35. func (err ErrUserOwnRepos) Error() string {
  36. return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
  37. }
  38. type ErrUserHasOrgs struct {
  39. UID int64
  40. }
  41. func IsErrUserHasOrgs(err error) bool {
  42. _, ok := err.(ErrUserHasOrgs)
  43. return ok
  44. }
  45. func (err ErrUserHasOrgs) Error() string {
  46. return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
  47. }
  48. // __ __.__ __ .__
  49. // / \ / \__| | _|__|
  50. // \ \/\/ / | |/ / |
  51. // \ /| | <| |
  52. // \__/\ / |__|__|_ \__|
  53. // \/ \/
  54. type ErrWikiAlreadyExist struct {
  55. Title string
  56. }
  57. func IsErrWikiAlreadyExist(err error) bool {
  58. _, ok := err.(ErrWikiAlreadyExist)
  59. return ok
  60. }
  61. func (err ErrWikiAlreadyExist) Error() string {
  62. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  63. }
  64. // __________ ___. .__ .__ ____ __.
  65. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  66. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  67. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  68. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  69. // \/ \/ \/ \/\/
  70. type ErrKeyUnableVerify struct {
  71. Result string
  72. }
  73. func IsErrKeyUnableVerify(err error) bool {
  74. _, ok := err.(ErrKeyUnableVerify)
  75. return ok
  76. }
  77. func (err ErrKeyUnableVerify) Error() string {
  78. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  79. }
  80. type ErrKeyNotExist struct {
  81. ID int64
  82. }
  83. func IsErrKeyNotExist(err error) bool {
  84. _, ok := err.(ErrKeyNotExist)
  85. return ok
  86. }
  87. func (err ErrKeyNotExist) Error() string {
  88. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  89. }
  90. type ErrKeyAlreadyExist struct {
  91. OwnerID int64
  92. Content string
  93. }
  94. func IsErrKeyAlreadyExist(err error) bool {
  95. _, ok := err.(ErrKeyAlreadyExist)
  96. return ok
  97. }
  98. func (err ErrKeyAlreadyExist) Error() string {
  99. return fmt.Sprintf("public key already exists [owner_id: %d, content: %s]", err.OwnerID, err.Content)
  100. }
  101. type ErrKeyNameAlreadyUsed struct {
  102. OwnerID int64
  103. Name string
  104. }
  105. func IsErrKeyNameAlreadyUsed(err error) bool {
  106. _, ok := err.(ErrKeyNameAlreadyUsed)
  107. return ok
  108. }
  109. func (err ErrKeyNameAlreadyUsed) Error() string {
  110. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  111. }
  112. type ErrKeyAccessDenied struct {
  113. UserID int64
  114. KeyID int64
  115. Note string
  116. }
  117. func IsErrKeyAccessDenied(err error) bool {
  118. _, ok := err.(ErrKeyAccessDenied)
  119. return ok
  120. }
  121. func (err ErrKeyAccessDenied) Error() string {
  122. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  123. err.UserID, err.KeyID, err.Note)
  124. }
  125. type ErrDeployKeyAlreadyExist struct {
  126. KeyID int64
  127. RepoID int64
  128. }
  129. func IsErrDeployKeyAlreadyExist(err error) bool {
  130. _, ok := err.(ErrDeployKeyAlreadyExist)
  131. return ok
  132. }
  133. func (err ErrDeployKeyAlreadyExist) Error() string {
  134. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  135. }
  136. type ErrDeployKeyNameAlreadyUsed struct {
  137. RepoID int64
  138. Name string
  139. }
  140. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  141. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  142. return ok
  143. }
  144. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  145. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  146. }
  147. // ________ .__ __ .__
  148. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  149. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  150. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  151. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  152. // \/ /_____/ \/ \/ \/ \/ \/
  153. type ErrLastOrgOwner struct {
  154. UID int64
  155. }
  156. func IsErrLastOrgOwner(err error) bool {
  157. _, ok := err.(ErrLastOrgOwner)
  158. return ok
  159. }
  160. func (err ErrLastOrgOwner) Error() string {
  161. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  162. }
  163. // __________ .__ __
  164. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  165. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  166. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  167. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  168. // \/ \/|__| \/ \/
  169. type ErrInvalidCloneAddr struct {
  170. IsURLError bool
  171. IsInvalidPath bool
  172. IsPermissionDenied bool
  173. }
  174. func IsErrInvalidCloneAddr(err error) bool {
  175. _, ok := err.(ErrInvalidCloneAddr)
  176. return ok
  177. }
  178. func (err ErrInvalidCloneAddr) Error() string {
  179. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  180. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  181. }
  182. type ErrUpdateTaskNotExist struct {
  183. UUID string
  184. }
  185. func IsErrUpdateTaskNotExist(err error) bool {
  186. _, ok := err.(ErrUpdateTaskNotExist)
  187. return ok
  188. }
  189. func (err ErrUpdateTaskNotExist) Error() string {
  190. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  191. }
  192. type ErrReleaseAlreadyExist struct {
  193. TagName string
  194. }
  195. func IsErrReleaseAlreadyExist(err error) bool {
  196. _, ok := err.(ErrReleaseAlreadyExist)
  197. return ok
  198. }
  199. func (err ErrReleaseAlreadyExist) Error() string {
  200. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  201. }
  202. type ErrInvalidTagName struct {
  203. TagName string
  204. }
  205. func IsErrInvalidTagName(err error) bool {
  206. _, ok := err.(ErrInvalidTagName)
  207. return ok
  208. }
  209. func (err ErrInvalidTagName) Error() string {
  210. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  211. }
  212. type ErrRepoFileAlreadyExist struct {
  213. FileName string
  214. }
  215. func IsErrRepoFileAlreadyExist(err error) bool {
  216. _, ok := err.(ErrRepoFileAlreadyExist)
  217. return ok
  218. }
  219. func (err ErrRepoFileAlreadyExist) Error() string {
  220. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  221. }
  222. // ___________
  223. // \__ ___/___ _____ _____
  224. // | |_/ __ \\__ \ / \
  225. // | |\ ___/ / __ \| Y Y \
  226. // |____| \___ >____ /__|_| /
  227. // \/ \/ \/
  228. type ErrTeamAlreadyExist struct {
  229. ID int64
  230. OrgID int64
  231. Name string
  232. }
  233. func IsErrTeamAlreadyExist(err error) bool {
  234. _, ok := err.(ErrTeamAlreadyExist)
  235. return ok
  236. }
  237. func (err ErrTeamAlreadyExist) Error() string {
  238. return fmt.Sprintf("team already exists [id: %d, org_id: %d, name: %s]", err.ID, err.OrgID, err.Name)
  239. }
  240. // ____ ___ .__ .___
  241. // | | \______ | | _________ __| _/
  242. // | | /\____ \| | / _ \__ \ / __ |
  243. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  244. // |______/ | __/|____/\____(____ /\____ |
  245. // |__| \/ \/
  246. //
  247. type ErrUploadNotExist struct {
  248. ID int64
  249. UUID string
  250. }
  251. func IsErrUploadNotExist(err error) bool {
  252. _, ok := err.(ErrAttachmentNotExist)
  253. return ok
  254. }
  255. func (err ErrUploadNotExist) Error() string {
  256. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  257. }