error.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. )
  8. type ErrNameReserved struct {
  9. Name string
  10. }
  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. type ErrNamePatternNotAllowed struct {
  19. Pattern string
  20. }
  21. func IsErrNamePatternNotAllowed(err error) bool {
  22. _, ok := err.(ErrNamePatternNotAllowed)
  23. return ok
  24. }
  25. func (err ErrNamePatternNotAllowed) Error() string {
  26. return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
  27. }
  28. // ____ ___
  29. // | | \______ ___________
  30. // | | / ___// __ \_ __ \
  31. // | | /\___ \\ ___/| | \/
  32. // |______//____ >\___ >__|
  33. // \/ \/
  34. type ErrUserAlreadyExist struct {
  35. Name string
  36. }
  37. func IsErrUserAlreadyExist(err error) bool {
  38. _, ok := err.(ErrUserAlreadyExist)
  39. return ok
  40. }
  41. func (err ErrUserAlreadyExist) Error() string {
  42. return fmt.Sprintf("user already exists [name: %s]", err.Name)
  43. }
  44. type ErrEmailAlreadyUsed struct {
  45. Email string
  46. }
  47. func IsErrEmailAlreadyUsed(err error) bool {
  48. _, ok := err.(ErrEmailAlreadyUsed)
  49. return ok
  50. }
  51. func (err ErrEmailAlreadyUsed) Error() string {
  52. return fmt.Sprintf("e-mail has been used [email: %s]", err.Email)
  53. }
  54. type ErrUserOwnRepos struct {
  55. UID int64
  56. }
  57. func IsErrUserOwnRepos(err error) bool {
  58. _, ok := err.(ErrUserOwnRepos)
  59. return ok
  60. }
  61. func (err ErrUserOwnRepos) Error() string {
  62. return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
  63. }
  64. type ErrUserHasOrgs struct {
  65. UID int64
  66. }
  67. func IsErrUserHasOrgs(err error) bool {
  68. _, ok := err.(ErrUserHasOrgs)
  69. return ok
  70. }
  71. func (err ErrUserHasOrgs) Error() string {
  72. return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
  73. }
  74. type ErrReachLimitOfRepo struct {
  75. Limit int
  76. }
  77. func IsErrReachLimitOfRepo(err error) bool {
  78. _, ok := err.(ErrReachLimitOfRepo)
  79. return ok
  80. }
  81. func (err ErrReachLimitOfRepo) Error() string {
  82. return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
  83. }
  84. // __ __.__ __ .__
  85. // / \ / \__| | _|__|
  86. // \ \/\/ / | |/ / |
  87. // \ /| | <| |
  88. // \__/\ / |__|__|_ \__|
  89. // \/ \/
  90. type ErrWikiAlreadyExist struct {
  91. Title string
  92. }
  93. func IsErrWikiAlreadyExist(err error) bool {
  94. _, ok := err.(ErrWikiAlreadyExist)
  95. return ok
  96. }
  97. func (err ErrWikiAlreadyExist) Error() string {
  98. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  99. }
  100. // __________ ___. .__ .__ ____ __.
  101. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  102. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  103. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  104. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  105. // \/ \/ \/ \/\/
  106. type ErrKeyUnableVerify struct {
  107. Result string
  108. }
  109. func IsErrKeyUnableVerify(err error) bool {
  110. _, ok := err.(ErrKeyUnableVerify)
  111. return ok
  112. }
  113. func (err ErrKeyUnableVerify) Error() string {
  114. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  115. }
  116. type ErrKeyNotExist struct {
  117. ID int64
  118. }
  119. func IsErrKeyNotExist(err error) bool {
  120. _, ok := err.(ErrKeyNotExist)
  121. return ok
  122. }
  123. func (err ErrKeyNotExist) Error() string {
  124. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  125. }
  126. type ErrKeyAlreadyExist struct {
  127. OwnerID int64
  128. Content string
  129. }
  130. func IsErrKeyAlreadyExist(err error) bool {
  131. _, ok := err.(ErrKeyAlreadyExist)
  132. return ok
  133. }
  134. func (err ErrKeyAlreadyExist) Error() string {
  135. return fmt.Sprintf("public key already exists [owner_id: %d, content: %s]", err.OwnerID, err.Content)
  136. }
  137. type ErrKeyNameAlreadyUsed struct {
  138. OwnerID int64
  139. Name string
  140. }
  141. func IsErrKeyNameAlreadyUsed(err error) bool {
  142. _, ok := err.(ErrKeyNameAlreadyUsed)
  143. return ok
  144. }
  145. func (err ErrKeyNameAlreadyUsed) Error() string {
  146. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  147. }
  148. type ErrKeyAccessDenied struct {
  149. UserID int64
  150. KeyID int64
  151. Note string
  152. }
  153. func IsErrKeyAccessDenied(err error) bool {
  154. _, ok := err.(ErrKeyAccessDenied)
  155. return ok
  156. }
  157. func (err ErrKeyAccessDenied) Error() string {
  158. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  159. err.UserID, err.KeyID, err.Note)
  160. }
  161. type ErrDeployKeyNotExist struct {
  162. ID int64
  163. KeyID int64
  164. RepoID int64
  165. }
  166. func IsErrDeployKeyNotExist(err error) bool {
  167. _, ok := err.(ErrDeployKeyNotExist)
  168. return ok
  169. }
  170. func (err ErrDeployKeyNotExist) Error() string {
  171. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  172. }
  173. type ErrDeployKeyAlreadyExist struct {
  174. KeyID int64
  175. RepoID int64
  176. }
  177. func IsErrDeployKeyAlreadyExist(err error) bool {
  178. _, ok := err.(ErrDeployKeyAlreadyExist)
  179. return ok
  180. }
  181. func (err ErrDeployKeyAlreadyExist) Error() string {
  182. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  183. }
  184. type ErrDeployKeyNameAlreadyUsed struct {
  185. RepoID int64
  186. Name string
  187. }
  188. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  189. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  190. return ok
  191. }
  192. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  193. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  194. }
  195. // _____ ___________ __
  196. // / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____
  197. // / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \
  198. // / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \
  199. // \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| /
  200. // \/ \/ \/ \/ \/ \/ \/ \/ \/
  201. type ErrAccessTokenNotExist struct {
  202. SHA string
  203. }
  204. func IsErrAccessTokenNotExist(err error) bool {
  205. _, ok := err.(ErrAccessTokenNotExist)
  206. return ok
  207. }
  208. func (err ErrAccessTokenNotExist) Error() string {
  209. return fmt.Sprintf("access token does not exist [sha: %s]", err.SHA)
  210. }
  211. type ErrAccessTokenEmpty struct {
  212. }
  213. func IsErrAccessTokenEmpty(err error) bool {
  214. _, ok := err.(ErrAccessTokenEmpty)
  215. return ok
  216. }
  217. func (err ErrAccessTokenEmpty) Error() string {
  218. return fmt.Sprintf("access token is empty")
  219. }
  220. // ________ .__ __ .__
  221. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  222. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  223. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  224. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  225. // \/ /_____/ \/ \/ \/ \/ \/
  226. type ErrLastOrgOwner struct {
  227. UID int64
  228. }
  229. func IsErrLastOrgOwner(err error) bool {
  230. _, ok := err.(ErrLastOrgOwner)
  231. return ok
  232. }
  233. func (err ErrLastOrgOwner) Error() string {
  234. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  235. }
  236. // __________ .__ __
  237. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  238. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  239. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  240. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  241. // \/ \/|__| \/ \/
  242. type ErrRepoAlreadyExist struct {
  243. Uname string
  244. Name string
  245. }
  246. func IsErrRepoAlreadyExist(err error) bool {
  247. _, ok := err.(ErrRepoAlreadyExist)
  248. return ok
  249. }
  250. func (err ErrRepoAlreadyExist) Error() string {
  251. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  252. }
  253. type ErrInvalidCloneAddr struct {
  254. IsURLError bool
  255. IsInvalidPath bool
  256. IsPermissionDenied bool
  257. }
  258. func IsErrInvalidCloneAddr(err error) bool {
  259. _, ok := err.(ErrInvalidCloneAddr)
  260. return ok
  261. }
  262. func (err ErrInvalidCloneAddr) Error() string {
  263. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  264. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  265. }
  266. type ErrUpdateTaskNotExist struct {
  267. UUID string
  268. }
  269. func IsErrUpdateTaskNotExist(err error) bool {
  270. _, ok := err.(ErrUpdateTaskNotExist)
  271. return ok
  272. }
  273. func (err ErrUpdateTaskNotExist) Error() string {
  274. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  275. }
  276. type ErrReleaseAlreadyExist struct {
  277. TagName string
  278. }
  279. func IsErrReleaseAlreadyExist(err error) bool {
  280. _, ok := err.(ErrReleaseAlreadyExist)
  281. return ok
  282. }
  283. func (err ErrReleaseAlreadyExist) Error() string {
  284. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  285. }
  286. type ErrReleaseNotExist struct {
  287. ID int64
  288. TagName string
  289. }
  290. func IsErrReleaseNotExist(err error) bool {
  291. _, ok := err.(ErrReleaseNotExist)
  292. return ok
  293. }
  294. func (err ErrReleaseNotExist) Error() string {
  295. return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
  296. }
  297. type ErrInvalidTagName struct {
  298. TagName string
  299. }
  300. func IsErrInvalidTagName(err error) bool {
  301. _, ok := err.(ErrInvalidTagName)
  302. return ok
  303. }
  304. func (err ErrInvalidTagName) Error() string {
  305. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  306. }
  307. type ErrRepoFileAlreadyExist struct {
  308. FileName string
  309. }
  310. func IsErrRepoFileAlreadyExist(err error) bool {
  311. _, ok := err.(ErrRepoFileAlreadyExist)
  312. return ok
  313. }
  314. func (err ErrRepoFileAlreadyExist) Error() string {
  315. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  316. }
  317. // __________ .__
  318. // \______ \____________ ____ ____ | |__
  319. // | | _/\_ __ \__ \ / \_/ ___\| | \
  320. // | | \ | | \// __ \| | \ \___| Y \
  321. // |______ / |__| (____ /___| /\___ >___| /
  322. // \/ \/ \/ \/ \/
  323. type ErrBranchNotExist struct {
  324. Name string
  325. }
  326. func IsErrBranchNotExist(err error) bool {
  327. _, ok := err.(ErrBranchNotExist)
  328. return ok
  329. }
  330. func (err ErrBranchNotExist) Error() string {
  331. return fmt.Sprintf("branch does not exist [name: %s]", err.Name)
  332. }
  333. // __________ .__ .__ __________ __
  334. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  335. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  336. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  337. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  338. // \/ \/ |__| \/ \/
  339. type ErrPullRequestNotExist struct {
  340. ID int64
  341. IssueID int64
  342. HeadRepoID int64
  343. BaseRepoID int64
  344. HeadBarcnh string
  345. BaseBranch string
  346. }
  347. func IsErrPullRequestNotExist(err error) bool {
  348. _, ok := err.(ErrPullRequestNotExist)
  349. return ok
  350. }
  351. func (err ErrPullRequestNotExist) Error() string {
  352. 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]",
  353. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBarcnh, err.BaseBranch)
  354. }
  355. // _________ __
  356. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  357. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  358. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  359. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  360. // \/ \/ \/ \/ \/
  361. type ErrCommentNotExist struct {
  362. ID int64
  363. IssueID int64
  364. }
  365. func IsErrCommentNotExist(err error) bool {
  366. _, ok := err.(ErrCommentNotExist)
  367. return ok
  368. }
  369. func (err ErrCommentNotExist) Error() string {
  370. return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
  371. }
  372. // .____ ___. .__
  373. // | | _____ \_ |__ ____ | |
  374. // | | \__ \ | __ \_/ __ \| |
  375. // | |___ / __ \| \_\ \ ___/| |__
  376. // |_______ (____ /___ /\___ >____/
  377. // \/ \/ \/ \/
  378. type ErrLabelNotExist struct {
  379. LabelID int64
  380. RepoID int64
  381. }
  382. func IsErrLabelNotExist(err error) bool {
  383. _, ok := err.(ErrLabelNotExist)
  384. return ok
  385. }
  386. func (err ErrLabelNotExist) Error() string {
  387. return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
  388. }
  389. // _____ .__.__ __
  390. // / \ |__| | ____ _______/ |_ ____ ____ ____
  391. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  392. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  393. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  394. // \/ \/ \/ \/ \/
  395. type ErrMilestoneNotExist struct {
  396. ID int64
  397. RepoID int64
  398. }
  399. func IsErrMilestoneNotExist(err error) bool {
  400. _, ok := err.(ErrMilestoneNotExist)
  401. return ok
  402. }
  403. func (err ErrMilestoneNotExist) Error() string {
  404. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  405. }
  406. // _____ __ __ .__ __
  407. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  408. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  409. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  410. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  411. // \/ \/ \/ \/ \/ \/ \/
  412. type ErrAttachmentNotExist struct {
  413. ID int64
  414. UUID string
  415. }
  416. func IsErrAttachmentNotExist(err error) bool {
  417. _, ok := err.(ErrAttachmentNotExist)
  418. return ok
  419. }
  420. func (err ErrAttachmentNotExist) Error() string {
  421. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  422. }
  423. // .____ .__ _________
  424. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  425. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  426. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  427. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  428. // \/ /_____/ \/ \/ \/ \/
  429. type ErrLoginSourceNotExist struct {
  430. ID int64
  431. }
  432. func IsErrLoginSourceNotExist(err error) bool {
  433. _, ok := err.(ErrLoginSourceNotExist)
  434. return ok
  435. }
  436. func (err ErrLoginSourceNotExist) Error() string {
  437. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  438. }
  439. type ErrLoginSourceAlreadyExist struct {
  440. Name string
  441. }
  442. func IsErrLoginSourceAlreadyExist(err error) bool {
  443. _, ok := err.(ErrLoginSourceAlreadyExist)
  444. return ok
  445. }
  446. func (err ErrLoginSourceAlreadyExist) Error() string {
  447. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  448. }
  449. type ErrLoginSourceInUse struct {
  450. ID int64
  451. }
  452. func IsErrLoginSourceInUse(err error) bool {
  453. _, ok := err.(ErrLoginSourceInUse)
  454. return ok
  455. }
  456. func (err ErrLoginSourceInUse) Error() string {
  457. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  458. }
  459. // ___________
  460. // \__ ___/___ _____ _____
  461. // | |_/ __ \\__ \ / \
  462. // | |\ ___/ / __ \| Y Y \
  463. // |____| \___ >____ /__|_| /
  464. // \/ \/ \/
  465. type ErrTeamAlreadyExist struct {
  466. OrgID int64
  467. Name string
  468. }
  469. func IsErrTeamAlreadyExist(err error) bool {
  470. _, ok := err.(ErrTeamAlreadyExist)
  471. return ok
  472. }
  473. func (err ErrTeamAlreadyExist) Error() string {
  474. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  475. }
  476. // ____ ___ .__ .___
  477. // | | \______ | | _________ __| _/
  478. // | | /\____ \| | / _ \__ \ / __ |
  479. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  480. // |______/ | __/|____/\____(____ /\____ |
  481. // |__| \/ \/
  482. //
  483. type ErrUploadNotExist struct {
  484. ID int64
  485. UUID string
  486. }
  487. func IsErrUploadNotExist(err error) bool {
  488. _, ok := err.(ErrAttachmentNotExist)
  489. return ok
  490. }
  491. func (err ErrUploadNotExist) Error() string {
  492. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  493. }