error.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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 ErrAccessTokenNotExist struct {
  180. SHA string
  181. }
  182. func IsErrAccessTokenNotExist(err error) bool {
  183. _, ok := err.(ErrAccessTokenNotExist)
  184. return ok
  185. }
  186. func (err ErrAccessTokenNotExist) Error() string {
  187. return fmt.Sprintf("access token does not exist [sha: %s]", err.SHA)
  188. }
  189. type ErrAccessTokenEmpty struct {
  190. }
  191. func IsErrAccessTokenEmpty(err error) bool {
  192. _, ok := err.(ErrAccessTokenEmpty)
  193. return ok
  194. }
  195. func (err ErrAccessTokenEmpty) Error() string {
  196. return fmt.Sprintf("access token is empty")
  197. }
  198. // ________ .__ __ .__
  199. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  200. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  201. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  202. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  203. // \/ /_____/ \/ \/ \/ \/ \/
  204. type ErrLastOrgOwner struct {
  205. UID int64
  206. }
  207. func IsErrLastOrgOwner(err error) bool {
  208. _, ok := err.(ErrLastOrgOwner)
  209. return ok
  210. }
  211. func (err ErrLastOrgOwner) Error() string {
  212. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  213. }
  214. // __________ .__ __
  215. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  216. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  217. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  218. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  219. // \/ \/|__| \/ \/
  220. type ErrRepoAlreadyExist struct {
  221. Uname string
  222. Name string
  223. }
  224. func IsErrRepoAlreadyExist(err error) bool {
  225. _, ok := err.(ErrRepoAlreadyExist)
  226. return ok
  227. }
  228. func (err ErrRepoAlreadyExist) Error() string {
  229. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  230. }
  231. type ErrInvalidCloneAddr struct {
  232. IsURLError bool
  233. IsInvalidPath bool
  234. IsPermissionDenied bool
  235. }
  236. func IsErrInvalidCloneAddr(err error) bool {
  237. _, ok := err.(ErrInvalidCloneAddr)
  238. return ok
  239. }
  240. func (err ErrInvalidCloneAddr) Error() string {
  241. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  242. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  243. }
  244. type ErrUpdateTaskNotExist struct {
  245. UUID string
  246. }
  247. func IsErrUpdateTaskNotExist(err error) bool {
  248. _, ok := err.(ErrUpdateTaskNotExist)
  249. return ok
  250. }
  251. func (err ErrUpdateTaskNotExist) Error() string {
  252. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  253. }
  254. type ErrReleaseAlreadyExist struct {
  255. TagName string
  256. }
  257. func IsErrReleaseAlreadyExist(err error) bool {
  258. _, ok := err.(ErrReleaseAlreadyExist)
  259. return ok
  260. }
  261. func (err ErrReleaseAlreadyExist) Error() string {
  262. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  263. }
  264. type ErrInvalidTagName struct {
  265. TagName string
  266. }
  267. func IsErrInvalidTagName(err error) bool {
  268. _, ok := err.(ErrInvalidTagName)
  269. return ok
  270. }
  271. func (err ErrInvalidTagName) Error() string {
  272. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  273. }
  274. type ErrRepoFileAlreadyExist struct {
  275. FileName string
  276. }
  277. func IsErrRepoFileAlreadyExist(err error) bool {
  278. _, ok := err.(ErrRepoFileAlreadyExist)
  279. return ok
  280. }
  281. func (err ErrRepoFileAlreadyExist) Error() string {
  282. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  283. }
  284. // .____ .__ _________
  285. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  286. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  287. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  288. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  289. // \/ /_____/ \/ \/ \/ \/
  290. type ErrLoginSourceAlreadyExist struct {
  291. Name string
  292. }
  293. func IsErrLoginSourceAlreadyExist(err error) bool {
  294. _, ok := err.(ErrLoginSourceAlreadyExist)
  295. return ok
  296. }
  297. func (err ErrLoginSourceAlreadyExist) Error() string {
  298. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  299. }
  300. type ErrLoginSourceInUse struct {
  301. ID int64
  302. }
  303. func IsErrLoginSourceInUse(err error) bool {
  304. _, ok := err.(ErrLoginSourceInUse)
  305. return ok
  306. }
  307. func (err ErrLoginSourceInUse) Error() string {
  308. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  309. }
  310. // ___________
  311. // \__ ___/___ _____ _____
  312. // | |_/ __ \\__ \ / \
  313. // | |\ ___/ / __ \| Y Y \
  314. // |____| \___ >____ /__|_| /
  315. // \/ \/ \/
  316. type ErrTeamAlreadyExist struct {
  317. OrgID int64
  318. Name string
  319. }
  320. func IsErrTeamAlreadyExist(err error) bool {
  321. _, ok := err.(ErrTeamAlreadyExist)
  322. return ok
  323. }
  324. func (err ErrTeamAlreadyExist) Error() string {
  325. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  326. }
  327. // ____ ___ .__ .___
  328. // | | \______ | | _________ __| _/
  329. // | | /\____ \| | / _ \__ \ / __ |
  330. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  331. // |______/ | __/|____/\____(____ /\____ |
  332. // |__| \/ \/
  333. //
  334. type ErrUploadNotExist struct {
  335. ID int64
  336. UUID string
  337. }
  338. func IsErrUploadNotExist(err error) bool {
  339. _, ok := err.(ErrAttachmentNotExist)
  340. return ok
  341. }
  342. func (err ErrUploadNotExist) Error() string {
  343. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  344. }