Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

error.go 32KB

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