error.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  311. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  312. // \/ \/ |__| \/ \/
  313. type ErrPullRequestNotExist struct {
  314. ID int64
  315. IssueID int64
  316. HeadRepoID int64
  317. BaseRepoID int64
  318. HeadBarcnh string
  319. BaseBranch string
  320. }
  321. func IsErrPullRequestNotExist(err error) bool {
  322. _, ok := err.(ErrPullRequestNotExist)
  323. return ok
  324. }
  325. func (err ErrPullRequestNotExist) Error() string {
  326. 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]",
  327. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBarcnh, err.BaseBranch)
  328. }
  329. // _________ __
  330. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  331. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  332. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  333. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  334. // \/ \/ \/ \/ \/
  335. type ErrCommentNotExist struct {
  336. ID int64
  337. IssueID int64
  338. }
  339. func IsErrCommentNotExist(err error) bool {
  340. _, ok := err.(ErrCommentNotExist)
  341. return ok
  342. }
  343. func (err ErrCommentNotExist) Error() string {
  344. return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
  345. }
  346. // .____ ___. .__
  347. // | | _____ \_ |__ ____ | |
  348. // | | \__ \ | __ \_/ __ \| |
  349. // | |___ / __ \| \_\ \ ___/| |__
  350. // |_______ (____ /___ /\___ >____/
  351. // \/ \/ \/ \/
  352. type ErrLabelNotExist struct {
  353. LabelID int64
  354. RepoID int64
  355. }
  356. func IsErrLabelNotExist(err error) bool {
  357. _, ok := err.(ErrLabelNotExist)
  358. return ok
  359. }
  360. func (err ErrLabelNotExist) Error() string {
  361. return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
  362. }
  363. // _____ .__.__ __
  364. // / \ |__| | ____ _______/ |_ ____ ____ ____
  365. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  366. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  367. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  368. // \/ \/ \/ \/ \/
  369. type ErrMilestoneNotExist struct {
  370. ID int64
  371. RepoID int64
  372. }
  373. func IsErrMilestoneNotExist(err error) bool {
  374. _, ok := err.(ErrMilestoneNotExist)
  375. return ok
  376. }
  377. func (err ErrMilestoneNotExist) Error() string {
  378. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  379. }
  380. // _____ __ __ .__ __
  381. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  382. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  383. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  384. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  385. // \/ \/ \/ \/ \/ \/ \/
  386. type ErrAttachmentNotExist struct {
  387. ID int64
  388. UUID string
  389. }
  390. func IsErrAttachmentNotExist(err error) bool {
  391. _, ok := err.(ErrAttachmentNotExist)
  392. return ok
  393. }
  394. func (err ErrAttachmentNotExist) Error() string {
  395. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  396. }
  397. // .____ .__ _________
  398. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  399. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  400. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  401. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  402. // \/ /_____/ \/ \/ \/ \/
  403. type ErrLoginSourceNotExist struct {
  404. ID int64
  405. }
  406. func IsErrLoginSourceNotExist(err error) bool {
  407. _, ok := err.(ErrLoginSourceNotExist)
  408. return ok
  409. }
  410. func (err ErrLoginSourceNotExist) Error() string {
  411. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  412. }
  413. type ErrLoginSourceAlreadyExist struct {
  414. Name string
  415. }
  416. func IsErrLoginSourceAlreadyExist(err error) bool {
  417. _, ok := err.(ErrLoginSourceAlreadyExist)
  418. return ok
  419. }
  420. func (err ErrLoginSourceAlreadyExist) Error() string {
  421. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  422. }
  423. type ErrLoginSourceInUse struct {
  424. ID int64
  425. }
  426. func IsErrLoginSourceInUse(err error) bool {
  427. _, ok := err.(ErrLoginSourceInUse)
  428. return ok
  429. }
  430. func (err ErrLoginSourceInUse) Error() string {
  431. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  432. }
  433. // ___________
  434. // \__ ___/___ _____ _____
  435. // | |_/ __ \\__ \ / \
  436. // | |\ ___/ / __ \| Y Y \
  437. // |____| \___ >____ /__|_| /
  438. // \/ \/ \/
  439. type ErrTeamAlreadyExist struct {
  440. OrgID int64
  441. Name string
  442. }
  443. func IsErrTeamAlreadyExist(err error) bool {
  444. _, ok := err.(ErrTeamAlreadyExist)
  445. return ok
  446. }
  447. func (err ErrTeamAlreadyExist) Error() string {
  448. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  449. }
  450. // ____ ___ .__ .___
  451. // | | \______ | | _________ __| _/
  452. // | | /\____ \| | / _ \__ \ / __ |
  453. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  454. // |______/ | __/|____/\____(____ /\____ |
  455. // |__| \/ \/
  456. //
  457. type ErrUploadNotExist struct {
  458. ID int64
  459. UUID string
  460. }
  461. func IsErrUploadNotExist(err error) bool {
  462. _, ok := err.(ErrAttachmentNotExist)
  463. return ok
  464. }
  465. func (err ErrUploadNotExist) Error() string {
  466. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  467. }