error.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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 ErrUserAlreadyExist struct {
  29. Name string
  30. }
  31. func IsErrUserAlreadyExist(err error) bool {
  32. _, ok := err.(ErrUserAlreadyExist)
  33. return ok
  34. }
  35. func (err ErrUserAlreadyExist) Error() string {
  36. return fmt.Sprintf("user already exists [name: %s]", err.Name)
  37. }
  38. type ErrEmailAlreadyUsed struct {
  39. Email string
  40. }
  41. func IsErrEmailAlreadyUsed(err error) bool {
  42. _, ok := err.(ErrEmailAlreadyUsed)
  43. return ok
  44. }
  45. func (err ErrEmailAlreadyUsed) Error() string {
  46. return fmt.Sprintf("e-mail has been used [email: %s]", err.Email)
  47. }
  48. type ErrUserOwnRepos struct {
  49. UID int64
  50. }
  51. func IsErrUserOwnRepos(err error) bool {
  52. _, ok := err.(ErrUserOwnRepos)
  53. return ok
  54. }
  55. func (err ErrUserOwnRepos) Error() string {
  56. return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
  57. }
  58. type ErrUserHasOrgs struct {
  59. UID int64
  60. }
  61. func IsErrUserHasOrgs(err error) bool {
  62. _, ok := err.(ErrUserHasOrgs)
  63. return ok
  64. }
  65. func (err ErrUserHasOrgs) Error() string {
  66. return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
  67. }
  68. // __ __.__ __ .__
  69. // / \ / \__| | _|__|
  70. // \ \/\/ / | |/ / |
  71. // \ /| | <| |
  72. // \__/\ / |__|__|_ \__|
  73. // \/ \/
  74. type ErrWikiAlreadyExist struct {
  75. Title string
  76. }
  77. func IsErrWikiAlreadyExist(err error) bool {
  78. _, ok := err.(ErrWikiAlreadyExist)
  79. return ok
  80. }
  81. func (err ErrWikiAlreadyExist) Error() string {
  82. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  83. }
  84. // __________ ___. .__ .__ ____ __.
  85. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  86. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  87. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  88. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  89. // \/ \/ \/ \/\/
  90. type ErrKeyUnableVerify struct {
  91. Result string
  92. }
  93. func IsErrKeyUnableVerify(err error) bool {
  94. _, ok := err.(ErrKeyUnableVerify)
  95. return ok
  96. }
  97. func (err ErrKeyUnableVerify) Error() string {
  98. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  99. }
  100. type ErrKeyNotExist struct {
  101. ID int64
  102. }
  103. func IsErrKeyNotExist(err error) bool {
  104. _, ok := err.(ErrKeyNotExist)
  105. return ok
  106. }
  107. func (err ErrKeyNotExist) Error() string {
  108. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  109. }
  110. type ErrKeyAlreadyExist struct {
  111. OwnerID int64
  112. Content string
  113. }
  114. func IsErrKeyAlreadyExist(err error) bool {
  115. _, ok := err.(ErrKeyAlreadyExist)
  116. return ok
  117. }
  118. func (err ErrKeyAlreadyExist) Error() string {
  119. return fmt.Sprintf("public key already exists [owner_id: %d, content: %s]", err.OwnerID, err.Content)
  120. }
  121. type ErrKeyNameAlreadyUsed struct {
  122. OwnerID int64
  123. Name string
  124. }
  125. func IsErrKeyNameAlreadyUsed(err error) bool {
  126. _, ok := err.(ErrKeyNameAlreadyUsed)
  127. return ok
  128. }
  129. func (err ErrKeyNameAlreadyUsed) Error() string {
  130. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  131. }
  132. type ErrKeyAccessDenied struct {
  133. UserID int64
  134. KeyID int64
  135. Note string
  136. }
  137. func IsErrKeyAccessDenied(err error) bool {
  138. _, ok := err.(ErrKeyAccessDenied)
  139. return ok
  140. }
  141. func (err ErrKeyAccessDenied) Error() string {
  142. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  143. err.UserID, err.KeyID, err.Note)
  144. }
  145. type ErrDeployKeyAlreadyExist struct {
  146. KeyID int64
  147. RepoID int64
  148. }
  149. func IsErrDeployKeyAlreadyExist(err error) bool {
  150. _, ok := err.(ErrDeployKeyAlreadyExist)
  151. return ok
  152. }
  153. func (err ErrDeployKeyAlreadyExist) Error() string {
  154. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  155. }
  156. type ErrDeployKeyNameAlreadyUsed struct {
  157. RepoID int64
  158. Name string
  159. }
  160. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  161. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  162. return ok
  163. }
  164. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  165. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  166. }
  167. // ________ .__ __ .__
  168. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  169. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  170. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  171. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  172. // \/ /_____/ \/ \/ \/ \/ \/
  173. type ErrLastOrgOwner struct {
  174. UID int64
  175. }
  176. func IsErrLastOrgOwner(err error) bool {
  177. _, ok := err.(ErrLastOrgOwner)
  178. return ok
  179. }
  180. func (err ErrLastOrgOwner) Error() string {
  181. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  182. }
  183. // __________ .__ __
  184. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  185. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  186. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  187. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  188. // \/ \/|__| \/ \/
  189. type ErrInvalidCloneAddr struct {
  190. IsURLError bool
  191. IsInvalidPath bool
  192. IsPermissionDenied bool
  193. }
  194. func IsErrInvalidCloneAddr(err error) bool {
  195. _, ok := err.(ErrInvalidCloneAddr)
  196. return ok
  197. }
  198. func (err ErrInvalidCloneAddr) Error() string {
  199. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  200. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  201. }
  202. type ErrUpdateTaskNotExist struct {
  203. UUID string
  204. }
  205. func IsErrUpdateTaskNotExist(err error) bool {
  206. _, ok := err.(ErrUpdateTaskNotExist)
  207. return ok
  208. }
  209. func (err ErrUpdateTaskNotExist) Error() string {
  210. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  211. }
  212. type ErrReleaseAlreadyExist struct {
  213. TagName string
  214. }
  215. func IsErrReleaseAlreadyExist(err error) bool {
  216. _, ok := err.(ErrReleaseAlreadyExist)
  217. return ok
  218. }
  219. func (err ErrReleaseAlreadyExist) Error() string {
  220. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  221. }
  222. type ErrInvalidTagName struct {
  223. TagName string
  224. }
  225. func IsErrInvalidTagName(err error) bool {
  226. _, ok := err.(ErrInvalidTagName)
  227. return ok
  228. }
  229. func (err ErrInvalidTagName) Error() string {
  230. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  231. }
  232. type ErrRepoFileAlreadyExist struct {
  233. FileName string
  234. }
  235. func IsErrRepoFileAlreadyExist(err error) bool {
  236. _, ok := err.(ErrRepoFileAlreadyExist)
  237. return ok
  238. }
  239. func (err ErrRepoFileAlreadyExist) Error() string {
  240. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  241. }
  242. // ___________
  243. // \__ ___/___ _____ _____
  244. // | |_/ __ \\__ \ / \
  245. // | |\ ___/ / __ \| Y Y \
  246. // |____| \___ >____ /__|_| /
  247. // \/ \/ \/
  248. type ErrTeamAlreadyExist struct {
  249. ID int64
  250. OrgID int64
  251. Name string
  252. }
  253. func IsErrTeamAlreadyExist(err error) bool {
  254. _, ok := err.(ErrTeamAlreadyExist)
  255. return ok
  256. }
  257. func (err ErrTeamAlreadyExist) Error() string {
  258. return fmt.Sprintf("team already exists [id: %d, org_id: %d, name: %s]", err.ID, err.OrgID, err.Name)
  259. }
  260. // ____ ___ .__ .___
  261. // | | \______ | | _________ __| _/
  262. // | | /\____ \| | / _ \__ \ / __ |
  263. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  264. // |______/ | __/|____/\____(____ /\____ |
  265. // |__| \/ \/
  266. //
  267. type ErrUploadNotExist struct {
  268. ID int64
  269. UUID string
  270. }
  271. func IsErrUploadNotExist(err error) bool {
  272. _, ok := err.(ErrAttachmentNotExist)
  273. return ok
  274. }
  275. func (err ErrUploadNotExist) Error() string {
  276. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  277. }