error.go 15 KB

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