Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

error.go 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  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. Fingerprint string
  176. Content string
  177. }
  178. // IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.
  179. func IsErrKeyAlreadyExist(err error) bool {
  180. _, ok := err.(ErrKeyAlreadyExist)
  181. return ok
  182. }
  183. func (err ErrKeyAlreadyExist) Error() string {
  184. return fmt.Sprintf("public key already exists [owner_id: %d, finter_print: %s, content: %s]",
  185. err.OwnerID, err.Fingerprint, err.Content)
  186. }
  187. // ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
  188. type ErrKeyNameAlreadyUsed struct {
  189. OwnerID int64
  190. Name string
  191. }
  192. // IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  193. func IsErrKeyNameAlreadyUsed(err error) bool {
  194. _, ok := err.(ErrKeyNameAlreadyUsed)
  195. return ok
  196. }
  197. func (err ErrKeyNameAlreadyUsed) Error() string {
  198. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  199. }
  200. // ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
  201. type ErrKeyAccessDenied struct {
  202. UserID int64
  203. KeyID int64
  204. Note string
  205. }
  206. // IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.
  207. func IsErrKeyAccessDenied(err error) bool {
  208. _, ok := err.(ErrKeyAccessDenied)
  209. return ok
  210. }
  211. func (err ErrKeyAccessDenied) Error() string {
  212. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  213. err.UserID, err.KeyID, err.Note)
  214. }
  215. // ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
  216. type ErrDeployKeyNotExist struct {
  217. ID int64
  218. KeyID int64
  219. RepoID int64
  220. }
  221. // IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.
  222. func IsErrDeployKeyNotExist(err error) bool {
  223. _, ok := err.(ErrDeployKeyNotExist)
  224. return ok
  225. }
  226. func (err ErrDeployKeyNotExist) Error() string {
  227. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  228. }
  229. // ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
  230. type ErrDeployKeyAlreadyExist struct {
  231. KeyID int64
  232. RepoID int64
  233. }
  234. // IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.
  235. func IsErrDeployKeyAlreadyExist(err error) bool {
  236. _, ok := err.(ErrDeployKeyAlreadyExist)
  237. return ok
  238. }
  239. func (err ErrDeployKeyAlreadyExist) Error() string {
  240. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  241. }
  242. // ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
  243. type ErrDeployKeyNameAlreadyUsed struct {
  244. RepoID int64
  245. Name string
  246. }
  247. // IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.
  248. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  249. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  250. return ok
  251. }
  252. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  253. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  254. }
  255. // _____ ___________ __
  256. // / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____
  257. // / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \
  258. // / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \
  259. // \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| /
  260. // \/ \/ \/ \/ \/ \/ \/ \/ \/
  261. // ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.
  262. type ErrAccessTokenNotExist struct {
  263. SHA string
  264. }
  265. // IsErrAccessTokenNotExist checks if an error is a ErrAccessTokenNotExist.
  266. func IsErrAccessTokenNotExist(err error) bool {
  267. _, ok := err.(ErrAccessTokenNotExist)
  268. return ok
  269. }
  270. func (err ErrAccessTokenNotExist) Error() string {
  271. return fmt.Sprintf("access token does not exist [sha: %s]", err.SHA)
  272. }
  273. // ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
  274. type ErrAccessTokenEmpty struct {
  275. }
  276. // IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
  277. func IsErrAccessTokenEmpty(err error) bool {
  278. _, ok := err.(ErrAccessTokenEmpty)
  279. return ok
  280. }
  281. func (err ErrAccessTokenEmpty) Error() string {
  282. return fmt.Sprintf("access token is empty")
  283. }
  284. // ________ .__ __ .__
  285. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  286. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  287. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  288. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  289. // \/ /_____/ \/ \/ \/ \/ \/
  290. // ErrLastOrgOwner represents a "LastOrgOwner" kind of error.
  291. type ErrLastOrgOwner struct {
  292. UID int64
  293. }
  294. // IsErrLastOrgOwner checks if an error is a ErrLastOrgOwner.
  295. func IsErrLastOrgOwner(err error) bool {
  296. _, ok := err.(ErrLastOrgOwner)
  297. return ok
  298. }
  299. func (err ErrLastOrgOwner) Error() string {
  300. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  301. }
  302. // __________ .__ __
  303. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  304. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  305. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  306. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  307. // \/ \/|__| \/ \/
  308. // ErrRepoNotExist represents a "RepoNotExist" kind of error.
  309. type ErrRepoNotExist struct {
  310. ID int64
  311. UID int64
  312. Name string
  313. }
  314. // IsErrRepoNotExist checks if an error is a ErrRepoNotExist.
  315. func IsErrRepoNotExist(err error) bool {
  316. _, ok := err.(ErrRepoNotExist)
  317. return ok
  318. }
  319. func (err ErrRepoNotExist) Error() string {
  320. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
  321. }
  322. // ErrRepoAlreadyExist represents a "RepoAlreadyExist" kind of error.
  323. type ErrRepoAlreadyExist struct {
  324. Uname string
  325. Name string
  326. }
  327. // IsErrRepoAlreadyExist checks if an error is a ErrRepoAlreadyExist.
  328. func IsErrRepoAlreadyExist(err error) bool {
  329. _, ok := err.(ErrRepoAlreadyExist)
  330. return ok
  331. }
  332. func (err ErrRepoAlreadyExist) Error() string {
  333. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  334. }
  335. // ErrRepoRedirectNotExist represents a "RepoRedirectNotExist" kind of error.
  336. type ErrRepoRedirectNotExist struct {
  337. OwnerID int64
  338. RepoName string
  339. }
  340. // IsErrRepoRedirectNotExist check if an error is an ErrRepoRedirectNotExist
  341. func IsErrRepoRedirectNotExist(err error) bool {
  342. _, ok := err.(ErrRepoRedirectNotExist)
  343. return ok
  344. }
  345. func (err ErrRepoRedirectNotExist) Error() string {
  346. return fmt.Sprintf("repository redirect does not exist [uid: %d, name: %s]", err.OwnerID, err.RepoName)
  347. }
  348. // ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error.
  349. type ErrInvalidCloneAddr struct {
  350. IsURLError bool
  351. IsInvalidPath bool
  352. IsPermissionDenied bool
  353. }
  354. // IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
  355. func IsErrInvalidCloneAddr(err error) bool {
  356. _, ok := err.(ErrInvalidCloneAddr)
  357. return ok
  358. }
  359. func (err ErrInvalidCloneAddr) Error() string {
  360. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  361. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  362. }
  363. // ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error.
  364. type ErrUpdateTaskNotExist struct {
  365. UUID string
  366. }
  367. // IsErrUpdateTaskNotExist checks if an error is a ErrUpdateTaskNotExist.
  368. func IsErrUpdateTaskNotExist(err error) bool {
  369. _, ok := err.(ErrUpdateTaskNotExist)
  370. return ok
  371. }
  372. func (err ErrUpdateTaskNotExist) Error() string {
  373. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  374. }
  375. // ErrReleaseAlreadyExist represents a "ReleaseAlreadyExist" kind of error.
  376. type ErrReleaseAlreadyExist struct {
  377. TagName string
  378. }
  379. // IsErrReleaseAlreadyExist checks if an error is a ErrReleaseAlreadyExist.
  380. func IsErrReleaseAlreadyExist(err error) bool {
  381. _, ok := err.(ErrReleaseAlreadyExist)
  382. return ok
  383. }
  384. func (err ErrReleaseAlreadyExist) Error() string {
  385. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  386. }
  387. // ErrReleaseNotExist represents a "ReleaseNotExist" kind of error.
  388. type ErrReleaseNotExist struct {
  389. ID int64
  390. TagName string
  391. }
  392. // IsErrReleaseNotExist checks if an error is a ErrReleaseNotExist.
  393. func IsErrReleaseNotExist(err error) bool {
  394. _, ok := err.(ErrReleaseNotExist)
  395. return ok
  396. }
  397. func (err ErrReleaseNotExist) Error() string {
  398. return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
  399. }
  400. // ErrInvalidTagName represents a "InvalidTagName" kind of error.
  401. type ErrInvalidTagName struct {
  402. TagName string
  403. }
  404. // IsErrInvalidTagName checks if an error is a ErrInvalidTagName.
  405. func IsErrInvalidTagName(err error) bool {
  406. _, ok := err.(ErrInvalidTagName)
  407. return ok
  408. }
  409. func (err ErrInvalidTagName) Error() string {
  410. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  411. }
  412. // ErrRepoFileAlreadyExist represents a "RepoFileAlreadyExist" kind of error.
  413. type ErrRepoFileAlreadyExist struct {
  414. FileName string
  415. }
  416. // IsErrRepoFileAlreadyExist checks if an error is a ErrRepoFileAlreadyExist.
  417. func IsErrRepoFileAlreadyExist(err error) bool {
  418. _, ok := err.(ErrRepoFileAlreadyExist)
  419. return ok
  420. }
  421. func (err ErrRepoFileAlreadyExist) Error() string {
  422. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  423. }
  424. // __________ .__
  425. // \______ \____________ ____ ____ | |__
  426. // | | _/\_ __ \__ \ / \_/ ___\| | \
  427. // | | \ | | \// __ \| | \ \___| Y \
  428. // |______ / |__| (____ /___| /\___ >___| /
  429. // \/ \/ \/ \/ \/
  430. // ErrBranchNotExist represents a "BranchNotExist" kind of error.
  431. type ErrBranchNotExist struct {
  432. Name string
  433. }
  434. // IsErrBranchNotExist checks if an error is a ErrBranchNotExist.
  435. func IsErrBranchNotExist(err error) bool {
  436. _, ok := err.(ErrBranchNotExist)
  437. return ok
  438. }
  439. func (err ErrBranchNotExist) Error() string {
  440. return fmt.Sprintf("branch does not exist [name: %s]", err.Name)
  441. }
  442. // __ __ ___. .__ __
  443. // / \ / \ ____\_ |__ | |__ ____ ____ | | __
  444. // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
  445. // \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
  446. // \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
  447. // \/ \/ \/ \/ \/
  448. // ErrWebhookNotExist represents a "WebhookNotExist" kind of error.
  449. type ErrWebhookNotExist struct {
  450. ID int64
  451. }
  452. // IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.
  453. func IsErrWebhookNotExist(err error) bool {
  454. _, ok := err.(ErrWebhookNotExist)
  455. return ok
  456. }
  457. func (err ErrWebhookNotExist) Error() string {
  458. return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
  459. }
  460. // .___
  461. // | | ______ ________ __ ____
  462. // | |/ ___// ___/ | \_/ __ \
  463. // | |\___ \ \___ \| | /\ ___/
  464. // |___/____ >____ >____/ \___ >
  465. // \/ \/ \/
  466. // ErrIssueNotExist represents a "IssueNotExist" kind of error.
  467. type ErrIssueNotExist struct {
  468. ID int64
  469. RepoID int64
  470. Index int64
  471. }
  472. // IsErrIssueNotExist checks if an error is a ErrIssueNotExist.
  473. func IsErrIssueNotExist(err error) bool {
  474. _, ok := err.(ErrIssueNotExist)
  475. return ok
  476. }
  477. func (err ErrIssueNotExist) Error() string {
  478. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  479. }
  480. // __________ .__ .__ __________ __
  481. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  482. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  483. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  484. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  485. // \/ \/ |__| \/ \/
  486. // ErrPullRequestNotExist represents a "PullRequestNotExist" kind of error.
  487. type ErrPullRequestNotExist struct {
  488. ID int64
  489. IssueID int64
  490. HeadRepoID int64
  491. BaseRepoID int64
  492. HeadBranch string
  493. BaseBranch string
  494. }
  495. // IsErrPullRequestNotExist checks if an error is a ErrPullRequestNotExist.
  496. func IsErrPullRequestNotExist(err error) bool {
  497. _, ok := err.(ErrPullRequestNotExist)
  498. return ok
  499. }
  500. func (err ErrPullRequestNotExist) Error() string {
  501. 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]",
  502. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  503. }
  504. // ErrPullRequestAlreadyExists represents a "PullRequestAlreadyExists"-error
  505. type ErrPullRequestAlreadyExists struct {
  506. ID int64
  507. IssueID int64
  508. HeadRepoID int64
  509. BaseRepoID int64
  510. HeadBranch string
  511. BaseBranch string
  512. }
  513. // IsErrPullRequestAlreadyExists checks if an error is a ErrPullRequestAlreadyExists.
  514. func IsErrPullRequestAlreadyExists(err error) bool {
  515. _, ok := err.(ErrPullRequestAlreadyExists)
  516. return ok
  517. }
  518. // Error does pretty-printing :D
  519. func (err ErrPullRequestAlreadyExists) Error() string {
  520. 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]",
  521. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  522. }
  523. // _________ __
  524. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  525. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  526. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  527. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  528. // \/ \/ \/ \/ \/
  529. // ErrCommentNotExist represents a "CommentNotExist" kind of error.
  530. type ErrCommentNotExist struct {
  531. ID int64
  532. IssueID int64
  533. }
  534. // IsErrCommentNotExist checks if an error is a ErrCommentNotExist.
  535. func IsErrCommentNotExist(err error) bool {
  536. _, ok := err.(ErrCommentNotExist)
  537. return ok
  538. }
  539. func (err ErrCommentNotExist) Error() string {
  540. return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
  541. }
  542. // .____ ___. .__
  543. // | | _____ \_ |__ ____ | |
  544. // | | \__ \ | __ \_/ __ \| |
  545. // | |___ / __ \| \_\ \ ___/| |__
  546. // |_______ (____ /___ /\___ >____/
  547. // \/ \/ \/ \/
  548. // ErrLabelNotExist represents a "LabelNotExist" kind of error.
  549. type ErrLabelNotExist struct {
  550. LabelID int64
  551. RepoID int64
  552. }
  553. // IsErrLabelNotExist checks if an error is a ErrLabelNotExist.
  554. func IsErrLabelNotExist(err error) bool {
  555. _, ok := err.(ErrLabelNotExist)
  556. return ok
  557. }
  558. func (err ErrLabelNotExist) Error() string {
  559. return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
  560. }
  561. // _____ .__.__ __
  562. // / \ |__| | ____ _______/ |_ ____ ____ ____
  563. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  564. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  565. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  566. // \/ \/ \/ \/ \/
  567. // ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
  568. type ErrMilestoneNotExist struct {
  569. ID int64
  570. RepoID int64
  571. }
  572. // IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
  573. func IsErrMilestoneNotExist(err error) bool {
  574. _, ok := err.(ErrMilestoneNotExist)
  575. return ok
  576. }
  577. func (err ErrMilestoneNotExist) Error() string {
  578. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  579. }
  580. // _____ __ __ .__ __
  581. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  582. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  583. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  584. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  585. // \/ \/ \/ \/ \/ \/ \/
  586. // ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
  587. type ErrAttachmentNotExist struct {
  588. ID int64
  589. UUID string
  590. }
  591. // IsErrAttachmentNotExist checks if an error is a ErrAttachmentNotExist.
  592. func IsErrAttachmentNotExist(err error) bool {
  593. _, ok := err.(ErrAttachmentNotExist)
  594. return ok
  595. }
  596. func (err ErrAttachmentNotExist) Error() string {
  597. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  598. }
  599. // .____ .__ _________
  600. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  601. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  602. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  603. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  604. // \/ /_____/ \/ \/ \/ \/
  605. // ErrLoginSourceNotExist represents a "LoginSourceNotExist" kind of error.
  606. type ErrLoginSourceNotExist struct {
  607. ID int64
  608. }
  609. // IsErrLoginSourceNotExist checks if an error is a ErrLoginSourceNotExist.
  610. func IsErrLoginSourceNotExist(err error) bool {
  611. _, ok := err.(ErrLoginSourceNotExist)
  612. return ok
  613. }
  614. func (err ErrLoginSourceNotExist) Error() string {
  615. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  616. }
  617. // ErrLoginSourceAlreadyExist represents a "LoginSourceAlreadyExist" kind of error.
  618. type ErrLoginSourceAlreadyExist struct {
  619. Name string
  620. }
  621. // IsErrLoginSourceAlreadyExist checks if an error is a ErrLoginSourceAlreadyExist.
  622. func IsErrLoginSourceAlreadyExist(err error) bool {
  623. _, ok := err.(ErrLoginSourceAlreadyExist)
  624. return ok
  625. }
  626. func (err ErrLoginSourceAlreadyExist) Error() string {
  627. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  628. }
  629. // ErrLoginSourceInUse represents a "LoginSourceInUse" kind of error.
  630. type ErrLoginSourceInUse struct {
  631. ID int64
  632. }
  633. // IsErrLoginSourceInUse checks if an error is a ErrLoginSourceInUse.
  634. func IsErrLoginSourceInUse(err error) bool {
  635. _, ok := err.(ErrLoginSourceInUse)
  636. return ok
  637. }
  638. func (err ErrLoginSourceInUse) Error() string {
  639. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  640. }
  641. // ___________
  642. // \__ ___/___ _____ _____
  643. // | |_/ __ \\__ \ / \
  644. // | |\ ___/ / __ \| Y Y \
  645. // |____| \___ >____ /__|_| /
  646. // \/ \/ \/
  647. // ErrTeamAlreadyExist represents a "TeamAlreadyExist" kind of error.
  648. type ErrTeamAlreadyExist struct {
  649. OrgID int64
  650. Name string
  651. }
  652. // IsErrTeamAlreadyExist checks if an error is a ErrTeamAlreadyExist.
  653. func IsErrTeamAlreadyExist(err error) bool {
  654. _, ok := err.(ErrTeamAlreadyExist)
  655. return ok
  656. }
  657. func (err ErrTeamAlreadyExist) Error() string {
  658. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  659. }
  660. //
  661. // Two-factor authentication
  662. //
  663. // ErrTwoFactorNotEnrolled indicates that a user is not enrolled in two-factor authentication.
  664. type ErrTwoFactorNotEnrolled struct {
  665. UID int64
  666. }
  667. // IsErrTwoFactorNotEnrolled checks if an error is a ErrTwoFactorNotEnrolled.
  668. func IsErrTwoFactorNotEnrolled(err error) bool {
  669. _, ok := err.(ErrTwoFactorNotEnrolled)
  670. return ok
  671. }
  672. func (err ErrTwoFactorNotEnrolled) Error() string {
  673. return fmt.Sprintf("user not enrolled in 2FA [uid: %d]", err.UID)
  674. }
  675. // ____ ___ .__ .___
  676. // | | \______ | | _________ __| _/
  677. // | | /\____ \| | / _ \__ \ / __ |
  678. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  679. // |______/ | __/|____/\____(____ /\____ |
  680. // |__| \/ \/
  681. //
  682. // ErrUploadNotExist represents a "UploadNotExist" kind of error.
  683. type ErrUploadNotExist struct {
  684. ID int64
  685. UUID string
  686. }
  687. // IsErrUploadNotExist checks if an error is a ErrUploadNotExist.
  688. func IsErrUploadNotExist(err error) bool {
  689. _, ok := err.(ErrAttachmentNotExist)
  690. return ok
  691. }
  692. func (err ErrUploadNotExist) Error() string {
  693. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  694. }
  695. // ___________ __ .__ .____ .__ ____ ___
  696. // \_ _____/__ ____/ |_ ___________ ____ _____ | | | | ____ ____ |__| ____ | | \______ ___________
  697. // | __)_\ \/ /\ __\/ __ \_ __ \/ \\__ \ | | | | / _ \ / ___\| |/ \ | | / ___// __ \_ __ \
  698. // | \> < | | \ ___/| | \/ | \/ __ \| |__ | |__( <_> ) /_/ > | | \ | | /\___ \\ ___/| | \/
  699. // /_______ /__/\_ \ |__| \___ >__| |___| (____ /____/ |_______ \____/\___ /|__|___| / |______//____ >\___ >__|
  700. // \/ \/ \/ \/ \/ \/ /_____/ \/ \/ \/
  701. // ErrExternalLoginUserAlreadyExist represents a "ExternalLoginUserAlreadyExist" kind of error.
  702. type ErrExternalLoginUserAlreadyExist struct {
  703. ExternalID string
  704. UserID int64
  705. LoginSourceID int64
  706. }
  707. // IsErrExternalLoginUserAlreadyExist checks if an error is a ExternalLoginUserAlreadyExist.
  708. func IsErrExternalLoginUserAlreadyExist(err error) bool {
  709. _, ok := err.(ErrExternalLoginUserAlreadyExist)
  710. return ok
  711. }
  712. func (err ErrExternalLoginUserAlreadyExist) Error() string {
  713. return fmt.Sprintf("external login user already exists [externalID: %s, userID: %d, loginSourceID: %d]", err.ExternalID, err.UserID, err.LoginSourceID)
  714. }
  715. // ErrExternalLoginUserNotExist represents a "ExternalLoginUserNotExist" kind of error.
  716. type ErrExternalLoginUserNotExist struct {
  717. UserID int64
  718. LoginSourceID int64
  719. }
  720. // IsErrExternalLoginUserNotExist checks if an error is a ExternalLoginUserNotExist.
  721. func IsErrExternalLoginUserNotExist(err error) bool {
  722. _, ok := err.(ErrExternalLoginUserNotExist)
  723. return ok
  724. }
  725. func (err ErrExternalLoginUserNotExist) Error() string {
  726. return fmt.Sprintf("external login user link does not exists [userID: %d, loginSourceID: %d]", err.UserID, err.LoginSourceID)
  727. }