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 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  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. // ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
  78. type ErrOpenIDAlreadyUsed struct {
  79. OpenID string
  80. }
  81. // IsErrOpenIDAlreadyUsed checks if an error is a ErrOpenIDAlreadyUsed.
  82. func IsErrOpenIDAlreadyUsed(err error) bool {
  83. _, ok := err.(ErrOpenIDAlreadyUsed)
  84. return ok
  85. }
  86. func (err ErrOpenIDAlreadyUsed) Error() string {
  87. return fmt.Sprintf("OpenID has been used [oid: %s]", err.OpenID)
  88. }
  89. // ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
  90. type ErrUserOwnRepos struct {
  91. UID int64
  92. }
  93. // IsErrUserOwnRepos checks if an error is a ErrUserOwnRepos.
  94. func IsErrUserOwnRepos(err error) bool {
  95. _, ok := err.(ErrUserOwnRepos)
  96. return ok
  97. }
  98. func (err ErrUserOwnRepos) Error() string {
  99. return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
  100. }
  101. // ErrUserHasOrgs represents a "UserHasOrgs" kind of error.
  102. type ErrUserHasOrgs struct {
  103. UID int64
  104. }
  105. // IsErrUserHasOrgs checks if an error is a ErrUserHasOrgs.
  106. func IsErrUserHasOrgs(err error) bool {
  107. _, ok := err.(ErrUserHasOrgs)
  108. return ok
  109. }
  110. func (err ErrUserHasOrgs) Error() string {
  111. return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
  112. }
  113. // ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error.
  114. type ErrUserNotAllowedCreateOrg struct {
  115. }
  116. // IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg.
  117. func IsErrUserNotAllowedCreateOrg(err error) bool {
  118. _, ok := err.(ErrUserNotAllowedCreateOrg)
  119. return ok
  120. }
  121. func (err ErrUserNotAllowedCreateOrg) Error() string {
  122. return fmt.Sprintf("user is not allowed to create organizations")
  123. }
  124. // ErrReachLimitOfRepo represents a "ReachLimitOfRepo" kind of error.
  125. type ErrReachLimitOfRepo struct {
  126. Limit int
  127. }
  128. // IsErrReachLimitOfRepo checks if an error is a ErrReachLimitOfRepo.
  129. func IsErrReachLimitOfRepo(err error) bool {
  130. _, ok := err.(ErrReachLimitOfRepo)
  131. return ok
  132. }
  133. func (err ErrReachLimitOfRepo) Error() string {
  134. return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
  135. }
  136. // __ __.__ __ .__
  137. // / \ / \__| | _|__|
  138. // \ \/\/ / | |/ / |
  139. // \ /| | <| |
  140. // \__/\ / |__|__|_ \__|
  141. // \/ \/
  142. // ErrWikiAlreadyExist represents a "WikiAlreadyExist" kind of error.
  143. type ErrWikiAlreadyExist struct {
  144. Title string
  145. }
  146. // IsErrWikiAlreadyExist checks if an error is a ErrWikiAlreadyExist.
  147. func IsErrWikiAlreadyExist(err error) bool {
  148. _, ok := err.(ErrWikiAlreadyExist)
  149. return ok
  150. }
  151. func (err ErrWikiAlreadyExist) Error() string {
  152. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  153. }
  154. // __________ ___. .__ .__ ____ __.
  155. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  156. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  157. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  158. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  159. // \/ \/ \/ \/\/
  160. // ErrKeyUnableVerify represents a "KeyUnableVerify" kind of error.
  161. type ErrKeyUnableVerify struct {
  162. Result string
  163. }
  164. // IsErrKeyUnableVerify checks if an error is a ErrKeyUnableVerify.
  165. func IsErrKeyUnableVerify(err error) bool {
  166. _, ok := err.(ErrKeyUnableVerify)
  167. return ok
  168. }
  169. func (err ErrKeyUnableVerify) Error() string {
  170. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  171. }
  172. // ErrKeyNotExist represents a "KeyNotExist" kind of error.
  173. type ErrKeyNotExist struct {
  174. ID int64
  175. }
  176. // IsErrKeyNotExist checks if an error is a ErrKeyNotExist.
  177. func IsErrKeyNotExist(err error) bool {
  178. _, ok := err.(ErrKeyNotExist)
  179. return ok
  180. }
  181. func (err ErrKeyNotExist) Error() string {
  182. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  183. }
  184. // ErrKeyAlreadyExist represents a "KeyAlreadyExist" kind of error.
  185. type ErrKeyAlreadyExist struct {
  186. OwnerID int64
  187. Fingerprint string
  188. Content string
  189. }
  190. // IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.
  191. func IsErrKeyAlreadyExist(err error) bool {
  192. _, ok := err.(ErrKeyAlreadyExist)
  193. return ok
  194. }
  195. func (err ErrKeyAlreadyExist) Error() string {
  196. return fmt.Sprintf("public key already exists [owner_id: %d, finter_print: %s, content: %s]",
  197. err.OwnerID, err.Fingerprint, err.Content)
  198. }
  199. // ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
  200. type ErrKeyNameAlreadyUsed struct {
  201. OwnerID int64
  202. Name string
  203. }
  204. // IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  205. func IsErrKeyNameAlreadyUsed(err error) bool {
  206. _, ok := err.(ErrKeyNameAlreadyUsed)
  207. return ok
  208. }
  209. func (err ErrKeyNameAlreadyUsed) Error() string {
  210. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  211. }
  212. // ErrGPGEmailNotFound represents a "ErrGPGEmailNotFound" kind of error.
  213. type ErrGPGEmailNotFound struct {
  214. Email string
  215. }
  216. // IsErrGPGEmailNotFound checks if an error is a ErrGPGEmailNotFound.
  217. func IsErrGPGEmailNotFound(err error) bool {
  218. _, ok := err.(ErrGPGEmailNotFound)
  219. return ok
  220. }
  221. func (err ErrGPGEmailNotFound) Error() string {
  222. return fmt.Sprintf("failed to found email or is not confirmed : %s", err.Email)
  223. }
  224. // ErrGPGKeyParsing represents a "ErrGPGKeyParsing" kind of error.
  225. type ErrGPGKeyParsing struct {
  226. ParseError error
  227. }
  228. // IsErrGPGKeyParsing checks if an error is a ErrGPGKeyParsing.
  229. func IsErrGPGKeyParsing(err error) bool {
  230. _, ok := err.(ErrGPGKeyParsing)
  231. return ok
  232. }
  233. func (err ErrGPGKeyParsing) Error() string {
  234. return fmt.Sprintf("failed to parse gpg key %s", err.ParseError.Error())
  235. }
  236. // ErrGPGKeyNotExist represents a "GPGKeyNotExist" kind of error.
  237. type ErrGPGKeyNotExist struct {
  238. ID int64
  239. }
  240. // IsErrGPGKeyNotExist checks if an error is a ErrGPGKeyNotExist.
  241. func IsErrGPGKeyNotExist(err error) bool {
  242. _, ok := err.(ErrGPGKeyNotExist)
  243. return ok
  244. }
  245. func (err ErrGPGKeyNotExist) Error() string {
  246. return fmt.Sprintf("public gpg key does not exist [id: %d]", err.ID)
  247. }
  248. // ErrGPGKeyIDAlreadyUsed represents a "GPGKeyIDAlreadyUsed" kind of error.
  249. type ErrGPGKeyIDAlreadyUsed struct {
  250. KeyID string
  251. }
  252. // IsErrGPGKeyIDAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  253. func IsErrGPGKeyIDAlreadyUsed(err error) bool {
  254. _, ok := err.(ErrGPGKeyIDAlreadyUsed)
  255. return ok
  256. }
  257. func (err ErrGPGKeyIDAlreadyUsed) Error() string {
  258. return fmt.Sprintf("public key already exists [key_id: %s]", err.KeyID)
  259. }
  260. // ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error.
  261. type ErrGPGKeyAccessDenied struct {
  262. UserID int64
  263. KeyID int64
  264. }
  265. // IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.
  266. func IsErrGPGKeyAccessDenied(err error) bool {
  267. _, ok := err.(ErrGPGKeyAccessDenied)
  268. return ok
  269. }
  270. // Error pretty-prints an error of type ErrGPGKeyAccessDenied.
  271. func (err ErrGPGKeyAccessDenied) Error() string {
  272. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d]",
  273. err.UserID, err.KeyID)
  274. }
  275. // ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
  276. type ErrKeyAccessDenied struct {
  277. UserID int64
  278. KeyID int64
  279. Note string
  280. }
  281. // IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.
  282. func IsErrKeyAccessDenied(err error) bool {
  283. _, ok := err.(ErrKeyAccessDenied)
  284. return ok
  285. }
  286. func (err ErrKeyAccessDenied) Error() string {
  287. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  288. err.UserID, err.KeyID, err.Note)
  289. }
  290. // ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
  291. type ErrDeployKeyNotExist struct {
  292. ID int64
  293. KeyID int64
  294. RepoID int64
  295. }
  296. // IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.
  297. func IsErrDeployKeyNotExist(err error) bool {
  298. _, ok := err.(ErrDeployKeyNotExist)
  299. return ok
  300. }
  301. func (err ErrDeployKeyNotExist) Error() string {
  302. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  303. }
  304. // ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
  305. type ErrDeployKeyAlreadyExist struct {
  306. KeyID int64
  307. RepoID int64
  308. }
  309. // IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.
  310. func IsErrDeployKeyAlreadyExist(err error) bool {
  311. _, ok := err.(ErrDeployKeyAlreadyExist)
  312. return ok
  313. }
  314. func (err ErrDeployKeyAlreadyExist) Error() string {
  315. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  316. }
  317. // ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
  318. type ErrDeployKeyNameAlreadyUsed struct {
  319. RepoID int64
  320. Name string
  321. }
  322. // IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.
  323. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  324. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  325. return ok
  326. }
  327. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  328. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  329. }
  330. // _____ ___________ __
  331. // / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____
  332. // / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \
  333. // / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \
  334. // \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| /
  335. // \/ \/ \/ \/ \/ \/ \/ \/ \/
  336. // ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.
  337. type ErrAccessTokenNotExist struct {
  338. SHA string
  339. }
  340. // IsErrAccessTokenNotExist checks if an error is a ErrAccessTokenNotExist.
  341. func IsErrAccessTokenNotExist(err error) bool {
  342. _, ok := err.(ErrAccessTokenNotExist)
  343. return ok
  344. }
  345. func (err ErrAccessTokenNotExist) Error() string {
  346. return fmt.Sprintf("access token does not exist [sha: %s]", err.SHA)
  347. }
  348. // ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
  349. type ErrAccessTokenEmpty struct {
  350. }
  351. // IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
  352. func IsErrAccessTokenEmpty(err error) bool {
  353. _, ok := err.(ErrAccessTokenEmpty)
  354. return ok
  355. }
  356. func (err ErrAccessTokenEmpty) Error() string {
  357. return fmt.Sprintf("access token is empty")
  358. }
  359. // ________ .__ __ .__
  360. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  361. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  362. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  363. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  364. // \/ /_____/ \/ \/ \/ \/ \/
  365. // ErrLastOrgOwner represents a "LastOrgOwner" kind of error.
  366. type ErrLastOrgOwner struct {
  367. UID int64
  368. }
  369. // IsErrLastOrgOwner checks if an error is a ErrLastOrgOwner.
  370. func IsErrLastOrgOwner(err error) bool {
  371. _, ok := err.(ErrLastOrgOwner)
  372. return ok
  373. }
  374. func (err ErrLastOrgOwner) Error() string {
  375. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  376. }
  377. // __________ .__ __
  378. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  379. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  380. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  381. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  382. // \/ \/|__| \/ \/
  383. // ErrRepoNotExist represents a "RepoNotExist" kind of error.
  384. type ErrRepoNotExist struct {
  385. ID int64
  386. UID int64
  387. Name string
  388. }
  389. // IsErrRepoNotExist checks if an error is a ErrRepoNotExist.
  390. func IsErrRepoNotExist(err error) bool {
  391. _, ok := err.(ErrRepoNotExist)
  392. return ok
  393. }
  394. func (err ErrRepoNotExist) Error() string {
  395. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, name: %s]", err.ID, err.UID, err.Name)
  396. }
  397. // ErrRepoAlreadyExist represents a "RepoAlreadyExist" kind of error.
  398. type ErrRepoAlreadyExist struct {
  399. Uname string
  400. Name string
  401. }
  402. // IsErrRepoAlreadyExist checks if an error is a ErrRepoAlreadyExist.
  403. func IsErrRepoAlreadyExist(err error) bool {
  404. _, ok := err.(ErrRepoAlreadyExist)
  405. return ok
  406. }
  407. func (err ErrRepoAlreadyExist) Error() string {
  408. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  409. }
  410. // ErrRepoRedirectNotExist represents a "RepoRedirectNotExist" kind of error.
  411. type ErrRepoRedirectNotExist struct {
  412. OwnerID int64
  413. RepoName string
  414. }
  415. // IsErrRepoRedirectNotExist check if an error is an ErrRepoRedirectNotExist
  416. func IsErrRepoRedirectNotExist(err error) bool {
  417. _, ok := err.(ErrRepoRedirectNotExist)
  418. return ok
  419. }
  420. func (err ErrRepoRedirectNotExist) Error() string {
  421. return fmt.Sprintf("repository redirect does not exist [uid: %d, name: %s]", err.OwnerID, err.RepoName)
  422. }
  423. // ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error.
  424. type ErrInvalidCloneAddr struct {
  425. IsURLError bool
  426. IsInvalidPath bool
  427. IsPermissionDenied bool
  428. }
  429. // IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
  430. func IsErrInvalidCloneAddr(err error) bool {
  431. _, ok := err.(ErrInvalidCloneAddr)
  432. return ok
  433. }
  434. func (err ErrInvalidCloneAddr) Error() string {
  435. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  436. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  437. }
  438. // ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error.
  439. type ErrUpdateTaskNotExist struct {
  440. UUID string
  441. }
  442. // IsErrUpdateTaskNotExist checks if an error is a ErrUpdateTaskNotExist.
  443. func IsErrUpdateTaskNotExist(err error) bool {
  444. _, ok := err.(ErrUpdateTaskNotExist)
  445. return ok
  446. }
  447. func (err ErrUpdateTaskNotExist) Error() string {
  448. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  449. }
  450. // ErrReleaseAlreadyExist represents a "ReleaseAlreadyExist" kind of error.
  451. type ErrReleaseAlreadyExist struct {
  452. TagName string
  453. }
  454. // IsErrReleaseAlreadyExist checks if an error is a ErrReleaseAlreadyExist.
  455. func IsErrReleaseAlreadyExist(err error) bool {
  456. _, ok := err.(ErrReleaseAlreadyExist)
  457. return ok
  458. }
  459. func (err ErrReleaseAlreadyExist) Error() string {
  460. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  461. }
  462. // ErrReleaseNotExist represents a "ReleaseNotExist" kind of error.
  463. type ErrReleaseNotExist struct {
  464. ID int64
  465. TagName string
  466. }
  467. // IsErrReleaseNotExist checks if an error is a ErrReleaseNotExist.
  468. func IsErrReleaseNotExist(err error) bool {
  469. _, ok := err.(ErrReleaseNotExist)
  470. return ok
  471. }
  472. func (err ErrReleaseNotExist) Error() string {
  473. return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
  474. }
  475. // ErrInvalidTagName represents a "InvalidTagName" kind of error.
  476. type ErrInvalidTagName struct {
  477. TagName string
  478. }
  479. // IsErrInvalidTagName checks if an error is a ErrInvalidTagName.
  480. func IsErrInvalidTagName(err error) bool {
  481. _, ok := err.(ErrInvalidTagName)
  482. return ok
  483. }
  484. func (err ErrInvalidTagName) Error() string {
  485. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  486. }
  487. // ErrRepoFileAlreadyExist represents a "RepoFileAlreadyExist" kind of error.
  488. type ErrRepoFileAlreadyExist struct {
  489. FileName string
  490. }
  491. // IsErrRepoFileAlreadyExist checks if an error is a ErrRepoFileAlreadyExist.
  492. func IsErrRepoFileAlreadyExist(err error) bool {
  493. _, ok := err.(ErrRepoFileAlreadyExist)
  494. return ok
  495. }
  496. func (err ErrRepoFileAlreadyExist) Error() string {
  497. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  498. }
  499. // __________ .__
  500. // \______ \____________ ____ ____ | |__
  501. // | | _/\_ __ \__ \ / \_/ ___\| | \
  502. // | | \ | | \// __ \| | \ \___| Y \
  503. // |______ / |__| (____ /___| /\___ >___| /
  504. // \/ \/ \/ \/ \/
  505. // ErrBranchNotExist represents a "BranchNotExist" kind of error.
  506. type ErrBranchNotExist struct {
  507. Name string
  508. }
  509. // IsErrBranchNotExist checks if an error is a ErrBranchNotExist.
  510. func IsErrBranchNotExist(err error) bool {
  511. _, ok := err.(ErrBranchNotExist)
  512. return ok
  513. }
  514. func (err ErrBranchNotExist) Error() string {
  515. return fmt.Sprintf("branch does not exist [name: %s]", err.Name)
  516. }
  517. // __ __ ___. .__ __
  518. // / \ / \ ____\_ |__ | |__ ____ ____ | | __
  519. // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
  520. // \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
  521. // \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
  522. // \/ \/ \/ \/ \/
  523. // ErrWebhookNotExist represents a "WebhookNotExist" kind of error.
  524. type ErrWebhookNotExist struct {
  525. ID int64
  526. }
  527. // IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.
  528. func IsErrWebhookNotExist(err error) bool {
  529. _, ok := err.(ErrWebhookNotExist)
  530. return ok
  531. }
  532. func (err ErrWebhookNotExist) Error() string {
  533. return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
  534. }
  535. // .___
  536. // | | ______ ________ __ ____
  537. // | |/ ___// ___/ | \_/ __ \
  538. // | |\___ \ \___ \| | /\ ___/
  539. // |___/____ >____ >____/ \___ >
  540. // \/ \/ \/
  541. // ErrIssueNotExist represents a "IssueNotExist" kind of error.
  542. type ErrIssueNotExist struct {
  543. ID int64
  544. RepoID int64
  545. Index int64
  546. }
  547. // IsErrIssueNotExist checks if an error is a ErrIssueNotExist.
  548. func IsErrIssueNotExist(err error) bool {
  549. _, ok := err.(ErrIssueNotExist)
  550. return ok
  551. }
  552. func (err ErrIssueNotExist) Error() string {
  553. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  554. }
  555. // __________ .__ .__ __________ __
  556. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  557. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  558. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  559. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  560. // \/ \/ |__| \/ \/
  561. // ErrPullRequestNotExist represents a "PullRequestNotExist" kind of error.
  562. type ErrPullRequestNotExist struct {
  563. ID int64
  564. IssueID int64
  565. HeadRepoID int64
  566. BaseRepoID int64
  567. HeadBranch string
  568. BaseBranch string
  569. }
  570. // IsErrPullRequestNotExist checks if an error is a ErrPullRequestNotExist.
  571. func IsErrPullRequestNotExist(err error) bool {
  572. _, ok := err.(ErrPullRequestNotExist)
  573. return ok
  574. }
  575. func (err ErrPullRequestNotExist) Error() string {
  576. 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]",
  577. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  578. }
  579. // ErrPullRequestAlreadyExists represents a "PullRequestAlreadyExists"-error
  580. type ErrPullRequestAlreadyExists struct {
  581. ID int64
  582. IssueID int64
  583. HeadRepoID int64
  584. BaseRepoID int64
  585. HeadBranch string
  586. BaseBranch string
  587. }
  588. // IsErrPullRequestAlreadyExists checks if an error is a ErrPullRequestAlreadyExists.
  589. func IsErrPullRequestAlreadyExists(err error) bool {
  590. _, ok := err.(ErrPullRequestAlreadyExists)
  591. return ok
  592. }
  593. // Error does pretty-printing :D
  594. func (err ErrPullRequestAlreadyExists) Error() string {
  595. 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]",
  596. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  597. }
  598. // _________ __
  599. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  600. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  601. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  602. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  603. // \/ \/ \/ \/ \/
  604. // ErrCommentNotExist represents a "CommentNotExist" kind of error.
  605. type ErrCommentNotExist struct {
  606. ID int64
  607. IssueID int64
  608. }
  609. // IsErrCommentNotExist checks if an error is a ErrCommentNotExist.
  610. func IsErrCommentNotExist(err error) bool {
  611. _, ok := err.(ErrCommentNotExist)
  612. return ok
  613. }
  614. func (err ErrCommentNotExist) Error() string {
  615. return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
  616. }
  617. // .____ ___. .__
  618. // | | _____ \_ |__ ____ | |
  619. // | | \__ \ | __ \_/ __ \| |
  620. // | |___ / __ \| \_\ \ ___/| |__
  621. // |_______ (____ /___ /\___ >____/
  622. // \/ \/ \/ \/
  623. // ErrLabelNotExist represents a "LabelNotExist" kind of error.
  624. type ErrLabelNotExist struct {
  625. LabelID int64
  626. RepoID int64
  627. }
  628. // IsErrLabelNotExist checks if an error is a ErrLabelNotExist.
  629. func IsErrLabelNotExist(err error) bool {
  630. _, ok := err.(ErrLabelNotExist)
  631. return ok
  632. }
  633. func (err ErrLabelNotExist) Error() string {
  634. return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
  635. }
  636. // _____ .__.__ __
  637. // / \ |__| | ____ _______/ |_ ____ ____ ____
  638. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  639. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  640. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  641. // \/ \/ \/ \/ \/
  642. // ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
  643. type ErrMilestoneNotExist struct {
  644. ID int64
  645. RepoID int64
  646. }
  647. // IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
  648. func IsErrMilestoneNotExist(err error) bool {
  649. _, ok := err.(ErrMilestoneNotExist)
  650. return ok
  651. }
  652. func (err ErrMilestoneNotExist) Error() string {
  653. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  654. }
  655. // _____ __ __ .__ __
  656. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  657. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  658. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  659. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  660. // \/ \/ \/ \/ \/ \/ \/
  661. // ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
  662. type ErrAttachmentNotExist struct {
  663. ID int64
  664. UUID string
  665. }
  666. // IsErrAttachmentNotExist checks if an error is a ErrAttachmentNotExist.
  667. func IsErrAttachmentNotExist(err error) bool {
  668. _, ok := err.(ErrAttachmentNotExist)
  669. return ok
  670. }
  671. func (err ErrAttachmentNotExist) Error() string {
  672. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  673. }
  674. // .____ .__ _________
  675. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  676. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  677. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  678. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  679. // \/ /_____/ \/ \/ \/ \/
  680. // ErrLoginSourceNotExist represents a "LoginSourceNotExist" kind of error.
  681. type ErrLoginSourceNotExist struct {
  682. ID int64
  683. }
  684. // IsErrLoginSourceNotExist checks if an error is a ErrLoginSourceNotExist.
  685. func IsErrLoginSourceNotExist(err error) bool {
  686. _, ok := err.(ErrLoginSourceNotExist)
  687. return ok
  688. }
  689. func (err ErrLoginSourceNotExist) Error() string {
  690. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  691. }
  692. // ErrLoginSourceAlreadyExist represents a "LoginSourceAlreadyExist" kind of error.
  693. type ErrLoginSourceAlreadyExist struct {
  694. Name string
  695. }
  696. // IsErrLoginSourceAlreadyExist checks if an error is a ErrLoginSourceAlreadyExist.
  697. func IsErrLoginSourceAlreadyExist(err error) bool {
  698. _, ok := err.(ErrLoginSourceAlreadyExist)
  699. return ok
  700. }
  701. func (err ErrLoginSourceAlreadyExist) Error() string {
  702. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  703. }
  704. // ErrLoginSourceInUse represents a "LoginSourceInUse" kind of error.
  705. type ErrLoginSourceInUse struct {
  706. ID int64
  707. }
  708. // IsErrLoginSourceInUse checks if an error is a ErrLoginSourceInUse.
  709. func IsErrLoginSourceInUse(err error) bool {
  710. _, ok := err.(ErrLoginSourceInUse)
  711. return ok
  712. }
  713. func (err ErrLoginSourceInUse) Error() string {
  714. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  715. }
  716. // ___________
  717. // \__ ___/___ _____ _____
  718. // | |_/ __ \\__ \ / \
  719. // | |\ ___/ / __ \| Y Y \
  720. // |____| \___ >____ /__|_| /
  721. // \/ \/ \/
  722. // ErrTeamAlreadyExist represents a "TeamAlreadyExist" kind of error.
  723. type ErrTeamAlreadyExist struct {
  724. OrgID int64
  725. Name string
  726. }
  727. // IsErrTeamAlreadyExist checks if an error is a ErrTeamAlreadyExist.
  728. func IsErrTeamAlreadyExist(err error) bool {
  729. _, ok := err.(ErrTeamAlreadyExist)
  730. return ok
  731. }
  732. func (err ErrTeamAlreadyExist) Error() string {
  733. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  734. }
  735. //
  736. // Two-factor authentication
  737. //
  738. // ErrTwoFactorNotEnrolled indicates that a user is not enrolled in two-factor authentication.
  739. type ErrTwoFactorNotEnrolled struct {
  740. UID int64
  741. }
  742. // IsErrTwoFactorNotEnrolled checks if an error is a ErrTwoFactorNotEnrolled.
  743. func IsErrTwoFactorNotEnrolled(err error) bool {
  744. _, ok := err.(ErrTwoFactorNotEnrolled)
  745. return ok
  746. }
  747. func (err ErrTwoFactorNotEnrolled) Error() string {
  748. return fmt.Sprintf("user not enrolled in 2FA [uid: %d]", err.UID)
  749. }
  750. // ____ ___ .__ .___
  751. // | | \______ | | _________ __| _/
  752. // | | /\____ \| | / _ \__ \ / __ |
  753. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  754. // |______/ | __/|____/\____(____ /\____ |
  755. // |__| \/ \/
  756. //
  757. // ErrUploadNotExist represents a "UploadNotExist" kind of error.
  758. type ErrUploadNotExist struct {
  759. ID int64
  760. UUID string
  761. }
  762. // IsErrUploadNotExist checks if an error is a ErrUploadNotExist.
  763. func IsErrUploadNotExist(err error) bool {
  764. _, ok := err.(ErrAttachmentNotExist)
  765. return ok
  766. }
  767. func (err ErrUploadNotExist) Error() string {
  768. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  769. }
  770. // ___________ __ .__ .____ .__ ____ ___
  771. // \_ _____/__ ____/ |_ ___________ ____ _____ | | | | ____ ____ |__| ____ | | \______ ___________
  772. // | __)_\ \/ /\ __\/ __ \_ __ \/ \\__ \ | | | | / _ \ / ___\| |/ \ | | / ___// __ \_ __ \
  773. // | \> < | | \ ___/| | \/ | \/ __ \| |__ | |__( <_> ) /_/ > | | \ | | /\___ \\ ___/| | \/
  774. // /_______ /__/\_ \ |__| \___ >__| |___| (____ /____/ |_______ \____/\___ /|__|___| / |______//____ >\___ >__|
  775. // \/ \/ \/ \/ \/ \/ /_____/ \/ \/ \/
  776. // ErrExternalLoginUserAlreadyExist represents a "ExternalLoginUserAlreadyExist" kind of error.
  777. type ErrExternalLoginUserAlreadyExist struct {
  778. ExternalID string
  779. UserID int64
  780. LoginSourceID int64
  781. }
  782. // IsErrExternalLoginUserAlreadyExist checks if an error is a ExternalLoginUserAlreadyExist.
  783. func IsErrExternalLoginUserAlreadyExist(err error) bool {
  784. _, ok := err.(ErrExternalLoginUserAlreadyExist)
  785. return ok
  786. }
  787. func (err ErrExternalLoginUserAlreadyExist) Error() string {
  788. return fmt.Sprintf("external login user already exists [externalID: %s, userID: %d, loginSourceID: %d]", err.ExternalID, err.UserID, err.LoginSourceID)
  789. }
  790. // ErrExternalLoginUserNotExist represents a "ExternalLoginUserNotExist" kind of error.
  791. type ErrExternalLoginUserNotExist struct {
  792. UserID int64
  793. LoginSourceID int64
  794. }
  795. // IsErrExternalLoginUserNotExist checks if an error is a ExternalLoginUserNotExist.
  796. func IsErrExternalLoginUserNotExist(err error) bool {
  797. _, ok := err.(ErrExternalLoginUserNotExist)
  798. return ok
  799. }
  800. func (err ErrExternalLoginUserNotExist) Error() string {
  801. return fmt.Sprintf("external login user link does not exists [userID: %d, loginSourceID: %d]", err.UserID, err.LoginSourceID)
  802. }