You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error.go 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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 models
  5. import (
  6. "fmt"
  7. )
  8. // ErrNameReserved represents a "reserved name" error.
  9. type ErrNameReserved struct {
  10. Name string
  11. }
  12. // IsErrNameReserved checks if an error is a ErrNameReserved.
  13. func IsErrNameReserved(err error) bool {
  14. _, ok := err.(ErrNameReserved)
  15. return ok
  16. }
  17. func (err ErrNameReserved) Error() string {
  18. return fmt.Sprintf("name is reserved [name: %s]", err.Name)
  19. }
  20. // ErrNamePatternNotAllowed represents a "pattern not allowed" error.
  21. type ErrNamePatternNotAllowed struct {
  22. Pattern string
  23. }
  24. // IsErrNamePatternNotAllowed checks if an error is an
  25. // ErrNamePatternNotAllowed.
  26. func IsErrNamePatternNotAllowed(err error) bool {
  27. _, ok := err.(ErrNamePatternNotAllowed)
  28. return ok
  29. }
  30. func (err ErrNamePatternNotAllowed) Error() string {
  31. return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
  32. }
  33. // ____ ___
  34. // | | \______ ___________
  35. // | | / ___// __ \_ __ \
  36. // | | /\___ \\ ___/| | \/
  37. // |______//____ >\___ >__|
  38. // \/ \/
  39. // ErrUserAlreadyExist represents a "user already exists" error.
  40. type ErrUserAlreadyExist struct {
  41. Name string
  42. }
  43. // IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.
  44. func IsErrUserAlreadyExist(err error) bool {
  45. _, ok := err.(ErrUserAlreadyExist)
  46. return ok
  47. }
  48. func (err ErrUserAlreadyExist) Error() string {
  49. return fmt.Sprintf("user already exists [name: %s]", err.Name)
  50. }
  51. // ErrUserNotExist represents a "UserNotExist" kind of error.
  52. type ErrUserNotExist struct {
  53. UID int64
  54. Name string
  55. KeyID int64
  56. }
  57. // IsErrUserNotExist checks if an error is a ErrUserNotExist.
  58. func IsErrUserNotExist(err error) bool {
  59. _, ok := err.(ErrUserNotExist)
  60. return ok
  61. }
  62. func (err ErrUserNotExist) Error() string {
  63. return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID)
  64. }
  65. // ErrEmailAlreadyUsed represents a "EmailAlreadyUsed" kind of error.
  66. type ErrEmailAlreadyUsed struct {
  67. Email string
  68. }
  69. // IsErrEmailAlreadyUsed checks if an error is a ErrEmailAlreadyUsed.
  70. func IsErrEmailAlreadyUsed(err error) bool {
  71. _, ok := err.(ErrEmailAlreadyUsed)
  72. return ok
  73. }
  74. func (err ErrEmailAlreadyUsed) Error() string {
  75. return fmt.Sprintf("e-mail has been used [email: %s]", err.Email)
  76. }
  77. // ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
  78. type ErrUserOwnRepos struct {
  79. UID int64
  80. }
  81. // IsErrUserOwnRepos checks if an error is a ErrUserOwnRepos.
  82. func IsErrUserOwnRepos(err error) bool {
  83. _, ok := err.(ErrUserOwnRepos)
  84. return ok
  85. }
  86. func (err ErrUserOwnRepos) Error() string {
  87. return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
  88. }
  89. // ErrUserHasOrgs represents a "UserHasOrgs" kind of error.
  90. type ErrUserHasOrgs struct {
  91. UID int64
  92. }
  93. // IsErrUserHasOrgs checks if an error is a ErrUserHasOrgs.
  94. func IsErrUserHasOrgs(err error) bool {
  95. _, ok := err.(ErrUserHasOrgs)
  96. return ok
  97. }
  98. func (err ErrUserHasOrgs) Error() string {
  99. return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
  100. }
  101. // ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error.
  102. type ErrUserNotAllowedCreateOrg struct {
  103. }
  104. // IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg.
  105. func IsErrUserNotAllowedCreateOrg(err error) bool {
  106. _, ok := err.(ErrUserNotAllowedCreateOrg)
  107. return ok
  108. }
  109. func (err ErrUserNotAllowedCreateOrg) Error() string {
  110. return fmt.Sprintf("user is not allowed to create organizations")
  111. }
  112. // ErrReachLimitOfRepo represents a "ReachLimitOfRepo" kind of error.
  113. type ErrReachLimitOfRepo struct {
  114. Limit int
  115. }
  116. // IsErrReachLimitOfRepo checks if an error is a ErrReachLimitOfRepo.
  117. func IsErrReachLimitOfRepo(err error) bool {
  118. _, ok := err.(ErrReachLimitOfRepo)
  119. return ok
  120. }
  121. func (err ErrReachLimitOfRepo) Error() string {
  122. return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
  123. }
  124. // __ __.__ __ .__
  125. // / \ / \__| | _|__|
  126. // \ \/\/ / | |/ / |
  127. // \ /| | <| |
  128. // \__/\ / |__|__|_ \__|
  129. // \/ \/
  130. // ErrWikiAlreadyExist represents a "WikiAlreadyExist" kind of error.
  131. type ErrWikiAlreadyExist struct {
  132. Title string
  133. }
  134. // IsErrWikiAlreadyExist checks if an error is a ErrWikiAlreadyExist.
  135. func IsErrWikiAlreadyExist(err error) bool {
  136. _, ok := err.(ErrWikiAlreadyExist)
  137. return ok
  138. }
  139. func (err ErrWikiAlreadyExist) Error() string {
  140. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  141. }
  142. // __________ ___. .__ .__ ____ __.
  143. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  144. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  145. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  146. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  147. // \/ \/ \/ \/\/
  148. // ErrKeyUnableVerify represents a "KeyUnableVerify" kind of error.
  149. type ErrKeyUnableVerify struct {
  150. Result string
  151. }
  152. // IsErrKeyUnableVerify checks if an error is a ErrKeyUnableVerify.
  153. func IsErrKeyUnableVerify(err error) bool {
  154. _, ok := err.(ErrKeyUnableVerify)
  155. return ok
  156. }
  157. func (err ErrKeyUnableVerify) Error() string {
  158. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  159. }
  160. // ErrKeyNotExist represents a "KeyNotExist" kind of error.
  161. type ErrKeyNotExist struct {
  162. ID int64
  163. }
  164. // IsErrKeyNotExist checks if an error is a ErrKeyNotExist.
  165. func IsErrKeyNotExist(err error) bool {
  166. _, ok := err.(ErrKeyNotExist)
  167. return ok
  168. }
  169. func (err ErrKeyNotExist) Error() string {
  170. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  171. }
  172. // ErrKeyAlreadyExist represents a "KeyAlreadyExist" kind of error.
  173. type ErrKeyAlreadyExist struct {
  174. OwnerID int64
  175. Content string
  176. }
  177. // IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.
  178. func IsErrKeyAlreadyExist(err error) bool {
  179. _, ok := err.(ErrKeyAlreadyExist)
  180. return ok
  181. }
  182. func (err ErrKeyAlreadyExist) Error() string {
  183. return fmt.Sprintf("public key already exists [owner_id: %d, content: %s]", err.OwnerID, err.Content)
  184. }
  185. // ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
  186. type ErrKeyNameAlreadyUsed struct {
  187. OwnerID int64
  188. Name string
  189. }
  190. // IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  191. func IsErrKeyNameAlreadyUsed(err error) bool {
  192. _, ok := err.(ErrKeyNameAlreadyUsed)
  193. return ok
  194. }
  195. func (err ErrKeyNameAlreadyUsed) Error() string {
  196. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  197. }
  198. // ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
  199. type ErrKeyAccessDenied struct {
  200. UserID int64
  201. KeyID int64
  202. Note string
  203. }
  204. // IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.
  205. func IsErrKeyAccessDenied(err error) bool {
  206. _, ok := err.(ErrKeyAccessDenied)
  207. return ok
  208. }
  209. func (err ErrKeyAccessDenied) Error() string {
  210. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  211. err.UserID, err.KeyID, err.Note)
  212. }
  213. // ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
  214. type ErrDeployKeyNotExist struct {
  215. ID int64
  216. KeyID int64
  217. RepoID int64
  218. }
  219. // IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.
  220. func IsErrDeployKeyNotExist(err error) bool {
  221. _, ok := err.(ErrDeployKeyNotExist)
  222. return ok
  223. }
  224. func (err ErrDeployKeyNotExist) Error() string {
  225. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  226. }
  227. // ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
  228. type ErrDeployKeyAlreadyExist struct {
  229. KeyID int64
  230. RepoID int64
  231. }
  232. // IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.
  233. func IsErrDeployKeyAlreadyExist(err error) bool {
  234. _, ok := err.(ErrDeployKeyAlreadyExist)
  235. return ok
  236. }
  237. func (err ErrDeployKeyAlreadyExist) Error() string {
  238. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  239. }
  240. // ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
  241. type ErrDeployKeyNameAlreadyUsed struct {
  242. RepoID int64
  243. Name string
  244. }
  245. // IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.
  246. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  247. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  248. return ok
  249. }
  250. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  251. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  252. }
  253. // _____ ___________ __
  254. // / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____
  255. // / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \
  256. // / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \
  257. // \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| /
  258. // \/ \/ \/ \/ \/ \/ \/ \/ \/
  259. // ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.
  260. type ErrAccessTokenNotExist struct {
  261. SHA string
  262. }
  263. // IsErrAccessTokenNotExist checks if an error is a ErrAccessTokenNotExist.
  264. func IsErrAccessTokenNotExist(err error) bool {
  265. _, ok := err.(ErrAccessTokenNotExist)
  266. return ok
  267. }
  268. func (err ErrAccessTokenNotExist) Error() string {
  269. return fmt.Sprintf("access token does not exist [sha: %s]", err.SHA)
  270. }
  271. // ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
  272. type ErrAccessTokenEmpty struct {
  273. }
  274. // IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
  275. func IsErrAccessTokenEmpty(err error) bool {
  276. _, ok := err.(ErrAccessTokenEmpty)
  277. return ok
  278. }
  279. func (err ErrAccessTokenEmpty) Error() string {
  280. return fmt.Sprintf("access token is empty")
  281. }
  282. // ________ .__ __ .__
  283. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  284. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  285. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  286. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  287. // \/ /_____/ \/ \/ \/ \/ \/
  288. // ErrLastOrgOwner represents a "LastOrgOwner" kind of error.
  289. type ErrLastOrgOwner struct {
  290. UID int64
  291. }
  292. // IsErrLastOrgOwner checks if an error is a ErrLastOrgOwner.
  293. func IsErrLastOrgOwner(err error) bool {
  294. _, ok := err.(ErrLastOrgOwner)
  295. return ok
  296. }
  297. func (err ErrLastOrgOwner) Error() string {
  298. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  299. }
  300. // __________ .__ __
  301. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  302. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  303. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  304. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  305. // \/ \/|__| \/ \/
  306. // ErrRepoNotExist represents a "RepoNotExist" kind of error.
  307. type ErrRepoNotExist struct {
  308. ID int64
  309. UID int64
  310. Name string
  311. }
  312. // IsErrRepoNotExist checks if an error is a ErrRepoNotExist.
  313. func IsErrRepoNotExist(err error) bool {
  314. _, ok := err.(ErrRepoNotExist)
  315. return ok
  316. }
  317. func (err ErrRepoNotExist) Error() string {
  318. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
  319. }
  320. // ErrRepoAlreadyExist represents a "RepoAlreadyExist" kind of error.
  321. type ErrRepoAlreadyExist struct {
  322. Uname string
  323. Name string
  324. }
  325. // IsErrRepoAlreadyExist checks if an error is a ErrRepoAlreadyExist.
  326. func IsErrRepoAlreadyExist(err error) bool {
  327. _, ok := err.(ErrRepoAlreadyExist)
  328. return ok
  329. }
  330. func (err ErrRepoAlreadyExist) Error() string {
  331. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  332. }
  333. // ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error.
  334. type ErrInvalidCloneAddr struct {
  335. IsURLError bool
  336. IsInvalidPath bool
  337. IsPermissionDenied bool
  338. }
  339. // IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
  340. func IsErrInvalidCloneAddr(err error) bool {
  341. _, ok := err.(ErrInvalidCloneAddr)
  342. return ok
  343. }
  344. func (err ErrInvalidCloneAddr) Error() string {
  345. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  346. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  347. }
  348. // ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error.
  349. type ErrUpdateTaskNotExist struct {
  350. UUID string
  351. }
  352. // IsErrUpdateTaskNotExist checks if an error is a ErrUpdateTaskNotExist.
  353. func IsErrUpdateTaskNotExist(err error) bool {
  354. _, ok := err.(ErrUpdateTaskNotExist)
  355. return ok
  356. }
  357. func (err ErrUpdateTaskNotExist) Error() string {
  358. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  359. }
  360. // ErrReleaseAlreadyExist represents a "ReleaseAlreadyExist" kind of error.
  361. type ErrReleaseAlreadyExist struct {
  362. TagName string
  363. }
  364. // IsErrReleaseAlreadyExist checks if an error is a ErrReleaseAlreadyExist.
  365. func IsErrReleaseAlreadyExist(err error) bool {
  366. _, ok := err.(ErrReleaseAlreadyExist)
  367. return ok
  368. }
  369. func (err ErrReleaseAlreadyExist) Error() string {
  370. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  371. }
  372. // ErrReleaseNotExist represents a "ReleaseNotExist" kind of error.
  373. type ErrReleaseNotExist struct {
  374. ID int64
  375. TagName string
  376. }
  377. // IsErrReleaseNotExist checks if an error is a ErrReleaseNotExist.
  378. func IsErrReleaseNotExist(err error) bool {
  379. _, ok := err.(ErrReleaseNotExist)
  380. return ok
  381. }
  382. func (err ErrReleaseNotExist) Error() string {
  383. return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
  384. }
  385. // ErrInvalidTagName represents a "InvalidTagName" kind of error.
  386. type ErrInvalidTagName struct {
  387. TagName string
  388. }
  389. // IsErrInvalidTagName checks if an error is a ErrInvalidTagName.
  390. func IsErrInvalidTagName(err error) bool {
  391. _, ok := err.(ErrInvalidTagName)
  392. return ok
  393. }
  394. func (err ErrInvalidTagName) Error() string {
  395. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  396. }
  397. // ErrRepoFileAlreadyExist represents a "RepoFileAlreadyExist" kind of error.
  398. type ErrRepoFileAlreadyExist struct {
  399. FileName string
  400. }
  401. // IsErrRepoFileAlreadyExist checks if an error is a ErrRepoFileAlreadyExist.
  402. func IsErrRepoFileAlreadyExist(err error) bool {
  403. _, ok := err.(ErrRepoFileAlreadyExist)
  404. return ok
  405. }
  406. func (err ErrRepoFileAlreadyExist) Error() string {
  407. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  408. }
  409. // __________ .__
  410. // \______ \____________ ____ ____ | |__
  411. // | | _/\_ __ \__ \ / \_/ ___\| | \
  412. // | | \ | | \// __ \| | \ \___| Y \
  413. // |______ / |__| (____ /___| /\___ >___| /
  414. // \/ \/ \/ \/ \/
  415. // ErrBranchNotExist represents a "BranchNotExist" kind of error.
  416. type ErrBranchNotExist struct {
  417. Name string
  418. }
  419. // IsErrBranchNotExist checks if an error is a ErrBranchNotExist.
  420. func IsErrBranchNotExist(err error) bool {
  421. _, ok := err.(ErrBranchNotExist)
  422. return ok
  423. }
  424. func (err ErrBranchNotExist) Error() string {
  425. return fmt.Sprintf("branch does not exist [name: %s]", err.Name)
  426. }
  427. // __ __ ___. .__ __
  428. // / \ / \ ____\_ |__ | |__ ____ ____ | | __
  429. // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
  430. // \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
  431. // \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
  432. // \/ \/ \/ \/ \/
  433. // ErrWebhookNotExist represents a "WebhookNotExist" kind of error.
  434. type ErrWebhookNotExist struct {
  435. ID int64
  436. }
  437. // IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.
  438. func IsErrWebhookNotExist(err error) bool {
  439. _, ok := err.(ErrWebhookNotExist)
  440. return ok
  441. }
  442. func (err ErrWebhookNotExist) Error() string {
  443. return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
  444. }
  445. // .___
  446. // | | ______ ________ __ ____
  447. // | |/ ___// ___/ | \_/ __ \
  448. // | |\___ \ \___ \| | /\ ___/
  449. // |___/____ >____ >____/ \___ >
  450. // \/ \/ \/
  451. // ErrIssueNotExist represents a "IssueNotExist" kind of error.
  452. type ErrIssueNotExist struct {
  453. ID int64
  454. RepoID int64
  455. Index int64
  456. }
  457. // IsErrIssueNotExist checks if an error is a ErrIssueNotExist.
  458. func IsErrIssueNotExist(err error) bool {
  459. _, ok := err.(ErrIssueNotExist)
  460. return ok
  461. }
  462. func (err ErrIssueNotExist) Error() string {
  463. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  464. }
  465. // __________ .__ .__ __________ __
  466. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  467. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  468. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  469. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  470. // \/ \/ |__| \/ \/
  471. // ErrPullRequestNotExist represents a "PullRequestNotExist" kind of error.
  472. type ErrPullRequestNotExist struct {
  473. ID int64
  474. IssueID int64
  475. HeadRepoID int64
  476. BaseRepoID int64
  477. HeadBranch string
  478. BaseBranch string
  479. }
  480. // IsErrPullRequestNotExist checks if an error is a ErrPullRequestNotExist.
  481. func IsErrPullRequestNotExist(err error) bool {
  482. _, ok := err.(ErrPullRequestNotExist)
  483. return ok
  484. }
  485. func (err ErrPullRequestNotExist) Error() string {
  486. return fmt.Sprintf("pull request does not exist [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]",
  487. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  488. }
  489. // ErrPullRequestAlreadyExists represents a "PullRequestAlreadyExists"-error
  490. type ErrPullRequestAlreadyExists struct {
  491. ID int64
  492. IssueID int64
  493. HeadRepoID int64
  494. BaseRepoID int64
  495. HeadBranch string
  496. BaseBranch string
  497. }
  498. // IsErrPullRequestAlreadyExists checks if an error is a ErrPullRequestAlreadyExists.
  499. func IsErrPullRequestAlreadyExists(err error) bool {
  500. _, ok := err.(ErrPullRequestAlreadyExists)
  501. return ok
  502. }
  503. // Error does pretty-printing :D
  504. func (err ErrPullRequestAlreadyExists) Error() string {
  505. return fmt.Sprintf("pull request already exists for these targets [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]",
  506. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  507. }
  508. // _________ __
  509. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  510. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  511. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  512. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  513. // \/ \/ \/ \/ \/
  514. // ErrCommentNotExist represents a "CommentNotExist" kind of error.
  515. type ErrCommentNotExist struct {
  516. ID int64
  517. IssueID int64
  518. }
  519. // IsErrCommentNotExist checks if an error is a ErrCommentNotExist.
  520. func IsErrCommentNotExist(err error) bool {
  521. _, ok := err.(ErrCommentNotExist)
  522. return ok
  523. }
  524. func (err ErrCommentNotExist) Error() string {
  525. return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
  526. }
  527. // .____ ___. .__
  528. // | | _____ \_ |__ ____ | |
  529. // | | \__ \ | __ \_/ __ \| |
  530. // | |___ / __ \| \_\ \ ___/| |__
  531. // |_______ (____ /___ /\___ >____/
  532. // \/ \/ \/ \/
  533. // ErrLabelNotExist represents a "LabelNotExist" kind of error.
  534. type ErrLabelNotExist struct {
  535. LabelID int64
  536. RepoID int64
  537. }
  538. // IsErrLabelNotExist checks if an error is a ErrLabelNotExist.
  539. func IsErrLabelNotExist(err error) bool {
  540. _, ok := err.(ErrLabelNotExist)
  541. return ok
  542. }
  543. func (err ErrLabelNotExist) Error() string {
  544. return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
  545. }
  546. // _____ .__.__ __
  547. // / \ |__| | ____ _______/ |_ ____ ____ ____
  548. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  549. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  550. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  551. // \/ \/ \/ \/ \/
  552. // ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
  553. type ErrMilestoneNotExist struct {
  554. ID int64
  555. RepoID int64
  556. }
  557. // IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
  558. func IsErrMilestoneNotExist(err error) bool {
  559. _, ok := err.(ErrMilestoneNotExist)
  560. return ok
  561. }
  562. func (err ErrMilestoneNotExist) Error() string {
  563. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  564. }
  565. // _____ __ __ .__ __
  566. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  567. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  568. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  569. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  570. // \/ \/ \/ \/ \/ \/ \/
  571. // ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
  572. type ErrAttachmentNotExist struct {
  573. ID int64
  574. UUID string
  575. }
  576. // IsErrAttachmentNotExist checks if an error is a ErrAttachmentNotExist.
  577. func IsErrAttachmentNotExist(err error) bool {
  578. _, ok := err.(ErrAttachmentNotExist)
  579. return ok
  580. }
  581. func (err ErrAttachmentNotExist) Error() string {
  582. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  583. }
  584. // .____ .__ _________
  585. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  586. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  587. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  588. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  589. // \/ /_____/ \/ \/ \/ \/
  590. // ErrLoginSourceNotExist represents a "LoginSourceNotExist" kind of error.
  591. type ErrLoginSourceNotExist struct {
  592. ID int64
  593. }
  594. // IsErrLoginSourceNotExist checks if an error is a ErrLoginSourceNotExist.
  595. func IsErrLoginSourceNotExist(err error) bool {
  596. _, ok := err.(ErrLoginSourceNotExist)
  597. return ok
  598. }
  599. func (err ErrLoginSourceNotExist) Error() string {
  600. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  601. }
  602. // ErrLoginSourceAlreadyExist represents a "LoginSourceAlreadyExist" kind of error.
  603. type ErrLoginSourceAlreadyExist struct {
  604. Name string
  605. }
  606. // IsErrLoginSourceAlreadyExist checks if an error is a ErrLoginSourceAlreadyExist.
  607. func IsErrLoginSourceAlreadyExist(err error) bool {
  608. _, ok := err.(ErrLoginSourceAlreadyExist)
  609. return ok
  610. }
  611. func (err ErrLoginSourceAlreadyExist) Error() string {
  612. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  613. }
  614. // ErrLoginSourceInUse represents a "LoginSourceInUse" kind of error.
  615. type ErrLoginSourceInUse struct {
  616. ID int64
  617. }
  618. // IsErrLoginSourceInUse checks if an error is a ErrLoginSourceInUse.
  619. func IsErrLoginSourceInUse(err error) bool {
  620. _, ok := err.(ErrLoginSourceInUse)
  621. return ok
  622. }
  623. func (err ErrLoginSourceInUse) Error() string {
  624. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  625. }
  626. // ___________
  627. // \__ ___/___ _____ _____
  628. // | |_/ __ \\__ \ / \
  629. // | |\ ___/ / __ \| Y Y \
  630. // |____| \___ >____ /__|_| /
  631. // \/ \/ \/
  632. // ErrTeamAlreadyExist represents a "TeamAlreadyExist" kind of error.
  633. type ErrTeamAlreadyExist struct {
  634. OrgID int64
  635. Name string
  636. }
  637. // IsErrTeamAlreadyExist checks if an error is a ErrTeamAlreadyExist.
  638. func IsErrTeamAlreadyExist(err error) bool {
  639. _, ok := err.(ErrTeamAlreadyExist)
  640. return ok
  641. }
  642. func (err ErrTeamAlreadyExist) Error() string {
  643. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  644. }
  645. // ____ ___ .__ .___
  646. // | | \______ | | _________ __| _/
  647. // | | /\____ \| | / _ \__ \ / __ |
  648. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  649. // |______/ | __/|____/\____(____ /\____ |
  650. // |__| \/ \/
  651. //
  652. // ErrUploadNotExist represents a "UploadNotExist" kind of error.
  653. type ErrUploadNotExist struct {
  654. ID int64
  655. UUID string
  656. }
  657. // IsErrUploadNotExist checks if an error is a ErrUploadNotExist.
  658. func IsErrUploadNotExist(err error) bool {
  659. _, ok := err.(ErrAttachmentNotExist)
  660. return ok
  661. }
  662. func (err ErrUploadNotExist) Error() string {
  663. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  664. }