本站源代码
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

1670 行
51KB

  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package models
  6. import (
  7. "fmt"
  8. "code.gitea.io/gitea/modules/git"
  9. )
  10. // ErrNotExist represents a non-exist error.
  11. type ErrNotExist struct {
  12. ID int64
  13. }
  14. // IsErrNotExist checks if an error is an ErrNotExist
  15. func IsErrNotExist(err error) bool {
  16. _, ok := err.(ErrNotExist)
  17. return ok
  18. }
  19. func (err ErrNotExist) Error() string {
  20. return fmt.Sprintf("record does not exist [id: %d]", err.ID)
  21. }
  22. // ErrNameReserved represents a "reserved name" error.
  23. type ErrNameReserved struct {
  24. Name string
  25. }
  26. // IsErrNameReserved checks if an error is a ErrNameReserved.
  27. func IsErrNameReserved(err error) bool {
  28. _, ok := err.(ErrNameReserved)
  29. return ok
  30. }
  31. func (err ErrNameReserved) Error() string {
  32. return fmt.Sprintf("name is reserved [name: %s]", err.Name)
  33. }
  34. // ErrNamePatternNotAllowed represents a "pattern not allowed" error.
  35. type ErrNamePatternNotAllowed struct {
  36. Pattern string
  37. }
  38. // IsErrNamePatternNotAllowed checks if an error is an ErrNamePatternNotAllowed.
  39. func IsErrNamePatternNotAllowed(err error) bool {
  40. _, ok := err.(ErrNamePatternNotAllowed)
  41. return ok
  42. }
  43. func (err ErrNamePatternNotAllowed) Error() string {
  44. return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
  45. }
  46. // ErrSSHDisabled represents an "SSH disabled" error.
  47. type ErrSSHDisabled struct {
  48. }
  49. // IsErrSSHDisabled checks if an error is a ErrSSHDisabled.
  50. func IsErrSSHDisabled(err error) bool {
  51. _, ok := err.(ErrSSHDisabled)
  52. return ok
  53. }
  54. func (err ErrSSHDisabled) Error() string {
  55. return "SSH is disabled"
  56. }
  57. // ____ ___
  58. // | | \______ ___________
  59. // | | / ___// __ \_ __ \
  60. // | | /\___ \\ ___/| | \/
  61. // |______//____ >\___ >__|
  62. // \/ \/
  63. // ErrUserAlreadyExist represents a "user already exists" error.
  64. type ErrUserAlreadyExist struct {
  65. Name string
  66. }
  67. // IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.
  68. func IsErrUserAlreadyExist(err error) bool {
  69. _, ok := err.(ErrUserAlreadyExist)
  70. return ok
  71. }
  72. func (err ErrUserAlreadyExist) Error() string {
  73. return fmt.Sprintf("user already exists [name: %s]", err.Name)
  74. }
  75. // ErrUserNotExist represents a "UserNotExist" kind of error.
  76. type ErrUserNotExist struct {
  77. UID int64
  78. Name string
  79. KeyID int64
  80. }
  81. // IsErrUserNotExist checks if an error is a ErrUserNotExist.
  82. func IsErrUserNotExist(err error) bool {
  83. _, ok := err.(ErrUserNotExist)
  84. return ok
  85. }
  86. func (err ErrUserNotExist) Error() string {
  87. return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID)
  88. }
  89. // ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
  90. type ErrUserProhibitLogin struct {
  91. UID int64
  92. Name string
  93. }
  94. // IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin
  95. func IsErrUserProhibitLogin(err error) bool {
  96. _, ok := err.(ErrUserProhibitLogin)
  97. return ok
  98. }
  99. func (err ErrUserProhibitLogin) Error() string {
  100. return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name)
  101. }
  102. // ErrUserInactive represents a "ErrUserInactive" kind of error.
  103. type ErrUserInactive struct {
  104. UID int64
  105. Name string
  106. }
  107. // IsErrUserInactive checks if an error is a ErrUserInactive
  108. func IsErrUserInactive(err error) bool {
  109. _, ok := err.(ErrUserInactive)
  110. return ok
  111. }
  112. func (err ErrUserInactive) Error() string {
  113. return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
  114. }
  115. // ErrEmailAlreadyUsed represents a "EmailAlreadyUsed" kind of error.
  116. type ErrEmailAlreadyUsed struct {
  117. Email string
  118. }
  119. // IsErrEmailAlreadyUsed checks if an error is a ErrEmailAlreadyUsed.
  120. func IsErrEmailAlreadyUsed(err error) bool {
  121. _, ok := err.(ErrEmailAlreadyUsed)
  122. return ok
  123. }
  124. func (err ErrEmailAlreadyUsed) Error() string {
  125. return fmt.Sprintf("e-mail already in use [email: %s]", err.Email)
  126. }
  127. // ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
  128. type ErrOpenIDAlreadyUsed struct {
  129. OpenID string
  130. }
  131. // IsErrOpenIDAlreadyUsed checks if an error is a ErrOpenIDAlreadyUsed.
  132. func IsErrOpenIDAlreadyUsed(err error) bool {
  133. _, ok := err.(ErrOpenIDAlreadyUsed)
  134. return ok
  135. }
  136. func (err ErrOpenIDAlreadyUsed) Error() string {
  137. return fmt.Sprintf("OpenID already in use [oid: %s]", err.OpenID)
  138. }
  139. // ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
  140. type ErrUserOwnRepos struct {
  141. UID int64
  142. }
  143. // IsErrUserOwnRepos checks if an error is a ErrUserOwnRepos.
  144. func IsErrUserOwnRepos(err error) bool {
  145. _, ok := err.(ErrUserOwnRepos)
  146. return ok
  147. }
  148. func (err ErrUserOwnRepos) Error() string {
  149. return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
  150. }
  151. // ErrUserHasOrgs represents a "UserHasOrgs" kind of error.
  152. type ErrUserHasOrgs struct {
  153. UID int64
  154. }
  155. // IsErrUserHasOrgs checks if an error is a ErrUserHasOrgs.
  156. func IsErrUserHasOrgs(err error) bool {
  157. _, ok := err.(ErrUserHasOrgs)
  158. return ok
  159. }
  160. func (err ErrUserHasOrgs) Error() string {
  161. return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
  162. }
  163. // ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error.
  164. type ErrUserNotAllowedCreateOrg struct {
  165. }
  166. // IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg.
  167. func IsErrUserNotAllowedCreateOrg(err error) bool {
  168. _, ok := err.(ErrUserNotAllowedCreateOrg)
  169. return ok
  170. }
  171. func (err ErrUserNotAllowedCreateOrg) Error() string {
  172. return fmt.Sprintf("user is not allowed to create organizations")
  173. }
  174. // ErrReachLimitOfRepo represents a "ReachLimitOfRepo" kind of error.
  175. type ErrReachLimitOfRepo struct {
  176. Limit int
  177. }
  178. // IsErrReachLimitOfRepo checks if an error is a ErrReachLimitOfRepo.
  179. func IsErrReachLimitOfRepo(err error) bool {
  180. _, ok := err.(ErrReachLimitOfRepo)
  181. return ok
  182. }
  183. func (err ErrReachLimitOfRepo) Error() string {
  184. return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
  185. }
  186. // __ __.__ __ .__
  187. // / \ / \__| | _|__|
  188. // \ \/\/ / | |/ / |
  189. // \ /| | <| |
  190. // \__/\ / |__|__|_ \__|
  191. // \/ \/
  192. // ErrWikiAlreadyExist represents a "WikiAlreadyExist" kind of error.
  193. type ErrWikiAlreadyExist struct {
  194. Title string
  195. }
  196. // IsErrWikiAlreadyExist checks if an error is an ErrWikiAlreadyExist.
  197. func IsErrWikiAlreadyExist(err error) bool {
  198. _, ok := err.(ErrWikiAlreadyExist)
  199. return ok
  200. }
  201. func (err ErrWikiAlreadyExist) Error() string {
  202. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  203. }
  204. // ErrWikiReservedName represents a reserved name error.
  205. type ErrWikiReservedName struct {
  206. Title string
  207. }
  208. // IsErrWikiReservedName checks if an error is an ErrWikiReservedName.
  209. func IsErrWikiReservedName(err error) bool {
  210. _, ok := err.(ErrWikiReservedName)
  211. return ok
  212. }
  213. func (err ErrWikiReservedName) Error() string {
  214. return fmt.Sprintf("wiki title is reserved: %s", err.Title)
  215. }
  216. // ErrWikiInvalidFileName represents an invalid wiki file name.
  217. type ErrWikiInvalidFileName struct {
  218. FileName string
  219. }
  220. // IsErrWikiInvalidFileName checks if an error is an ErrWikiInvalidFileName.
  221. func IsErrWikiInvalidFileName(err error) bool {
  222. _, ok := err.(ErrWikiInvalidFileName)
  223. return ok
  224. }
  225. func (err ErrWikiInvalidFileName) Error() string {
  226. return fmt.Sprintf("Invalid wiki filename: %s", err.FileName)
  227. }
  228. // __________ ___. .__ .__ ____ __.
  229. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  230. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  231. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  232. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  233. // \/ \/ \/ \/\/
  234. // ErrKeyUnableVerify represents a "KeyUnableVerify" kind of error.
  235. type ErrKeyUnableVerify struct {
  236. Result string
  237. }
  238. // IsErrKeyUnableVerify checks if an error is a ErrKeyUnableVerify.
  239. func IsErrKeyUnableVerify(err error) bool {
  240. _, ok := err.(ErrKeyUnableVerify)
  241. return ok
  242. }
  243. func (err ErrKeyUnableVerify) Error() string {
  244. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  245. }
  246. // ErrKeyNotExist represents a "KeyNotExist" kind of error.
  247. type ErrKeyNotExist struct {
  248. ID int64
  249. }
  250. // IsErrKeyNotExist checks if an error is a ErrKeyNotExist.
  251. func IsErrKeyNotExist(err error) bool {
  252. _, ok := err.(ErrKeyNotExist)
  253. return ok
  254. }
  255. func (err ErrKeyNotExist) Error() string {
  256. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  257. }
  258. // ErrKeyAlreadyExist represents a "KeyAlreadyExist" kind of error.
  259. type ErrKeyAlreadyExist struct {
  260. OwnerID int64
  261. Fingerprint string
  262. Content string
  263. }
  264. // IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.
  265. func IsErrKeyAlreadyExist(err error) bool {
  266. _, ok := err.(ErrKeyAlreadyExist)
  267. return ok
  268. }
  269. func (err ErrKeyAlreadyExist) Error() string {
  270. return fmt.Sprintf("public key already exists [owner_id: %d, finger_print: %s, content: %s]",
  271. err.OwnerID, err.Fingerprint, err.Content)
  272. }
  273. // ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
  274. type ErrKeyNameAlreadyUsed struct {
  275. OwnerID int64
  276. Name string
  277. }
  278. // IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  279. func IsErrKeyNameAlreadyUsed(err error) bool {
  280. _, ok := err.(ErrKeyNameAlreadyUsed)
  281. return ok
  282. }
  283. func (err ErrKeyNameAlreadyUsed) Error() string {
  284. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  285. }
  286. // ErrGPGNoEmailFound represents a "ErrGPGNoEmailFound" kind of error.
  287. type ErrGPGNoEmailFound struct {
  288. FailedEmails []string
  289. }
  290. // IsErrGPGNoEmailFound checks if an error is a ErrGPGNoEmailFound.
  291. func IsErrGPGNoEmailFound(err error) bool {
  292. _, ok := err.(ErrGPGNoEmailFound)
  293. return ok
  294. }
  295. func (err ErrGPGNoEmailFound) Error() string {
  296. return fmt.Sprintf("none of the emails attached to the GPG key could be found: %v", err.FailedEmails)
  297. }
  298. // ErrGPGKeyParsing represents a "ErrGPGKeyParsing" kind of error.
  299. type ErrGPGKeyParsing struct {
  300. ParseError error
  301. }
  302. // IsErrGPGKeyParsing checks if an error is a ErrGPGKeyParsing.
  303. func IsErrGPGKeyParsing(err error) bool {
  304. _, ok := err.(ErrGPGKeyParsing)
  305. return ok
  306. }
  307. func (err ErrGPGKeyParsing) Error() string {
  308. return fmt.Sprintf("failed to parse gpg key %s", err.ParseError.Error())
  309. }
  310. // ErrGPGKeyNotExist represents a "GPGKeyNotExist" kind of error.
  311. type ErrGPGKeyNotExist struct {
  312. ID int64
  313. }
  314. // IsErrGPGKeyNotExist checks if an error is a ErrGPGKeyNotExist.
  315. func IsErrGPGKeyNotExist(err error) bool {
  316. _, ok := err.(ErrGPGKeyNotExist)
  317. return ok
  318. }
  319. func (err ErrGPGKeyNotExist) Error() string {
  320. return fmt.Sprintf("public gpg key does not exist [id: %d]", err.ID)
  321. }
  322. // ErrGPGKeyImportNotExist represents a "GPGKeyImportNotExist" kind of error.
  323. type ErrGPGKeyImportNotExist struct {
  324. ID string
  325. }
  326. // IsErrGPGKeyImportNotExist checks if an error is a ErrGPGKeyImportNotExist.
  327. func IsErrGPGKeyImportNotExist(err error) bool {
  328. _, ok := err.(ErrGPGKeyImportNotExist)
  329. return ok
  330. }
  331. func (err ErrGPGKeyImportNotExist) Error() string {
  332. return fmt.Sprintf("public gpg key import does not exist [id: %s]", err.ID)
  333. }
  334. // ErrGPGKeyIDAlreadyUsed represents a "GPGKeyIDAlreadyUsed" kind of error.
  335. type ErrGPGKeyIDAlreadyUsed struct {
  336. KeyID string
  337. }
  338. // IsErrGPGKeyIDAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  339. func IsErrGPGKeyIDAlreadyUsed(err error) bool {
  340. _, ok := err.(ErrGPGKeyIDAlreadyUsed)
  341. return ok
  342. }
  343. func (err ErrGPGKeyIDAlreadyUsed) Error() string {
  344. return fmt.Sprintf("public key already exists [key_id: %s]", err.KeyID)
  345. }
  346. // ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error.
  347. type ErrGPGKeyAccessDenied struct {
  348. UserID int64
  349. KeyID int64
  350. }
  351. // IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.
  352. func IsErrGPGKeyAccessDenied(err error) bool {
  353. _, ok := err.(ErrGPGKeyAccessDenied)
  354. return ok
  355. }
  356. // Error pretty-prints an error of type ErrGPGKeyAccessDenied.
  357. func (err ErrGPGKeyAccessDenied) Error() string {
  358. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d]",
  359. err.UserID, err.KeyID)
  360. }
  361. // ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
  362. type ErrKeyAccessDenied struct {
  363. UserID int64
  364. KeyID int64
  365. Note string
  366. }
  367. // IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.
  368. func IsErrKeyAccessDenied(err error) bool {
  369. _, ok := err.(ErrKeyAccessDenied)
  370. return ok
  371. }
  372. func (err ErrKeyAccessDenied) Error() string {
  373. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  374. err.UserID, err.KeyID, err.Note)
  375. }
  376. // ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
  377. type ErrDeployKeyNotExist struct {
  378. ID int64
  379. KeyID int64
  380. RepoID int64
  381. }
  382. // IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.
  383. func IsErrDeployKeyNotExist(err error) bool {
  384. _, ok := err.(ErrDeployKeyNotExist)
  385. return ok
  386. }
  387. func (err ErrDeployKeyNotExist) Error() string {
  388. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  389. }
  390. // ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
  391. type ErrDeployKeyAlreadyExist struct {
  392. KeyID int64
  393. RepoID int64
  394. }
  395. // IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.
  396. func IsErrDeployKeyAlreadyExist(err error) bool {
  397. _, ok := err.(ErrDeployKeyAlreadyExist)
  398. return ok
  399. }
  400. func (err ErrDeployKeyAlreadyExist) Error() string {
  401. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  402. }
  403. // ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
  404. type ErrDeployKeyNameAlreadyUsed struct {
  405. RepoID int64
  406. Name string
  407. }
  408. // IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.
  409. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  410. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  411. return ok
  412. }
  413. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  414. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  415. }
  416. // _____ ___________ __
  417. // / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____
  418. // / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \
  419. // / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \
  420. // \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| /
  421. // \/ \/ \/ \/ \/ \/ \/ \/ \/
  422. // ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.
  423. type ErrAccessTokenNotExist struct {
  424. Token string
  425. }
  426. // IsErrAccessTokenNotExist checks if an error is a ErrAccessTokenNotExist.
  427. func IsErrAccessTokenNotExist(err error) bool {
  428. _, ok := err.(ErrAccessTokenNotExist)
  429. return ok
  430. }
  431. func (err ErrAccessTokenNotExist) Error() string {
  432. return fmt.Sprintf("access token does not exist [sha: %s]", err.Token)
  433. }
  434. // ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
  435. type ErrAccessTokenEmpty struct {
  436. }
  437. // IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
  438. func IsErrAccessTokenEmpty(err error) bool {
  439. _, ok := err.(ErrAccessTokenEmpty)
  440. return ok
  441. }
  442. func (err ErrAccessTokenEmpty) Error() string {
  443. return fmt.Sprintf("access token is empty")
  444. }
  445. // ________ .__ __ .__
  446. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  447. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  448. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  449. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  450. // \/ /_____/ \/ \/ \/ \/ \/
  451. // ErrOrgNotExist represents a "OrgNotExist" kind of error.
  452. type ErrOrgNotExist struct {
  453. ID int64
  454. Name string
  455. }
  456. // IsErrOrgNotExist checks if an error is a ErrOrgNotExist.
  457. func IsErrOrgNotExist(err error) bool {
  458. _, ok := err.(ErrOrgNotExist)
  459. return ok
  460. }
  461. func (err ErrOrgNotExist) Error() string {
  462. return fmt.Sprintf("org does not exist [id: %d, name: %s]", err.ID, err.Name)
  463. }
  464. // ErrLastOrgOwner represents a "LastOrgOwner" kind of error.
  465. type ErrLastOrgOwner struct {
  466. UID int64
  467. }
  468. // IsErrLastOrgOwner checks if an error is a ErrLastOrgOwner.
  469. func IsErrLastOrgOwner(err error) bool {
  470. _, ok := err.(ErrLastOrgOwner)
  471. return ok
  472. }
  473. func (err ErrLastOrgOwner) Error() string {
  474. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  475. }
  476. //.____ ____________________
  477. //| | \_ _____/ _____/
  478. //| | | __) \_____ \
  479. //| |___| \ / \
  480. //|_______ \___ / /_______ /
  481. // \/ \/ \/
  482. // ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error.
  483. type ErrLFSLockNotExist struct {
  484. ID int64
  485. RepoID int64
  486. Path string
  487. }
  488. // IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist.
  489. func IsErrLFSLockNotExist(err error) bool {
  490. _, ok := err.(ErrLFSLockNotExist)
  491. return ok
  492. }
  493. func (err ErrLFSLockNotExist) Error() string {
  494. return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path)
  495. }
  496. // ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error.
  497. type ErrLFSUnauthorizedAction struct {
  498. RepoID int64
  499. UserName string
  500. Mode AccessMode
  501. }
  502. // IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction.
  503. func IsErrLFSUnauthorizedAction(err error) bool {
  504. _, ok := err.(ErrLFSUnauthorizedAction)
  505. return ok
  506. }
  507. func (err ErrLFSUnauthorizedAction) Error() string {
  508. if err.Mode == AccessModeWrite {
  509. return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID)
  510. }
  511. return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID)
  512. }
  513. // ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error.
  514. type ErrLFSLockAlreadyExist struct {
  515. RepoID int64
  516. Path string
  517. }
  518. // IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist.
  519. func IsErrLFSLockAlreadyExist(err error) bool {
  520. _, ok := err.(ErrLFSLockAlreadyExist)
  521. return ok
  522. }
  523. func (err ErrLFSLockAlreadyExist) Error() string {
  524. return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path)
  525. }
  526. // __________ .__ __
  527. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  528. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  529. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  530. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  531. // \/ \/|__| \/ \/
  532. // ErrRepoNotExist represents a "RepoNotExist" kind of error.
  533. type ErrRepoNotExist struct {
  534. ID int64
  535. UID int64
  536. OwnerName string
  537. Name string
  538. }
  539. // IsErrRepoNotExist checks if an error is a ErrRepoNotExist.
  540. func IsErrRepoNotExist(err error) bool {
  541. _, ok := err.(ErrRepoNotExist)
  542. return ok
  543. }
  544. func (err ErrRepoNotExist) Error() string {
  545. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, owner_name: %s, name: %s]",
  546. err.ID, err.UID, err.OwnerName, err.Name)
  547. }
  548. // ErrRepoAlreadyExist represents a "RepoAlreadyExist" kind of error.
  549. type ErrRepoAlreadyExist struct {
  550. Uname string
  551. Name string
  552. }
  553. // IsErrRepoAlreadyExist checks if an error is a ErrRepoAlreadyExist.
  554. func IsErrRepoAlreadyExist(err error) bool {
  555. _, ok := err.(ErrRepoAlreadyExist)
  556. return ok
  557. }
  558. func (err ErrRepoAlreadyExist) Error() string {
  559. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  560. }
  561. // ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error.
  562. type ErrForkAlreadyExist struct {
  563. Uname string
  564. RepoName string
  565. ForkName string
  566. }
  567. // IsErrForkAlreadyExist checks if an error is an ErrForkAlreadyExist.
  568. func IsErrForkAlreadyExist(err error) bool {
  569. _, ok := err.(ErrForkAlreadyExist)
  570. return ok
  571. }
  572. func (err ErrForkAlreadyExist) Error() string {
  573. return fmt.Sprintf("repository is already forked by user [uname: %s, repo path: %s, fork path: %s]", err.Uname, err.RepoName, err.ForkName)
  574. }
  575. // ErrRepoRedirectNotExist represents a "RepoRedirectNotExist" kind of error.
  576. type ErrRepoRedirectNotExist struct {
  577. OwnerID int64
  578. RepoName string
  579. }
  580. // IsErrRepoRedirectNotExist check if an error is an ErrRepoRedirectNotExist.
  581. func IsErrRepoRedirectNotExist(err error) bool {
  582. _, ok := err.(ErrRepoRedirectNotExist)
  583. return ok
  584. }
  585. func (err ErrRepoRedirectNotExist) Error() string {
  586. return fmt.Sprintf("repository redirect does not exist [uid: %d, name: %s]", err.OwnerID, err.RepoName)
  587. }
  588. // ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error.
  589. type ErrInvalidCloneAddr struct {
  590. IsURLError bool
  591. IsInvalidPath bool
  592. IsPermissionDenied bool
  593. }
  594. // IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
  595. func IsErrInvalidCloneAddr(err error) bool {
  596. _, ok := err.(ErrInvalidCloneAddr)
  597. return ok
  598. }
  599. func (err ErrInvalidCloneAddr) Error() string {
  600. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  601. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  602. }
  603. // ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error.
  604. type ErrUpdateTaskNotExist struct {
  605. UUID string
  606. }
  607. // IsErrUpdateTaskNotExist checks if an error is a ErrUpdateTaskNotExist.
  608. func IsErrUpdateTaskNotExist(err error) bool {
  609. _, ok := err.(ErrUpdateTaskNotExist)
  610. return ok
  611. }
  612. func (err ErrUpdateTaskNotExist) Error() string {
  613. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  614. }
  615. // ErrReleaseAlreadyExist represents a "ReleaseAlreadyExist" kind of error.
  616. type ErrReleaseAlreadyExist struct {
  617. TagName string
  618. }
  619. // IsErrReleaseAlreadyExist checks if an error is a ErrReleaseAlreadyExist.
  620. func IsErrReleaseAlreadyExist(err error) bool {
  621. _, ok := err.(ErrReleaseAlreadyExist)
  622. return ok
  623. }
  624. func (err ErrReleaseAlreadyExist) Error() string {
  625. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  626. }
  627. // ErrReleaseNotExist represents a "ReleaseNotExist" kind of error.
  628. type ErrReleaseNotExist struct {
  629. ID int64
  630. TagName string
  631. }
  632. // IsErrReleaseNotExist checks if an error is a ErrReleaseNotExist.
  633. func IsErrReleaseNotExist(err error) bool {
  634. _, ok := err.(ErrReleaseNotExist)
  635. return ok
  636. }
  637. func (err ErrReleaseNotExist) Error() string {
  638. return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
  639. }
  640. // ErrInvalidTagName represents a "InvalidTagName" kind of error.
  641. type ErrInvalidTagName struct {
  642. TagName string
  643. }
  644. // IsErrInvalidTagName checks if an error is a ErrInvalidTagName.
  645. func IsErrInvalidTagName(err error) bool {
  646. _, ok := err.(ErrInvalidTagName)
  647. return ok
  648. }
  649. func (err ErrInvalidTagName) Error() string {
  650. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  651. }
  652. // ErrRepoFileAlreadyExists represents a "RepoFileAlreadyExist" kind of error.
  653. type ErrRepoFileAlreadyExists struct {
  654. Path string
  655. }
  656. // IsErrRepoFileAlreadyExists checks if an error is a ErrRepoFileAlreadyExists.
  657. func IsErrRepoFileAlreadyExists(err error) bool {
  658. _, ok := err.(ErrRepoFileAlreadyExists)
  659. return ok
  660. }
  661. func (err ErrRepoFileAlreadyExists) Error() string {
  662. return fmt.Sprintf("repository file already exists [path: %s]", err.Path)
  663. }
  664. // ErrRepoFileDoesNotExist represents a "RepoFileDoesNotExist" kind of error.
  665. type ErrRepoFileDoesNotExist struct {
  666. Path string
  667. Name string
  668. }
  669. // IsErrRepoFileDoesNotExist checks if an error is a ErrRepoDoesNotExist.
  670. func IsErrRepoFileDoesNotExist(err error) bool {
  671. _, ok := err.(ErrRepoFileDoesNotExist)
  672. return ok
  673. }
  674. func (err ErrRepoFileDoesNotExist) Error() string {
  675. return fmt.Sprintf("repository file does not exist [path: %s]", err.Path)
  676. }
  677. // ErrFilenameInvalid represents a "FilenameInvalid" kind of error.
  678. type ErrFilenameInvalid struct {
  679. Path string
  680. }
  681. // IsErrFilenameInvalid checks if an error is an ErrFilenameInvalid.
  682. func IsErrFilenameInvalid(err error) bool {
  683. _, ok := err.(ErrFilenameInvalid)
  684. return ok
  685. }
  686. func (err ErrFilenameInvalid) Error() string {
  687. return fmt.Sprintf("path contains a malformed path component [path: %s]", err.Path)
  688. }
  689. // ErrUserCannotCommit represents "UserCannotCommit" kind of error.
  690. type ErrUserCannotCommit struct {
  691. UserName string
  692. }
  693. // IsErrUserCannotCommit checks if an error is an ErrUserCannotCommit.
  694. func IsErrUserCannotCommit(err error) bool {
  695. _, ok := err.(ErrUserCannotCommit)
  696. return ok
  697. }
  698. func (err ErrUserCannotCommit) Error() string {
  699. return fmt.Sprintf("user cannot commit to repo [user: %s]", err.UserName)
  700. }
  701. // ErrFilePathInvalid represents a "FilePathInvalid" kind of error.
  702. type ErrFilePathInvalid struct {
  703. Message string
  704. Path string
  705. Name string
  706. Type git.EntryMode
  707. }
  708. // IsErrFilePathInvalid checks if an error is an ErrFilePathInvalid.
  709. func IsErrFilePathInvalid(err error) bool {
  710. _, ok := err.(ErrFilePathInvalid)
  711. return ok
  712. }
  713. func (err ErrFilePathInvalid) Error() string {
  714. if err.Message != "" {
  715. return err.Message
  716. }
  717. return fmt.Sprintf("path is invalid [path: %s]", err.Path)
  718. }
  719. // ErrUserDoesNotHaveAccessToRepo represets an error where the user doesn't has access to a given repo.
  720. type ErrUserDoesNotHaveAccessToRepo struct {
  721. UserID int64
  722. RepoName string
  723. }
  724. // IsErrUserDoesNotHaveAccessToRepo checks if an error is a ErrRepoFileAlreadyExists.
  725. func IsErrUserDoesNotHaveAccessToRepo(err error) bool {
  726. _, ok := err.(ErrUserDoesNotHaveAccessToRepo)
  727. return ok
  728. }
  729. func (err ErrUserDoesNotHaveAccessToRepo) Error() string {
  730. return fmt.Sprintf("user doesn't have acces to repo [user_id: %d, repo_name: %s]", err.UserID, err.RepoName)
  731. }
  732. // __________ .__
  733. // \______ \____________ ____ ____ | |__
  734. // | | _/\_ __ \__ \ / \_/ ___\| | \
  735. // | | \ | | \// __ \| | \ \___| Y \
  736. // |______ / |__| (____ /___| /\___ >___| /
  737. // \/ \/ \/ \/ \/
  738. // ErrBranchAlreadyExists represents an error that branch with such name already exists.
  739. type ErrBranchAlreadyExists struct {
  740. BranchName string
  741. }
  742. // IsErrBranchAlreadyExists checks if an error is an ErrBranchAlreadyExists.
  743. func IsErrBranchAlreadyExists(err error) bool {
  744. _, ok := err.(ErrBranchAlreadyExists)
  745. return ok
  746. }
  747. func (err ErrBranchAlreadyExists) Error() string {
  748. return fmt.Sprintf("branch already exists [name: %s]", err.BranchName)
  749. }
  750. // ErrBranchNameConflict represents an error that branch name conflicts with other branch.
  751. type ErrBranchNameConflict struct {
  752. BranchName string
  753. }
  754. // IsErrBranchNameConflict checks if an error is an ErrBranchNameConflict.
  755. func IsErrBranchNameConflict(err error) bool {
  756. _, ok := err.(ErrBranchNameConflict)
  757. return ok
  758. }
  759. func (err ErrBranchNameConflict) Error() string {
  760. return fmt.Sprintf("branch conflicts with existing branch [name: %s]", err.BranchName)
  761. }
  762. // ErrNotAllowedToMerge represents an error that a branch is protected and the current user is not allowed to modify it.
  763. type ErrNotAllowedToMerge struct {
  764. Reason string
  765. }
  766. // IsErrNotAllowedToMerge checks if an error is an ErrNotAllowedToMerge.
  767. func IsErrNotAllowedToMerge(err error) bool {
  768. _, ok := err.(ErrNotAllowedToMerge)
  769. return ok
  770. }
  771. func (err ErrNotAllowedToMerge) Error() string {
  772. return fmt.Sprintf("not allowed to merge [reason: %s]", err.Reason)
  773. }
  774. // ErrTagAlreadyExists represents an error that tag with such name already exists.
  775. type ErrTagAlreadyExists struct {
  776. TagName string
  777. }
  778. // IsErrTagAlreadyExists checks if an error is an ErrTagAlreadyExists.
  779. func IsErrTagAlreadyExists(err error) bool {
  780. _, ok := err.(ErrTagAlreadyExists)
  781. return ok
  782. }
  783. func (err ErrTagAlreadyExists) Error() string {
  784. return fmt.Sprintf("tag already exists [name: %s]", err.TagName)
  785. }
  786. // ErrSHADoesNotMatch represents a "SHADoesNotMatch" kind of error.
  787. type ErrSHADoesNotMatch struct {
  788. Path string
  789. GivenSHA string
  790. CurrentSHA string
  791. }
  792. // IsErrSHADoesNotMatch checks if an error is a ErrSHADoesNotMatch.
  793. func IsErrSHADoesNotMatch(err error) bool {
  794. _, ok := err.(ErrSHADoesNotMatch)
  795. return ok
  796. }
  797. func (err ErrSHADoesNotMatch) Error() string {
  798. return fmt.Sprintf("sha does not match [given: %s, expected: %s]", err.GivenSHA, err.CurrentSHA)
  799. }
  800. // ErrSHANotFound represents a "SHADoesNotMatch" kind of error.
  801. type ErrSHANotFound struct {
  802. SHA string
  803. }
  804. // IsErrSHANotFound checks if an error is a ErrSHANotFound.
  805. func IsErrSHANotFound(err error) bool {
  806. _, ok := err.(ErrSHANotFound)
  807. return ok
  808. }
  809. func (err ErrSHANotFound) Error() string {
  810. return fmt.Sprintf("sha not found [%s]", err.SHA)
  811. }
  812. // ErrCommitIDDoesNotMatch represents a "CommitIDDoesNotMatch" kind of error.
  813. type ErrCommitIDDoesNotMatch struct {
  814. GivenCommitID string
  815. CurrentCommitID string
  816. }
  817. // IsErrCommitIDDoesNotMatch checks if an error is a ErrCommitIDDoesNotMatch.
  818. func IsErrCommitIDDoesNotMatch(err error) bool {
  819. _, ok := err.(ErrCommitIDDoesNotMatch)
  820. return ok
  821. }
  822. func (err ErrCommitIDDoesNotMatch) Error() string {
  823. return fmt.Sprintf("file CommitID does not match [given: %s, expected: %s]", err.GivenCommitID, err.CurrentCommitID)
  824. }
  825. // ErrSHAOrCommitIDNotProvided represents a "SHAOrCommitIDNotProvided" kind of error.
  826. type ErrSHAOrCommitIDNotProvided struct{}
  827. // IsErrSHAOrCommitIDNotProvided checks if an error is a ErrSHAOrCommitIDNotProvided.
  828. func IsErrSHAOrCommitIDNotProvided(err error) bool {
  829. _, ok := err.(ErrSHAOrCommitIDNotProvided)
  830. return ok
  831. }
  832. func (err ErrSHAOrCommitIDNotProvided) Error() string {
  833. return fmt.Sprintf("a SHA or commmit ID must be proved when updating a file")
  834. }
  835. // __ __ ___. .__ __
  836. // / \ / \ ____\_ |__ | |__ ____ ____ | | __
  837. // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
  838. // \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
  839. // \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
  840. // \/ \/ \/ \/ \/
  841. // ErrWebhookNotExist represents a "WebhookNotExist" kind of error.
  842. type ErrWebhookNotExist struct {
  843. ID int64
  844. }
  845. // IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.
  846. func IsErrWebhookNotExist(err error) bool {
  847. _, ok := err.(ErrWebhookNotExist)
  848. return ok
  849. }
  850. func (err ErrWebhookNotExist) Error() string {
  851. return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
  852. }
  853. // .___
  854. // | | ______ ________ __ ____
  855. // | |/ ___// ___/ | \_/ __ \
  856. // | |\___ \ \___ \| | /\ ___/
  857. // |___/____ >____ >____/ \___ >
  858. // \/ \/ \/
  859. // ErrIssueNotExist represents a "IssueNotExist" kind of error.
  860. type ErrIssueNotExist struct {
  861. ID int64
  862. RepoID int64
  863. Index int64
  864. }
  865. // IsErrIssueNotExist checks if an error is a ErrIssueNotExist.
  866. func IsErrIssueNotExist(err error) bool {
  867. _, ok := err.(ErrIssueNotExist)
  868. return ok
  869. }
  870. func (err ErrIssueNotExist) Error() string {
  871. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  872. }
  873. // ErrIssueLabelTemplateLoad represents a "ErrIssueLabelTemplateLoad" kind of error.
  874. type ErrIssueLabelTemplateLoad struct {
  875. TemplateFile string
  876. OriginalError error
  877. }
  878. // IsErrIssueLabelTemplateLoad checks if an error is a ErrIssueLabelTemplateLoad.
  879. func IsErrIssueLabelTemplateLoad(err error) bool {
  880. _, ok := err.(ErrIssueLabelTemplateLoad)
  881. return ok
  882. }
  883. func (err ErrIssueLabelTemplateLoad) Error() string {
  884. return fmt.Sprintf("Failed to load label template file '%s': %v", err.TemplateFile, err.OriginalError)
  885. }
  886. // ErrNewIssueInsert is used when the INSERT statement in newIssue fails
  887. type ErrNewIssueInsert struct {
  888. OriginalError error
  889. }
  890. // IsErrNewIssueInsert checks if an error is a ErrNewIssueInsert.
  891. func IsErrNewIssueInsert(err error) bool {
  892. _, ok := err.(ErrNewIssueInsert)
  893. return ok
  894. }
  895. func (err ErrNewIssueInsert) Error() string {
  896. return err.OriginalError.Error()
  897. }
  898. // __________ .__ .__ __________ __
  899. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  900. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  901. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  902. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  903. // \/ \/ |__| \/ \/
  904. // ErrPullRequestNotExist represents a "PullRequestNotExist" kind of error.
  905. type ErrPullRequestNotExist struct {
  906. ID int64
  907. IssueID int64
  908. HeadRepoID int64
  909. BaseRepoID int64
  910. HeadBranch string
  911. BaseBranch string
  912. }
  913. // IsErrPullRequestNotExist checks if an error is a ErrPullRequestNotExist.
  914. func IsErrPullRequestNotExist(err error) bool {
  915. _, ok := err.(ErrPullRequestNotExist)
  916. return ok
  917. }
  918. func (err ErrPullRequestNotExist) Error() string {
  919. 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]",
  920. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  921. }
  922. // ErrPullRequestAlreadyExists represents a "PullRequestAlreadyExists"-error
  923. type ErrPullRequestAlreadyExists struct {
  924. ID int64
  925. IssueID int64
  926. HeadRepoID int64
  927. BaseRepoID int64
  928. HeadBranch string
  929. BaseBranch string
  930. }
  931. // IsErrPullRequestAlreadyExists checks if an error is a ErrPullRequestAlreadyExists.
  932. func IsErrPullRequestAlreadyExists(err error) bool {
  933. _, ok := err.(ErrPullRequestAlreadyExists)
  934. return ok
  935. }
  936. // Error does pretty-printing :D
  937. func (err ErrPullRequestAlreadyExists) Error() string {
  938. 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]",
  939. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  940. }
  941. // ErrPullRequestHeadRepoMissing represents a "ErrPullRequestHeadRepoMissing" error
  942. type ErrPullRequestHeadRepoMissing struct {
  943. ID int64
  944. HeadRepoID int64
  945. }
  946. // IsErrErrPullRequestHeadRepoMissing checks if an error is a ErrPullRequestHeadRepoMissing.
  947. func IsErrErrPullRequestHeadRepoMissing(err error) bool {
  948. _, ok := err.(ErrPullRequestHeadRepoMissing)
  949. return ok
  950. }
  951. // Error does pretty-printing :D
  952. func (err ErrPullRequestHeadRepoMissing) Error() string {
  953. return fmt.Sprintf("pull request head repo missing [id: %d, head_repo_id: %d]",
  954. err.ID, err.HeadRepoID)
  955. }
  956. // ErrInvalidMergeStyle represents an error if merging with disabled merge strategy
  957. type ErrInvalidMergeStyle struct {
  958. ID int64
  959. Style MergeStyle
  960. }
  961. // IsErrInvalidMergeStyle checks if an error is a ErrInvalidMergeStyle.
  962. func IsErrInvalidMergeStyle(err error) bool {
  963. _, ok := err.(ErrInvalidMergeStyle)
  964. return ok
  965. }
  966. func (err ErrInvalidMergeStyle) Error() string {
  967. return fmt.Sprintf("merge strategy is not allowed or is invalid [repo_id: %d, strategy: %s]",
  968. err.ID, err.Style)
  969. }
  970. // _________ __
  971. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  972. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  973. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  974. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  975. // \/ \/ \/ \/ \/
  976. // ErrCommentNotExist represents a "CommentNotExist" kind of error.
  977. type ErrCommentNotExist struct {
  978. ID int64
  979. IssueID int64
  980. }
  981. // IsErrCommentNotExist checks if an error is a ErrCommentNotExist.
  982. func IsErrCommentNotExist(err error) bool {
  983. _, ok := err.(ErrCommentNotExist)
  984. return ok
  985. }
  986. func (err ErrCommentNotExist) Error() string {
  987. return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
  988. }
  989. // _________ __ __ .__
  990. // / _____// |_ ____ ________ _ _______ _/ |_ ____ | |__
  991. // \_____ \\ __\/ _ \\____ \ \/ \/ /\__ \\ __\/ ___\| | \
  992. // / \| | ( <_> ) |_> > / / __ \| | \ \___| Y \
  993. // /_______ /|__| \____/| __/ \/\_/ (____ /__| \___ >___| /
  994. // \/ |__| \/ \/ \/
  995. // ErrStopwatchNotExist represents a "Stopwatch Not Exist" kind of error.
  996. type ErrStopwatchNotExist struct {
  997. ID int64
  998. }
  999. // IsErrStopwatchNotExist checks if an error is a ErrStopwatchNotExist.
  1000. func IsErrStopwatchNotExist(err error) bool {
  1001. _, ok := err.(ErrStopwatchNotExist)
  1002. return ok
  1003. }
  1004. func (err ErrStopwatchNotExist) Error() string {
  1005. return fmt.Sprintf("stopwatch does not exist [id: %d]", err.ID)
  1006. }
  1007. // ___________ __ .______________.__
  1008. // \__ ___/___________ ____ | | __ ____ __| _/\__ ___/|__| _____ ____
  1009. // | | \_ __ \__ \ _/ ___\| |/ // __ \ / __ | | | | |/ \_/ __ \
  1010. // | | | | \// __ \\ \___| <\ ___// /_/ | | | | | Y Y \ ___/
  1011. // |____| |__| (____ /\___ >__|_ \\___ >____ | |____| |__|__|_| /\___ >
  1012. // \/ \/ \/ \/ \/ \/ \/
  1013. // ErrTrackedTimeNotExist represents a "TrackedTime Not Exist" kind of error.
  1014. type ErrTrackedTimeNotExist struct {
  1015. ID int64
  1016. }
  1017. // IsErrTrackedTimeNotExist checks if an error is a ErrTrackedTimeNotExist.
  1018. func IsErrTrackedTimeNotExist(err error) bool {
  1019. _, ok := err.(ErrTrackedTimeNotExist)
  1020. return ok
  1021. }
  1022. func (err ErrTrackedTimeNotExist) Error() string {
  1023. return fmt.Sprintf("tracked time does not exist [id: %d]", err.ID)
  1024. }
  1025. // .____ ___. .__
  1026. // | | _____ \_ |__ ____ | |
  1027. // | | \__ \ | __ \_/ __ \| |
  1028. // | |___ / __ \| \_\ \ ___/| |__
  1029. // |_______ (____ /___ /\___ >____/
  1030. // \/ \/ \/ \/
  1031. // ErrLabelNotExist represents a "LabelNotExist" kind of error.
  1032. type ErrLabelNotExist struct {
  1033. LabelID int64
  1034. RepoID int64
  1035. }
  1036. // IsErrLabelNotExist checks if an error is a ErrLabelNotExist.
  1037. func IsErrLabelNotExist(err error) bool {
  1038. _, ok := err.(ErrLabelNotExist)
  1039. return ok
  1040. }
  1041. func (err ErrLabelNotExist) Error() string {
  1042. return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
  1043. }
  1044. // _____ .__.__ __
  1045. // / \ |__| | ____ _______/ |_ ____ ____ ____
  1046. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  1047. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  1048. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  1049. // \/ \/ \/ \/ \/
  1050. // ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
  1051. type ErrMilestoneNotExist struct {
  1052. ID int64
  1053. RepoID int64
  1054. }
  1055. // IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
  1056. func IsErrMilestoneNotExist(err error) bool {
  1057. _, ok := err.(ErrMilestoneNotExist)
  1058. return ok
  1059. }
  1060. func (err ErrMilestoneNotExist) Error() string {
  1061. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  1062. }
  1063. // _____ __ __ .__ __
  1064. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  1065. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  1066. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  1067. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  1068. // \/ \/ \/ \/ \/ \/ \/
  1069. // ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
  1070. type ErrAttachmentNotExist struct {
  1071. ID int64
  1072. UUID string
  1073. }
  1074. // IsErrAttachmentNotExist checks if an error is a ErrAttachmentNotExist.
  1075. func IsErrAttachmentNotExist(err error) bool {
  1076. _, ok := err.(ErrAttachmentNotExist)
  1077. return ok
  1078. }
  1079. func (err ErrAttachmentNotExist) Error() string {
  1080. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  1081. }
  1082. // .____ .__ _________
  1083. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  1084. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  1085. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  1086. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  1087. // \/ /_____/ \/ \/ \/ \/
  1088. // ErrLoginSourceNotExist represents a "LoginSourceNotExist" kind of error.
  1089. type ErrLoginSourceNotExist struct {
  1090. ID int64
  1091. }
  1092. // IsErrLoginSourceNotExist checks if an error is a ErrLoginSourceNotExist.
  1093. func IsErrLoginSourceNotExist(err error) bool {
  1094. _, ok := err.(ErrLoginSourceNotExist)
  1095. return ok
  1096. }
  1097. func (err ErrLoginSourceNotExist) Error() string {
  1098. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  1099. }
  1100. // ErrLoginSourceAlreadyExist represents a "LoginSourceAlreadyExist" kind of error.
  1101. type ErrLoginSourceAlreadyExist struct {
  1102. Name string
  1103. }
  1104. // IsErrLoginSourceAlreadyExist checks if an error is a ErrLoginSourceAlreadyExist.
  1105. func IsErrLoginSourceAlreadyExist(err error) bool {
  1106. _, ok := err.(ErrLoginSourceAlreadyExist)
  1107. return ok
  1108. }
  1109. func (err ErrLoginSourceAlreadyExist) Error() string {
  1110. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  1111. }
  1112. // ErrLoginSourceInUse represents a "LoginSourceInUse" kind of error.
  1113. type ErrLoginSourceInUse struct {
  1114. ID int64
  1115. }
  1116. // IsErrLoginSourceInUse checks if an error is a ErrLoginSourceInUse.
  1117. func IsErrLoginSourceInUse(err error) bool {
  1118. _, ok := err.(ErrLoginSourceInUse)
  1119. return ok
  1120. }
  1121. func (err ErrLoginSourceInUse) Error() string {
  1122. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  1123. }
  1124. // ___________
  1125. // \__ ___/___ _____ _____
  1126. // | |_/ __ \\__ \ / \
  1127. // | |\ ___/ / __ \| Y Y \
  1128. // |____| \___ >____ /__|_| /
  1129. // \/ \/ \/
  1130. // ErrTeamAlreadyExist represents a "TeamAlreadyExist" kind of error.
  1131. type ErrTeamAlreadyExist struct {
  1132. OrgID int64
  1133. Name string
  1134. }
  1135. // IsErrTeamAlreadyExist checks if an error is a ErrTeamAlreadyExist.
  1136. func IsErrTeamAlreadyExist(err error) bool {
  1137. _, ok := err.(ErrTeamAlreadyExist)
  1138. return ok
  1139. }
  1140. func (err ErrTeamAlreadyExist) Error() string {
  1141. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  1142. }
  1143. // ErrTeamNotExist represents a "TeamNotExist" error
  1144. type ErrTeamNotExist struct {
  1145. OrgID int64
  1146. TeamID int64
  1147. Name string
  1148. }
  1149. // IsErrTeamNotExist checks if an error is a ErrTeamNotExist.
  1150. func IsErrTeamNotExist(err error) bool {
  1151. _, ok := err.(ErrTeamNotExist)
  1152. return ok
  1153. }
  1154. func (err ErrTeamNotExist) Error() string {
  1155. return fmt.Sprintf("team does not exist [org_id %d, team_id %d, name: %s]", err.OrgID, err.TeamID, err.Name)
  1156. }
  1157. //
  1158. // Two-factor authentication
  1159. //
  1160. // ErrTwoFactorNotEnrolled indicates that a user is not enrolled in two-factor authentication.
  1161. type ErrTwoFactorNotEnrolled struct {
  1162. UID int64
  1163. }
  1164. // IsErrTwoFactorNotEnrolled checks if an error is a ErrTwoFactorNotEnrolled.
  1165. func IsErrTwoFactorNotEnrolled(err error) bool {
  1166. _, ok := err.(ErrTwoFactorNotEnrolled)
  1167. return ok
  1168. }
  1169. func (err ErrTwoFactorNotEnrolled) Error() string {
  1170. return fmt.Sprintf("user not enrolled in 2FA [uid: %d]", err.UID)
  1171. }
  1172. // ____ ___ .__ .___
  1173. // | | \______ | | _________ __| _/
  1174. // | | /\____ \| | / _ \__ \ / __ |
  1175. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  1176. // |______/ | __/|____/\____(____ /\____ |
  1177. // |__| \/ \/
  1178. //
  1179. // ErrUploadNotExist represents a "UploadNotExist" kind of error.
  1180. type ErrUploadNotExist struct {
  1181. ID int64
  1182. UUID string
  1183. }
  1184. // IsErrUploadNotExist checks if an error is a ErrUploadNotExist.
  1185. func IsErrUploadNotExist(err error) bool {
  1186. _, ok := err.(ErrAttachmentNotExist)
  1187. return ok
  1188. }
  1189. func (err ErrUploadNotExist) Error() string {
  1190. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  1191. }
  1192. // ___________ __ .__ .____ .__ ____ ___
  1193. // \_ _____/__ ____/ |_ ___________ ____ _____ | | | | ____ ____ |__| ____ | | \______ ___________
  1194. // | __)_\ \/ /\ __\/ __ \_ __ \/ \\__ \ | | | | / _ \ / ___\| |/ \ | | / ___// __ \_ __ \
  1195. // | \> < | | \ ___/| | \/ | \/ __ \| |__ | |__( <_> ) /_/ > | | \ | | /\___ \\ ___/| | \/
  1196. // /_______ /__/\_ \ |__| \___ >__| |___| (____ /____/ |_______ \____/\___ /|__|___| / |______//____ >\___ >__|
  1197. // \/ \/ \/ \/ \/ \/ /_____/ \/ \/ \/
  1198. // ErrExternalLoginUserAlreadyExist represents a "ExternalLoginUserAlreadyExist" kind of error.
  1199. type ErrExternalLoginUserAlreadyExist struct {
  1200. ExternalID string
  1201. UserID int64
  1202. LoginSourceID int64
  1203. }
  1204. // IsErrExternalLoginUserAlreadyExist checks if an error is a ExternalLoginUserAlreadyExist.
  1205. func IsErrExternalLoginUserAlreadyExist(err error) bool {
  1206. _, ok := err.(ErrExternalLoginUserAlreadyExist)
  1207. return ok
  1208. }
  1209. func (err ErrExternalLoginUserAlreadyExist) Error() string {
  1210. return fmt.Sprintf("external login user already exists [externalID: %s, userID: %d, loginSourceID: %d]", err.ExternalID, err.UserID, err.LoginSourceID)
  1211. }
  1212. // ErrExternalLoginUserNotExist represents a "ExternalLoginUserNotExist" kind of error.
  1213. type ErrExternalLoginUserNotExist struct {
  1214. UserID int64
  1215. LoginSourceID int64
  1216. }
  1217. // IsErrExternalLoginUserNotExist checks if an error is a ExternalLoginUserNotExist.
  1218. func IsErrExternalLoginUserNotExist(err error) bool {
  1219. _, ok := err.(ErrExternalLoginUserNotExist)
  1220. return ok
  1221. }
  1222. func (err ErrExternalLoginUserNotExist) Error() string {
  1223. return fmt.Sprintf("external login user link does not exists [userID: %d, loginSourceID: %d]", err.UserID, err.LoginSourceID)
  1224. }
  1225. // ____ ________________________________ .__ __ __ .__
  1226. // | | \_____ \_ _____/\______ \ ____ ____ |__| _______/ |_____________ _/ |_|__| ____ ____
  1227. // | | // ____/| __) | _// __ \ / ___\| |/ ___/\ __\_ __ \__ \\ __\ |/ _ \ / \
  1228. // | | // \| \ | | \ ___// /_/ > |\___ \ | | | | \// __ \| | | ( <_> ) | \
  1229. // |______/ \_______ \___ / |____|_ /\___ >___ /|__/____ > |__| |__| (____ /__| |__|\____/|___| /
  1230. // \/ \/ \/ \/_____/ \/ \/ \/
  1231. // ErrU2FRegistrationNotExist represents a "ErrU2FRegistrationNotExist" kind of error.
  1232. type ErrU2FRegistrationNotExist struct {
  1233. ID int64
  1234. }
  1235. func (err ErrU2FRegistrationNotExist) Error() string {
  1236. return fmt.Sprintf("U2F registration does not exist [id: %d]", err.ID)
  1237. }
  1238. // IsErrU2FRegistrationNotExist checks if an error is a ErrU2FRegistrationNotExist.
  1239. func IsErrU2FRegistrationNotExist(err error) bool {
  1240. _, ok := err.(ErrU2FRegistrationNotExist)
  1241. return ok
  1242. }
  1243. // .___ ________ .___ .__
  1244. // | | ______ ________ __ ____ \______ \ ____ ______ ____ ____ __| _/____ ____ ____ |__| ____ ______
  1245. // | |/ ___// ___/ | \_/ __ \ | | \_/ __ \\____ \_/ __ \ / \ / __ |/ __ \ / \_/ ___\| |/ __ \ / ___/
  1246. // | |\___ \ \___ \| | /\ ___/ | ` \ ___/| |_> > ___/| | \/ /_/ \ ___/| | \ \___| \ ___/ \___ \
  1247. // |___/____ >____ >____/ \___ >_______ /\___ > __/ \___ >___| /\____ |\___ >___| /\___ >__|\___ >____ >
  1248. // \/ \/ \/ \/ \/|__| \/ \/ \/ \/ \/ \/ \/ \/
  1249. // ErrDependencyExists represents a "DependencyAlreadyExists" kind of error.
  1250. type ErrDependencyExists struct {
  1251. IssueID int64
  1252. DependencyID int64
  1253. }
  1254. // IsErrDependencyExists checks if an error is a ErrDependencyExists.
  1255. func IsErrDependencyExists(err error) bool {
  1256. _, ok := err.(ErrDependencyExists)
  1257. return ok
  1258. }
  1259. func (err ErrDependencyExists) Error() string {
  1260. return fmt.Sprintf("issue dependency does already exist [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1261. }
  1262. // ErrDependencyNotExists represents a "DependencyAlreadyExists" kind of error.
  1263. type ErrDependencyNotExists struct {
  1264. IssueID int64
  1265. DependencyID int64
  1266. }
  1267. // IsErrDependencyNotExists checks if an error is a ErrDependencyExists.
  1268. func IsErrDependencyNotExists(err error) bool {
  1269. _, ok := err.(ErrDependencyNotExists)
  1270. return ok
  1271. }
  1272. func (err ErrDependencyNotExists) Error() string {
  1273. return fmt.Sprintf("issue dependency does not exist [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1274. }
  1275. // ErrCircularDependency represents a "DependencyCircular" kind of error.
  1276. type ErrCircularDependency struct {
  1277. IssueID int64
  1278. DependencyID int64
  1279. }
  1280. // IsErrCircularDependency checks if an error is a ErrCircularDependency.
  1281. func IsErrCircularDependency(err error) bool {
  1282. _, ok := err.(ErrCircularDependency)
  1283. return ok
  1284. }
  1285. func (err ErrCircularDependency) Error() string {
  1286. return fmt.Sprintf("circular dependencies exists (two issues blocking each other) [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1287. }
  1288. // ErrDependenciesLeft represents an error where the issue you're trying to close still has dependencies left.
  1289. type ErrDependenciesLeft struct {
  1290. IssueID int64
  1291. }
  1292. // IsErrDependenciesLeft checks if an error is a ErrDependenciesLeft.
  1293. func IsErrDependenciesLeft(err error) bool {
  1294. _, ok := err.(ErrDependenciesLeft)
  1295. return ok
  1296. }
  1297. func (err ErrDependenciesLeft) Error() string {
  1298. return fmt.Sprintf("issue has open dependencies [issue id: %d]", err.IssueID)
  1299. }
  1300. // ErrUnknownDependencyType represents an error where an unknown dependency type was passed
  1301. type ErrUnknownDependencyType struct {
  1302. Type DependencyType
  1303. }
  1304. // IsErrUnknownDependencyType checks if an error is ErrUnknownDependencyType
  1305. func IsErrUnknownDependencyType(err error) bool {
  1306. _, ok := err.(ErrUnknownDependencyType)
  1307. return ok
  1308. }
  1309. func (err ErrUnknownDependencyType) Error() string {
  1310. return fmt.Sprintf("unknown dependency type [type: %d]", err.Type)
  1311. }
  1312. // __________ .__
  1313. // \______ \ _______ _|__| ______ _ __
  1314. // | _// __ \ \/ / |/ __ \ \/ \/ /
  1315. // | | \ ___/\ /| \ ___/\ /
  1316. // |____|_ /\___ >\_/ |__|\___ >\/\_/
  1317. // \/ \/ \/
  1318. // ErrReviewNotExist represents a "ReviewNotExist" kind of error.
  1319. type ErrReviewNotExist struct {
  1320. ID int64
  1321. }
  1322. // IsErrReviewNotExist checks if an error is a ErrReviewNotExist.
  1323. func IsErrReviewNotExist(err error) bool {
  1324. _, ok := err.(ErrReviewNotExist)
  1325. return ok
  1326. }
  1327. func (err ErrReviewNotExist) Error() string {
  1328. return fmt.Sprintf("review does not exist [id: %d]", err.ID)
  1329. }
  1330. // ________ _____ __ .__
  1331. // \_____ \ / _ \ __ ___/ |_| |__
  1332. // / | \ / /_\ \| | \ __\ | \
  1333. // / | \/ | \ | /| | | Y \
  1334. // \_______ /\____|__ /____/ |__| |___| /
  1335. // \/ \/ \/
  1336. // ErrOAuthClientIDInvalid will be thrown if client id cannot be found
  1337. type ErrOAuthClientIDInvalid struct {
  1338. ClientID string
  1339. }
  1340. // IsErrOauthClientIDInvalid checks if an error is a ErrReviewNotExist.
  1341. func IsErrOauthClientIDInvalid(err error) bool {
  1342. _, ok := err.(ErrOAuthClientIDInvalid)
  1343. return ok
  1344. }
  1345. // Error returns the error message
  1346. func (err ErrOAuthClientIDInvalid) Error() string {
  1347. return fmt.Sprintf("Client ID invalid [Client ID: %s]", err.ClientID)
  1348. }
  1349. // ErrOAuthApplicationNotFound will be thrown if id cannot be found
  1350. type ErrOAuthApplicationNotFound struct {
  1351. ID int64
  1352. }
  1353. // IsErrOAuthApplicationNotFound checks if an error is a ErrReviewNotExist.
  1354. func IsErrOAuthApplicationNotFound(err error) bool {
  1355. _, ok := err.(ErrOAuthApplicationNotFound)
  1356. return ok
  1357. }
  1358. // Error returns the error message
  1359. func (err ErrOAuthApplicationNotFound) Error() string {
  1360. return fmt.Sprintf("OAuth application not found [ID: %d]", err.ID)
  1361. }
上海开阖软件有限公司 沪ICP备12045867号-1