error.go 16 KB

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