error.go 15 KB

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