error.go 9.8 KB

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