You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error.go 49KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package models
  6. import (
  7. "fmt"
  8. "code.gitea.io/gitea/modules/git"
  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 ErrNamePatternNotAllowed.
  27. func IsErrNamePatternNotAllowed(err error) bool {
  28. _, ok := err.(ErrNamePatternNotAllowed)
  29. return ok
  30. }
  31. func (err ErrNamePatternNotAllowed) Error() string {
  32. return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
  33. }
  34. // ErrSSHDisabled represents an "SSH disabled" error.
  35. type ErrSSHDisabled struct {
  36. }
  37. // IsErrSSHDisabled checks if an error is a ErrSSHDisabled.
  38. func IsErrSSHDisabled(err error) bool {
  39. _, ok := err.(ErrSSHDisabled)
  40. return ok
  41. }
  42. func (err ErrSSHDisabled) Error() string {
  43. return "SSH is disabled"
  44. }
  45. // ____ ___
  46. // | | \______ ___________
  47. // | | / ___// __ \_ __ \
  48. // | | /\___ \\ ___/| | \/
  49. // |______//____ >\___ >__|
  50. // \/ \/
  51. // ErrUserAlreadyExist represents a "user already exists" error.
  52. type ErrUserAlreadyExist struct {
  53. Name string
  54. }
  55. // IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.
  56. func IsErrUserAlreadyExist(err error) bool {
  57. _, ok := err.(ErrUserAlreadyExist)
  58. return ok
  59. }
  60. func (err ErrUserAlreadyExist) Error() string {
  61. return fmt.Sprintf("user already exists [name: %s]", err.Name)
  62. }
  63. // ErrUserNotExist represents a "UserNotExist" kind of error.
  64. type ErrUserNotExist struct {
  65. UID int64
  66. Name string
  67. KeyID int64
  68. }
  69. // IsErrUserNotExist checks if an error is a ErrUserNotExist.
  70. func IsErrUserNotExist(err error) bool {
  71. _, ok := err.(ErrUserNotExist)
  72. return ok
  73. }
  74. func (err ErrUserNotExist) Error() string {
  75. return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID)
  76. }
  77. // ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
  78. type ErrUserProhibitLogin struct {
  79. UID int64
  80. Name string
  81. }
  82. // IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin
  83. func IsErrUserProhibitLogin(err error) bool {
  84. _, ok := err.(ErrUserProhibitLogin)
  85. return ok
  86. }
  87. func (err ErrUserProhibitLogin) Error() string {
  88. return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name)
  89. }
  90. // ErrUserInactive represents a "ErrUserInactive" kind of error.
  91. type ErrUserInactive struct {
  92. UID int64
  93. Name string
  94. }
  95. // IsErrUserInactive checks if an error is a ErrUserInactive
  96. func IsErrUserInactive(err error) bool {
  97. _, ok := err.(ErrUserInactive)
  98. return ok
  99. }
  100. func (err ErrUserInactive) Error() string {
  101. return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
  102. }
  103. // ErrEmailAlreadyUsed represents a "EmailAlreadyUsed" kind of error.
  104. type ErrEmailAlreadyUsed struct {
  105. Email string
  106. }
  107. // IsErrEmailAlreadyUsed checks if an error is a ErrEmailAlreadyUsed.
  108. func IsErrEmailAlreadyUsed(err error) bool {
  109. _, ok := err.(ErrEmailAlreadyUsed)
  110. return ok
  111. }
  112. func (err ErrEmailAlreadyUsed) Error() string {
  113. return fmt.Sprintf("e-mail already in use [email: %s]", err.Email)
  114. }
  115. // ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
  116. type ErrOpenIDAlreadyUsed struct {
  117. OpenID string
  118. }
  119. // IsErrOpenIDAlreadyUsed checks if an error is a ErrOpenIDAlreadyUsed.
  120. func IsErrOpenIDAlreadyUsed(err error) bool {
  121. _, ok := err.(ErrOpenIDAlreadyUsed)
  122. return ok
  123. }
  124. func (err ErrOpenIDAlreadyUsed) Error() string {
  125. return fmt.Sprintf("OpenID already in use [oid: %s]", err.OpenID)
  126. }
  127. // ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
  128. type ErrUserOwnRepos struct {
  129. UID int64
  130. }
  131. // IsErrUserOwnRepos checks if an error is a ErrUserOwnRepos.
  132. func IsErrUserOwnRepos(err error) bool {
  133. _, ok := err.(ErrUserOwnRepos)
  134. return ok
  135. }
  136. func (err ErrUserOwnRepos) Error() string {
  137. return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
  138. }
  139. // ErrUserHasOrgs represents a "UserHasOrgs" kind of error.
  140. type ErrUserHasOrgs struct {
  141. UID int64
  142. }
  143. // IsErrUserHasOrgs checks if an error is a ErrUserHasOrgs.
  144. func IsErrUserHasOrgs(err error) bool {
  145. _, ok := err.(ErrUserHasOrgs)
  146. return ok
  147. }
  148. func (err ErrUserHasOrgs) Error() string {
  149. return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
  150. }
  151. // ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error.
  152. type ErrUserNotAllowedCreateOrg struct {
  153. }
  154. // IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg.
  155. func IsErrUserNotAllowedCreateOrg(err error) bool {
  156. _, ok := err.(ErrUserNotAllowedCreateOrg)
  157. return ok
  158. }
  159. func (err ErrUserNotAllowedCreateOrg) Error() string {
  160. return fmt.Sprintf("user is not allowed to create organizations")
  161. }
  162. // ErrReachLimitOfRepo represents a "ReachLimitOfRepo" kind of error.
  163. type ErrReachLimitOfRepo struct {
  164. Limit int
  165. }
  166. // IsErrReachLimitOfRepo checks if an error is a ErrReachLimitOfRepo.
  167. func IsErrReachLimitOfRepo(err error) bool {
  168. _, ok := err.(ErrReachLimitOfRepo)
  169. return ok
  170. }
  171. func (err ErrReachLimitOfRepo) Error() string {
  172. return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
  173. }
  174. // __ __.__ __ .__
  175. // / \ / \__| | _|__|
  176. // \ \/\/ / | |/ / |
  177. // \ /| | <| |
  178. // \__/\ / |__|__|_ \__|
  179. // \/ \/
  180. // ErrWikiAlreadyExist represents a "WikiAlreadyExist" kind of error.
  181. type ErrWikiAlreadyExist struct {
  182. Title string
  183. }
  184. // IsErrWikiAlreadyExist checks if an error is an ErrWikiAlreadyExist.
  185. func IsErrWikiAlreadyExist(err error) bool {
  186. _, ok := err.(ErrWikiAlreadyExist)
  187. return ok
  188. }
  189. func (err ErrWikiAlreadyExist) Error() string {
  190. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  191. }
  192. // ErrWikiReservedName represents a reserved name error.
  193. type ErrWikiReservedName struct {
  194. Title string
  195. }
  196. // IsErrWikiReservedName checks if an error is an ErrWikiReservedName.
  197. func IsErrWikiReservedName(err error) bool {
  198. _, ok := err.(ErrWikiReservedName)
  199. return ok
  200. }
  201. func (err ErrWikiReservedName) Error() string {
  202. return fmt.Sprintf("wiki title is reserved: %s", err.Title)
  203. }
  204. // ErrWikiInvalidFileName represents an invalid wiki file name.
  205. type ErrWikiInvalidFileName struct {
  206. FileName string
  207. }
  208. // IsErrWikiInvalidFileName checks if an error is an ErrWikiInvalidFileName.
  209. func IsErrWikiInvalidFileName(err error) bool {
  210. _, ok := err.(ErrWikiInvalidFileName)
  211. return ok
  212. }
  213. func (err ErrWikiInvalidFileName) Error() string {
  214. return fmt.Sprintf("Invalid wiki filename: %s", err.FileName)
  215. }
  216. // __________ ___. .__ .__ ____ __.
  217. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  218. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  219. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  220. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  221. // \/ \/ \/ \/\/
  222. // ErrKeyUnableVerify represents a "KeyUnableVerify" kind of error.
  223. type ErrKeyUnableVerify struct {
  224. Result string
  225. }
  226. // IsErrKeyUnableVerify checks if an error is a ErrKeyUnableVerify.
  227. func IsErrKeyUnableVerify(err error) bool {
  228. _, ok := err.(ErrKeyUnableVerify)
  229. return ok
  230. }
  231. func (err ErrKeyUnableVerify) Error() string {
  232. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  233. }
  234. // ErrKeyNotExist represents a "KeyNotExist" kind of error.
  235. type ErrKeyNotExist struct {
  236. ID int64
  237. }
  238. // IsErrKeyNotExist checks if an error is a ErrKeyNotExist.
  239. func IsErrKeyNotExist(err error) bool {
  240. _, ok := err.(ErrKeyNotExist)
  241. return ok
  242. }
  243. func (err ErrKeyNotExist) Error() string {
  244. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  245. }
  246. // ErrKeyAlreadyExist represents a "KeyAlreadyExist" kind of error.
  247. type ErrKeyAlreadyExist struct {
  248. OwnerID int64
  249. Fingerprint string
  250. Content string
  251. }
  252. // IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.
  253. func IsErrKeyAlreadyExist(err error) bool {
  254. _, ok := err.(ErrKeyAlreadyExist)
  255. return ok
  256. }
  257. func (err ErrKeyAlreadyExist) Error() string {
  258. return fmt.Sprintf("public key already exists [owner_id: %d, finger_print: %s, content: %s]",
  259. err.OwnerID, err.Fingerprint, err.Content)
  260. }
  261. // ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
  262. type ErrKeyNameAlreadyUsed struct {
  263. OwnerID int64
  264. Name string
  265. }
  266. // IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  267. func IsErrKeyNameAlreadyUsed(err error) bool {
  268. _, ok := err.(ErrKeyNameAlreadyUsed)
  269. return ok
  270. }
  271. func (err ErrKeyNameAlreadyUsed) Error() string {
  272. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  273. }
  274. // ErrGPGNoEmailFound represents a "ErrGPGNoEmailFound" kind of error.
  275. type ErrGPGNoEmailFound struct {
  276. FailedEmails []string
  277. }
  278. // IsErrGPGNoEmailFound checks if an error is a ErrGPGNoEmailFound.
  279. func IsErrGPGNoEmailFound(err error) bool {
  280. _, ok := err.(ErrGPGNoEmailFound)
  281. return ok
  282. }
  283. func (err ErrGPGNoEmailFound) Error() string {
  284. return fmt.Sprintf("none of the emails attached to the GPG key could be found: %v", err.FailedEmails)
  285. }
  286. // ErrGPGKeyParsing represents a "ErrGPGKeyParsing" kind of error.
  287. type ErrGPGKeyParsing struct {
  288. ParseError error
  289. }
  290. // IsErrGPGKeyParsing checks if an error is a ErrGPGKeyParsing.
  291. func IsErrGPGKeyParsing(err error) bool {
  292. _, ok := err.(ErrGPGKeyParsing)
  293. return ok
  294. }
  295. func (err ErrGPGKeyParsing) Error() string {
  296. return fmt.Sprintf("failed to parse gpg key %s", err.ParseError.Error())
  297. }
  298. // ErrGPGKeyNotExist represents a "GPGKeyNotExist" kind of error.
  299. type ErrGPGKeyNotExist struct {
  300. ID int64
  301. }
  302. // IsErrGPGKeyNotExist checks if an error is a ErrGPGKeyNotExist.
  303. func IsErrGPGKeyNotExist(err error) bool {
  304. _, ok := err.(ErrGPGKeyNotExist)
  305. return ok
  306. }
  307. func (err ErrGPGKeyNotExist) Error() string {
  308. return fmt.Sprintf("public gpg key does not exist [id: %d]", err.ID)
  309. }
  310. // ErrGPGKeyImportNotExist represents a "GPGKeyImportNotExist" kind of error.
  311. type ErrGPGKeyImportNotExist struct {
  312. ID string
  313. }
  314. // IsErrGPGKeyImportNotExist checks if an error is a ErrGPGKeyImportNotExist.
  315. func IsErrGPGKeyImportNotExist(err error) bool {
  316. _, ok := err.(ErrGPGKeyImportNotExist)
  317. return ok
  318. }
  319. func (err ErrGPGKeyImportNotExist) Error() string {
  320. return fmt.Sprintf("public gpg key import does not exist [id: %s]", err.ID)
  321. }
  322. // ErrGPGKeyIDAlreadyUsed represents a "GPGKeyIDAlreadyUsed" kind of error.
  323. type ErrGPGKeyIDAlreadyUsed struct {
  324. KeyID string
  325. }
  326. // IsErrGPGKeyIDAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  327. func IsErrGPGKeyIDAlreadyUsed(err error) bool {
  328. _, ok := err.(ErrGPGKeyIDAlreadyUsed)
  329. return ok
  330. }
  331. func (err ErrGPGKeyIDAlreadyUsed) Error() string {
  332. return fmt.Sprintf("public key already exists [key_id: %s]", err.KeyID)
  333. }
  334. // ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error.
  335. type ErrGPGKeyAccessDenied struct {
  336. UserID int64
  337. KeyID int64
  338. }
  339. // IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.
  340. func IsErrGPGKeyAccessDenied(err error) bool {
  341. _, ok := err.(ErrGPGKeyAccessDenied)
  342. return ok
  343. }
  344. // Error pretty-prints an error of type ErrGPGKeyAccessDenied.
  345. func (err ErrGPGKeyAccessDenied) Error() string {
  346. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d]",
  347. err.UserID, err.KeyID)
  348. }
  349. // ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
  350. type ErrKeyAccessDenied struct {
  351. UserID int64
  352. KeyID int64
  353. Note string
  354. }
  355. // IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.
  356. func IsErrKeyAccessDenied(err error) bool {
  357. _, ok := err.(ErrKeyAccessDenied)
  358. return ok
  359. }
  360. func (err ErrKeyAccessDenied) Error() string {
  361. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  362. err.UserID, err.KeyID, err.Note)
  363. }
  364. // ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
  365. type ErrDeployKeyNotExist struct {
  366. ID int64
  367. KeyID int64
  368. RepoID int64
  369. }
  370. // IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.
  371. func IsErrDeployKeyNotExist(err error) bool {
  372. _, ok := err.(ErrDeployKeyNotExist)
  373. return ok
  374. }
  375. func (err ErrDeployKeyNotExist) Error() string {
  376. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  377. }
  378. // ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
  379. type ErrDeployKeyAlreadyExist struct {
  380. KeyID int64
  381. RepoID int64
  382. }
  383. // IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.
  384. func IsErrDeployKeyAlreadyExist(err error) bool {
  385. _, ok := err.(ErrDeployKeyAlreadyExist)
  386. return ok
  387. }
  388. func (err ErrDeployKeyAlreadyExist) Error() string {
  389. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  390. }
  391. // ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
  392. type ErrDeployKeyNameAlreadyUsed struct {
  393. RepoID int64
  394. Name string
  395. }
  396. // IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.
  397. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  398. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  399. return ok
  400. }
  401. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  402. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  403. }
  404. // _____ ___________ __
  405. // / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____
  406. // / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \
  407. // / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \
  408. // \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| /
  409. // \/ \/ \/ \/ \/ \/ \/ \/ \/
  410. // ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.
  411. type ErrAccessTokenNotExist struct {
  412. Token string
  413. }
  414. // IsErrAccessTokenNotExist checks if an error is a ErrAccessTokenNotExist.
  415. func IsErrAccessTokenNotExist(err error) bool {
  416. _, ok := err.(ErrAccessTokenNotExist)
  417. return ok
  418. }
  419. func (err ErrAccessTokenNotExist) Error() string {
  420. return fmt.Sprintf("access token does not exist [sha: %s]", err.Token)
  421. }
  422. // ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
  423. type ErrAccessTokenEmpty struct {
  424. }
  425. // IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
  426. func IsErrAccessTokenEmpty(err error) bool {
  427. _, ok := err.(ErrAccessTokenEmpty)
  428. return ok
  429. }
  430. func (err ErrAccessTokenEmpty) Error() string {
  431. return fmt.Sprintf("access token is empty")
  432. }
  433. // ________ .__ __ .__
  434. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  435. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  436. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  437. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  438. // \/ /_____/ \/ \/ \/ \/ \/
  439. // ErrOrgNotExist represents a "OrgNotExist" kind of error.
  440. type ErrOrgNotExist struct {
  441. ID int64
  442. Name string
  443. }
  444. // IsErrOrgNotExist checks if an error is a ErrOrgNotExist.
  445. func IsErrOrgNotExist(err error) bool {
  446. _, ok := err.(ErrOrgNotExist)
  447. return ok
  448. }
  449. func (err ErrOrgNotExist) Error() string {
  450. return fmt.Sprintf("org does not exist [id: %d, name: %s]", err.ID, err.Name)
  451. }
  452. // ErrLastOrgOwner represents a "LastOrgOwner" kind of error.
  453. type ErrLastOrgOwner struct {
  454. UID int64
  455. }
  456. // IsErrLastOrgOwner checks if an error is a ErrLastOrgOwner.
  457. func IsErrLastOrgOwner(err error) bool {
  458. _, ok := err.(ErrLastOrgOwner)
  459. return ok
  460. }
  461. func (err ErrLastOrgOwner) Error() string {
  462. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  463. }
  464. //.____ ____________________
  465. //| | \_ _____/ _____/
  466. //| | | __) \_____ \
  467. //| |___| \ / \
  468. //|_______ \___ / /_______ /
  469. // \/ \/ \/
  470. // ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error.
  471. type ErrLFSLockNotExist struct {
  472. ID int64
  473. RepoID int64
  474. Path string
  475. }
  476. // IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist.
  477. func IsErrLFSLockNotExist(err error) bool {
  478. _, ok := err.(ErrLFSLockNotExist)
  479. return ok
  480. }
  481. func (err ErrLFSLockNotExist) Error() string {
  482. return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path)
  483. }
  484. // ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error.
  485. type ErrLFSUnauthorizedAction struct {
  486. RepoID int64
  487. UserName string
  488. Mode AccessMode
  489. }
  490. // IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction.
  491. func IsErrLFSUnauthorizedAction(err error) bool {
  492. _, ok := err.(ErrLFSUnauthorizedAction)
  493. return ok
  494. }
  495. func (err ErrLFSUnauthorizedAction) Error() string {
  496. if err.Mode == AccessModeWrite {
  497. return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID)
  498. }
  499. return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID)
  500. }
  501. // ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error.
  502. type ErrLFSLockAlreadyExist struct {
  503. RepoID int64
  504. Path string
  505. }
  506. // IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist.
  507. func IsErrLFSLockAlreadyExist(err error) bool {
  508. _, ok := err.(ErrLFSLockAlreadyExist)
  509. return ok
  510. }
  511. func (err ErrLFSLockAlreadyExist) Error() string {
  512. return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path)
  513. }
  514. // __________ .__ __
  515. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  516. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  517. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  518. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  519. // \/ \/|__| \/ \/
  520. // ErrRepoNotExist represents a "RepoNotExist" kind of error.
  521. type ErrRepoNotExist struct {
  522. ID int64
  523. UID int64
  524. OwnerName string
  525. Name string
  526. }
  527. // IsErrRepoNotExist checks if an error is a ErrRepoNotExist.
  528. func IsErrRepoNotExist(err error) bool {
  529. _, ok := err.(ErrRepoNotExist)
  530. return ok
  531. }
  532. func (err ErrRepoNotExist) Error() string {
  533. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, owner_name: %s, name: %s]",
  534. err.ID, err.UID, err.OwnerName, err.Name)
  535. }
  536. // ErrRepoAlreadyExist represents a "RepoAlreadyExist" kind of error.
  537. type ErrRepoAlreadyExist struct {
  538. Uname string
  539. Name string
  540. }
  541. // IsErrRepoAlreadyExist checks if an error is a ErrRepoAlreadyExist.
  542. func IsErrRepoAlreadyExist(err error) bool {
  543. _, ok := err.(ErrRepoAlreadyExist)
  544. return ok
  545. }
  546. func (err ErrRepoAlreadyExist) Error() string {
  547. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  548. }
  549. // ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error.
  550. type ErrForkAlreadyExist struct {
  551. Uname string
  552. RepoName string
  553. ForkName string
  554. }
  555. // IsErrForkAlreadyExist checks if an error is an ErrForkAlreadyExist.
  556. func IsErrForkAlreadyExist(err error) bool {
  557. _, ok := err.(ErrForkAlreadyExist)
  558. return ok
  559. }
  560. func (err ErrForkAlreadyExist) Error() string {
  561. return fmt.Sprintf("repository is already forked by user [uname: %s, repo path: %s, fork path: %s]", err.Uname, err.RepoName, err.ForkName)
  562. }
  563. // ErrRepoRedirectNotExist represents a "RepoRedirectNotExist" kind of error.
  564. type ErrRepoRedirectNotExist struct {
  565. OwnerID int64
  566. RepoName string
  567. }
  568. // IsErrRepoRedirectNotExist check if an error is an ErrRepoRedirectNotExist.
  569. func IsErrRepoRedirectNotExist(err error) bool {
  570. _, ok := err.(ErrRepoRedirectNotExist)
  571. return ok
  572. }
  573. func (err ErrRepoRedirectNotExist) Error() string {
  574. return fmt.Sprintf("repository redirect does not exist [uid: %d, name: %s]", err.OwnerID, err.RepoName)
  575. }
  576. // ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error.
  577. type ErrInvalidCloneAddr struct {
  578. IsURLError bool
  579. IsInvalidPath bool
  580. IsPermissionDenied bool
  581. }
  582. // IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
  583. func IsErrInvalidCloneAddr(err error) bool {
  584. _, ok := err.(ErrInvalidCloneAddr)
  585. return ok
  586. }
  587. func (err ErrInvalidCloneAddr) Error() string {
  588. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v]",
  589. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied)
  590. }
  591. // ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error.
  592. type ErrUpdateTaskNotExist struct {
  593. UUID string
  594. }
  595. // IsErrUpdateTaskNotExist checks if an error is a ErrUpdateTaskNotExist.
  596. func IsErrUpdateTaskNotExist(err error) bool {
  597. _, ok := err.(ErrUpdateTaskNotExist)
  598. return ok
  599. }
  600. func (err ErrUpdateTaskNotExist) Error() string {
  601. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  602. }
  603. // ErrReleaseAlreadyExist represents a "ReleaseAlreadyExist" kind of error.
  604. type ErrReleaseAlreadyExist struct {
  605. TagName string
  606. }
  607. // IsErrReleaseAlreadyExist checks if an error is a ErrReleaseAlreadyExist.
  608. func IsErrReleaseAlreadyExist(err error) bool {
  609. _, ok := err.(ErrReleaseAlreadyExist)
  610. return ok
  611. }
  612. func (err ErrReleaseAlreadyExist) Error() string {
  613. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  614. }
  615. // ErrReleaseNotExist represents a "ReleaseNotExist" kind of error.
  616. type ErrReleaseNotExist struct {
  617. ID int64
  618. TagName string
  619. }
  620. // IsErrReleaseNotExist checks if an error is a ErrReleaseNotExist.
  621. func IsErrReleaseNotExist(err error) bool {
  622. _, ok := err.(ErrReleaseNotExist)
  623. return ok
  624. }
  625. func (err ErrReleaseNotExist) Error() string {
  626. return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
  627. }
  628. // ErrInvalidTagName represents a "InvalidTagName" kind of error.
  629. type ErrInvalidTagName struct {
  630. TagName string
  631. }
  632. // IsErrInvalidTagName checks if an error is a ErrInvalidTagName.
  633. func IsErrInvalidTagName(err error) bool {
  634. _, ok := err.(ErrInvalidTagName)
  635. return ok
  636. }
  637. func (err ErrInvalidTagName) Error() string {
  638. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  639. }
  640. // ErrRepoFileAlreadyExists represents a "RepoFileAlreadyExist" kind of error.
  641. type ErrRepoFileAlreadyExists struct {
  642. Path string
  643. }
  644. // IsErrRepoFileAlreadyExists checks if an error is a ErrRepoFileAlreadyExists.
  645. func IsErrRepoFileAlreadyExists(err error) bool {
  646. _, ok := err.(ErrRepoFileAlreadyExists)
  647. return ok
  648. }
  649. func (err ErrRepoFileAlreadyExists) Error() string {
  650. return fmt.Sprintf("repository file already exists [path: %s]", err.Path)
  651. }
  652. // ErrRepoFileDoesNotExist represents a "RepoFileDoesNotExist" kind of error.
  653. type ErrRepoFileDoesNotExist struct {
  654. Path string
  655. Name string
  656. }
  657. // IsErrRepoFileDoesNotExist checks if an error is a ErrRepoDoesNotExist.
  658. func IsErrRepoFileDoesNotExist(err error) bool {
  659. _, ok := err.(ErrRepoFileDoesNotExist)
  660. return ok
  661. }
  662. func (err ErrRepoFileDoesNotExist) Error() string {
  663. return fmt.Sprintf("repository file does not exist [path: %s]", err.Path)
  664. }
  665. // ErrFilenameInvalid represents a "FilenameInvalid" kind of error.
  666. type ErrFilenameInvalid struct {
  667. Path string
  668. }
  669. // IsErrFilenameInvalid checks if an error is an ErrFilenameInvalid.
  670. func IsErrFilenameInvalid(err error) bool {
  671. _, ok := err.(ErrFilenameInvalid)
  672. return ok
  673. }
  674. func (err ErrFilenameInvalid) Error() string {
  675. return fmt.Sprintf("path contains a malformed path component [path: %s]", err.Path)
  676. }
  677. // ErrUserCannotCommit represents "UserCannotCommit" kind of error.
  678. type ErrUserCannotCommit struct {
  679. UserName string
  680. }
  681. // IsErrUserCannotCommit checks if an error is an ErrUserCannotCommit.
  682. func IsErrUserCannotCommit(err error) bool {
  683. _, ok := err.(ErrUserCannotCommit)
  684. return ok
  685. }
  686. func (err ErrUserCannotCommit) Error() string {
  687. return fmt.Sprintf("user cannot commit to repo [user: %s]", err.UserName)
  688. }
  689. // ErrFilePathInvalid represents a "FilePathInvalid" kind of error.
  690. type ErrFilePathInvalid struct {
  691. Message string
  692. Path string
  693. Name string
  694. Type git.EntryMode
  695. }
  696. // IsErrFilePathInvalid checks if an error is an ErrFilePathInvalid.
  697. func IsErrFilePathInvalid(err error) bool {
  698. _, ok := err.(ErrFilePathInvalid)
  699. return ok
  700. }
  701. func (err ErrFilePathInvalid) Error() string {
  702. if err.Message != "" {
  703. return err.Message
  704. }
  705. return fmt.Sprintf("path is invalid [path: %s]", err.Path)
  706. }
  707. // ErrUserDoesNotHaveAccessToRepo represets an error where the user doesn't has access to a given repo.
  708. type ErrUserDoesNotHaveAccessToRepo struct {
  709. UserID int64
  710. RepoName string
  711. }
  712. // IsErrUserDoesNotHaveAccessToRepo checks if an error is a ErrRepoFileAlreadyExists.
  713. func IsErrUserDoesNotHaveAccessToRepo(err error) bool {
  714. _, ok := err.(ErrUserDoesNotHaveAccessToRepo)
  715. return ok
  716. }
  717. func (err ErrUserDoesNotHaveAccessToRepo) Error() string {
  718. return fmt.Sprintf("user doesn't have acces to repo [user_id: %d, repo_name: %s]", err.UserID, err.RepoName)
  719. }
  720. // __________ .__
  721. // \______ \____________ ____ ____ | |__
  722. // | | _/\_ __ \__ \ / \_/ ___\| | \
  723. // | | \ | | \// __ \| | \ \___| Y \
  724. // |______ / |__| (____ /___| /\___ >___| /
  725. // \/ \/ \/ \/ \/
  726. // ErrBranchAlreadyExists represents an error that branch with such name already exists.
  727. type ErrBranchAlreadyExists struct {
  728. BranchName string
  729. }
  730. // IsErrBranchAlreadyExists checks if an error is an ErrBranchAlreadyExists.
  731. func IsErrBranchAlreadyExists(err error) bool {
  732. _, ok := err.(ErrBranchAlreadyExists)
  733. return ok
  734. }
  735. func (err ErrBranchAlreadyExists) Error() string {
  736. return fmt.Sprintf("branch already exists [name: %s]", err.BranchName)
  737. }
  738. // ErrBranchNameConflict represents an error that branch name conflicts with other branch.
  739. type ErrBranchNameConflict struct {
  740. BranchName string
  741. }
  742. // IsErrBranchNameConflict checks if an error is an ErrBranchNameConflict.
  743. func IsErrBranchNameConflict(err error) bool {
  744. _, ok := err.(ErrBranchNameConflict)
  745. return ok
  746. }
  747. func (err ErrBranchNameConflict) Error() string {
  748. return fmt.Sprintf("branch conflicts with existing branch [name: %s]", err.BranchName)
  749. }
  750. // ErrNotAllowedToMerge represents an error that a branch is protected and the current user is not allowed to modify it.
  751. type ErrNotAllowedToMerge struct {
  752. Reason string
  753. }
  754. // IsErrNotAllowedToMerge checks if an error is an ErrNotAllowedToMerge.
  755. func IsErrNotAllowedToMerge(err error) bool {
  756. _, ok := err.(ErrNotAllowedToMerge)
  757. return ok
  758. }
  759. func (err ErrNotAllowedToMerge) Error() string {
  760. return fmt.Sprintf("not allowed to merge [reason: %s]", err.Reason)
  761. }
  762. // ErrTagAlreadyExists represents an error that tag with such name already exists.
  763. type ErrTagAlreadyExists struct {
  764. TagName string
  765. }
  766. // IsErrTagAlreadyExists checks if an error is an ErrTagAlreadyExists.
  767. func IsErrTagAlreadyExists(err error) bool {
  768. _, ok := err.(ErrTagAlreadyExists)
  769. return ok
  770. }
  771. func (err ErrTagAlreadyExists) Error() string {
  772. return fmt.Sprintf("tag already exists [name: %s]", err.TagName)
  773. }
  774. // ErrSHADoesNotMatch represents a "SHADoesNotMatch" kind of error.
  775. type ErrSHADoesNotMatch struct {
  776. Path string
  777. GivenSHA string
  778. CurrentSHA string
  779. }
  780. // IsErrSHADoesNotMatch checks if an error is a ErrSHADoesNotMatch.
  781. func IsErrSHADoesNotMatch(err error) bool {
  782. _, ok := err.(ErrSHADoesNotMatch)
  783. return ok
  784. }
  785. func (err ErrSHADoesNotMatch) Error() string {
  786. return fmt.Sprintf("sha does not match [given: %s, expected: %s]", err.GivenSHA, err.CurrentSHA)
  787. }
  788. // ErrSHANotFound represents a "SHADoesNotMatch" kind of error.
  789. type ErrSHANotFound struct {
  790. SHA string
  791. }
  792. // IsErrSHANotFound checks if an error is a ErrSHANotFound.
  793. func IsErrSHANotFound(err error) bool {
  794. _, ok := err.(ErrSHANotFound)
  795. return ok
  796. }
  797. func (err ErrSHANotFound) Error() string {
  798. return fmt.Sprintf("sha not found [%s]", err.SHA)
  799. }
  800. // ErrCommitIDDoesNotMatch represents a "CommitIDDoesNotMatch" kind of error.
  801. type ErrCommitIDDoesNotMatch struct {
  802. GivenCommitID string
  803. CurrentCommitID string
  804. }
  805. // IsErrCommitIDDoesNotMatch checks if an error is a ErrCommitIDDoesNotMatch.
  806. func IsErrCommitIDDoesNotMatch(err error) bool {
  807. _, ok := err.(ErrCommitIDDoesNotMatch)
  808. return ok
  809. }
  810. func (err ErrCommitIDDoesNotMatch) Error() string {
  811. return fmt.Sprintf("file CommitID does not match [given: %s, expected: %s]", err.GivenCommitID, err.CurrentCommitID)
  812. }
  813. // ErrSHAOrCommitIDNotProvided represents a "SHAOrCommitIDNotProvided" kind of error.
  814. type ErrSHAOrCommitIDNotProvided struct{}
  815. // IsErrSHAOrCommitIDNotProvided checks if an error is a ErrSHAOrCommitIDNotProvided.
  816. func IsErrSHAOrCommitIDNotProvided(err error) bool {
  817. _, ok := err.(ErrSHAOrCommitIDNotProvided)
  818. return ok
  819. }
  820. func (err ErrSHAOrCommitIDNotProvided) Error() string {
  821. return fmt.Sprintf("a SHA or commmit ID must be proved when updating a file")
  822. }
  823. // __ __ ___. .__ __
  824. // / \ / \ ____\_ |__ | |__ ____ ____ | | __
  825. // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
  826. // \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
  827. // \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
  828. // \/ \/ \/ \/ \/
  829. // ErrWebhookNotExist represents a "WebhookNotExist" kind of error.
  830. type ErrWebhookNotExist struct {
  831. ID int64
  832. }
  833. // IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.
  834. func IsErrWebhookNotExist(err error) bool {
  835. _, ok := err.(ErrWebhookNotExist)
  836. return ok
  837. }
  838. func (err ErrWebhookNotExist) Error() string {
  839. return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
  840. }
  841. // .___
  842. // | | ______ ________ __ ____
  843. // | |/ ___// ___/ | \_/ __ \
  844. // | |\___ \ \___ \| | /\ ___/
  845. // |___/____ >____ >____/ \___ >
  846. // \/ \/ \/
  847. // ErrIssueNotExist represents a "IssueNotExist" kind of error.
  848. type ErrIssueNotExist struct {
  849. ID int64
  850. RepoID int64
  851. Index int64
  852. }
  853. // IsErrIssueNotExist checks if an error is a ErrIssueNotExist.
  854. func IsErrIssueNotExist(err error) bool {
  855. _, ok := err.(ErrIssueNotExist)
  856. return ok
  857. }
  858. func (err ErrIssueNotExist) Error() string {
  859. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  860. }
  861. // ErrIssueLabelTemplateLoad represents a "ErrIssueLabelTemplateLoad" kind of error.
  862. type ErrIssueLabelTemplateLoad struct {
  863. TemplateFile string
  864. OriginalError error
  865. }
  866. // IsErrIssueLabelTemplateLoad checks if an error is a ErrIssueLabelTemplateLoad.
  867. func IsErrIssueLabelTemplateLoad(err error) bool {
  868. _, ok := err.(ErrIssueLabelTemplateLoad)
  869. return ok
  870. }
  871. func (err ErrIssueLabelTemplateLoad) Error() string {
  872. return fmt.Sprintf("Failed to load label template file '%s': %v", err.TemplateFile, err.OriginalError)
  873. }
  874. // __________ .__ .__ __________ __
  875. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  876. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  877. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  878. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  879. // \/ \/ |__| \/ \/
  880. // ErrPullRequestNotExist represents a "PullRequestNotExist" kind of error.
  881. type ErrPullRequestNotExist struct {
  882. ID int64
  883. IssueID int64
  884. HeadRepoID int64
  885. BaseRepoID int64
  886. HeadBranch string
  887. BaseBranch string
  888. }
  889. // IsErrPullRequestNotExist checks if an error is a ErrPullRequestNotExist.
  890. func IsErrPullRequestNotExist(err error) bool {
  891. _, ok := err.(ErrPullRequestNotExist)
  892. return ok
  893. }
  894. func (err ErrPullRequestNotExist) Error() string {
  895. 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]",
  896. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  897. }
  898. // ErrPullRequestAlreadyExists represents a "PullRequestAlreadyExists"-error
  899. type ErrPullRequestAlreadyExists struct {
  900. ID int64
  901. IssueID int64
  902. HeadRepoID int64
  903. BaseRepoID int64
  904. HeadBranch string
  905. BaseBranch string
  906. }
  907. // IsErrPullRequestAlreadyExists checks if an error is a ErrPullRequestAlreadyExists.
  908. func IsErrPullRequestAlreadyExists(err error) bool {
  909. _, ok := err.(ErrPullRequestAlreadyExists)
  910. return ok
  911. }
  912. // Error does pretty-printing :D
  913. func (err ErrPullRequestAlreadyExists) Error() string {
  914. return fmt.Sprintf("pull request already exists for these targets [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]",
  915. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  916. }
  917. // ErrPullRequestHeadRepoMissing represents a "ErrPullRequestHeadRepoMissing" error
  918. type ErrPullRequestHeadRepoMissing struct {
  919. ID int64
  920. HeadRepoID int64
  921. }
  922. // IsErrErrPullRequestHeadRepoMissing checks if an error is a ErrPullRequestHeadRepoMissing.
  923. func IsErrErrPullRequestHeadRepoMissing(err error) bool {
  924. _, ok := err.(ErrPullRequestHeadRepoMissing)
  925. return ok
  926. }
  927. // Error does pretty-printing :D
  928. func (err ErrPullRequestHeadRepoMissing) Error() string {
  929. return fmt.Sprintf("pull request head repo missing [id: %d, head_repo_id: %d]",
  930. err.ID, err.HeadRepoID)
  931. }
  932. // ErrInvalidMergeStyle represents an error if merging with disabled merge strategy
  933. type ErrInvalidMergeStyle struct {
  934. ID int64
  935. Style MergeStyle
  936. }
  937. // IsErrInvalidMergeStyle checks if an error is a ErrInvalidMergeStyle.
  938. func IsErrInvalidMergeStyle(err error) bool {
  939. _, ok := err.(ErrInvalidMergeStyle)
  940. return ok
  941. }
  942. func (err ErrInvalidMergeStyle) Error() string {
  943. return fmt.Sprintf("merge strategy is not allowed or is invalid [repo_id: %d, strategy: %s]",
  944. err.ID, err.Style)
  945. }
  946. // _________ __
  947. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  948. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  949. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  950. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  951. // \/ \/ \/ \/ \/
  952. // ErrCommentNotExist represents a "CommentNotExist" kind of error.
  953. type ErrCommentNotExist struct {
  954. ID int64
  955. IssueID int64
  956. }
  957. // IsErrCommentNotExist checks if an error is a ErrCommentNotExist.
  958. func IsErrCommentNotExist(err error) bool {
  959. _, ok := err.(ErrCommentNotExist)
  960. return ok
  961. }
  962. func (err ErrCommentNotExist) Error() string {
  963. return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
  964. }
  965. // _________ __ __ .__
  966. // / _____// |_ ____ ________ _ _______ _/ |_ ____ | |__
  967. // \_____ \\ __\/ _ \\____ \ \/ \/ /\__ \\ __\/ ___\| | \
  968. // / \| | ( <_> ) |_> > / / __ \| | \ \___| Y \
  969. // /_______ /|__| \____/| __/ \/\_/ (____ /__| \___ >___| /
  970. // \/ |__| \/ \/ \/
  971. // ErrStopwatchNotExist represents a "Stopwatch Not Exist" kind of error.
  972. type ErrStopwatchNotExist struct {
  973. ID int64
  974. }
  975. // IsErrStopwatchNotExist checks if an error is a ErrStopwatchNotExist.
  976. func IsErrStopwatchNotExist(err error) bool {
  977. _, ok := err.(ErrStopwatchNotExist)
  978. return ok
  979. }
  980. func (err ErrStopwatchNotExist) Error() string {
  981. return fmt.Sprintf("stopwatch does not exist [id: %d]", err.ID)
  982. }
  983. // ___________ __ .______________.__
  984. // \__ ___/___________ ____ | | __ ____ __| _/\__ ___/|__| _____ ____
  985. // | | \_ __ \__ \ _/ ___\| |/ // __ \ / __ | | | | |/ \_/ __ \
  986. // | | | | \// __ \\ \___| <\ ___// /_/ | | | | | Y Y \ ___/
  987. // |____| |__| (____ /\___ >__|_ \\___ >____ | |____| |__|__|_| /\___ >
  988. // \/ \/ \/ \/ \/ \/ \/
  989. // ErrTrackedTimeNotExist represents a "TrackedTime Not Exist" kind of error.
  990. type ErrTrackedTimeNotExist struct {
  991. ID int64
  992. }
  993. // IsErrTrackedTimeNotExist checks if an error is a ErrTrackedTimeNotExist.
  994. func IsErrTrackedTimeNotExist(err error) bool {
  995. _, ok := err.(ErrTrackedTimeNotExist)
  996. return ok
  997. }
  998. func (err ErrTrackedTimeNotExist) Error() string {
  999. return fmt.Sprintf("tracked time does not exist [id: %d]", err.ID)
  1000. }
  1001. // .____ ___. .__
  1002. // | | _____ \_ |__ ____ | |
  1003. // | | \__ \ | __ \_/ __ \| |
  1004. // | |___ / __ \| \_\ \ ___/| |__
  1005. // |_______ (____ /___ /\___ >____/
  1006. // \/ \/ \/ \/
  1007. // ErrLabelNotExist represents a "LabelNotExist" kind of error.
  1008. type ErrLabelNotExist struct {
  1009. LabelID int64
  1010. RepoID int64
  1011. }
  1012. // IsErrLabelNotExist checks if an error is a ErrLabelNotExist.
  1013. func IsErrLabelNotExist(err error) bool {
  1014. _, ok := err.(ErrLabelNotExist)
  1015. return ok
  1016. }
  1017. func (err ErrLabelNotExist) Error() string {
  1018. return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
  1019. }
  1020. // _____ .__.__ __
  1021. // / \ |__| | ____ _______/ |_ ____ ____ ____
  1022. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  1023. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  1024. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  1025. // \/ \/ \/ \/ \/
  1026. // ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
  1027. type ErrMilestoneNotExist struct {
  1028. ID int64
  1029. RepoID int64
  1030. }
  1031. // IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
  1032. func IsErrMilestoneNotExist(err error) bool {
  1033. _, ok := err.(ErrMilestoneNotExist)
  1034. return ok
  1035. }
  1036. func (err ErrMilestoneNotExist) Error() string {
  1037. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  1038. }
  1039. // _____ __ __ .__ __
  1040. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  1041. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  1042. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  1043. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  1044. // \/ \/ \/ \/ \/ \/ \/
  1045. // ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
  1046. type ErrAttachmentNotExist struct {
  1047. ID int64
  1048. UUID string
  1049. }
  1050. // IsErrAttachmentNotExist checks if an error is a ErrAttachmentNotExist.
  1051. func IsErrAttachmentNotExist(err error) bool {
  1052. _, ok := err.(ErrAttachmentNotExist)
  1053. return ok
  1054. }
  1055. func (err ErrAttachmentNotExist) Error() string {
  1056. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  1057. }
  1058. // .____ .__ _________
  1059. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  1060. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  1061. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  1062. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  1063. // \/ /_____/ \/ \/ \/ \/
  1064. // ErrLoginSourceNotExist represents a "LoginSourceNotExist" kind of error.
  1065. type ErrLoginSourceNotExist struct {
  1066. ID int64
  1067. }
  1068. // IsErrLoginSourceNotExist checks if an error is a ErrLoginSourceNotExist.
  1069. func IsErrLoginSourceNotExist(err error) bool {
  1070. _, ok := err.(ErrLoginSourceNotExist)
  1071. return ok
  1072. }
  1073. func (err ErrLoginSourceNotExist) Error() string {
  1074. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  1075. }
  1076. // ErrLoginSourceAlreadyExist represents a "LoginSourceAlreadyExist" kind of error.
  1077. type ErrLoginSourceAlreadyExist struct {
  1078. Name string
  1079. }
  1080. // IsErrLoginSourceAlreadyExist checks if an error is a ErrLoginSourceAlreadyExist.
  1081. func IsErrLoginSourceAlreadyExist(err error) bool {
  1082. _, ok := err.(ErrLoginSourceAlreadyExist)
  1083. return ok
  1084. }
  1085. func (err ErrLoginSourceAlreadyExist) Error() string {
  1086. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  1087. }
  1088. // ErrLoginSourceInUse represents a "LoginSourceInUse" kind of error.
  1089. type ErrLoginSourceInUse struct {
  1090. ID int64
  1091. }
  1092. // IsErrLoginSourceInUse checks if an error is a ErrLoginSourceInUse.
  1093. func IsErrLoginSourceInUse(err error) bool {
  1094. _, ok := err.(ErrLoginSourceInUse)
  1095. return ok
  1096. }
  1097. func (err ErrLoginSourceInUse) Error() string {
  1098. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  1099. }
  1100. // ___________
  1101. // \__ ___/___ _____ _____
  1102. // | |_/ __ \\__ \ / \
  1103. // | |\ ___/ / __ \| Y Y \
  1104. // |____| \___ >____ /__|_| /
  1105. // \/ \/ \/
  1106. // ErrTeamAlreadyExist represents a "TeamAlreadyExist" kind of error.
  1107. type ErrTeamAlreadyExist struct {
  1108. OrgID int64
  1109. Name string
  1110. }
  1111. // IsErrTeamAlreadyExist checks if an error is a ErrTeamAlreadyExist.
  1112. func IsErrTeamAlreadyExist(err error) bool {
  1113. _, ok := err.(ErrTeamAlreadyExist)
  1114. return ok
  1115. }
  1116. func (err ErrTeamAlreadyExist) Error() string {
  1117. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  1118. }
  1119. //
  1120. // Two-factor authentication
  1121. //
  1122. // ErrTwoFactorNotEnrolled indicates that a user is not enrolled in two-factor authentication.
  1123. type ErrTwoFactorNotEnrolled struct {
  1124. UID int64
  1125. }
  1126. // IsErrTwoFactorNotEnrolled checks if an error is a ErrTwoFactorNotEnrolled.
  1127. func IsErrTwoFactorNotEnrolled(err error) bool {
  1128. _, ok := err.(ErrTwoFactorNotEnrolled)
  1129. return ok
  1130. }
  1131. func (err ErrTwoFactorNotEnrolled) Error() string {
  1132. return fmt.Sprintf("user not enrolled in 2FA [uid: %d]", err.UID)
  1133. }
  1134. // ____ ___ .__ .___
  1135. // | | \______ | | _________ __| _/
  1136. // | | /\____ \| | / _ \__ \ / __ |
  1137. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  1138. // |______/ | __/|____/\____(____ /\____ |
  1139. // |__| \/ \/
  1140. //
  1141. // ErrUploadNotExist represents a "UploadNotExist" kind of error.
  1142. type ErrUploadNotExist struct {
  1143. ID int64
  1144. UUID string
  1145. }
  1146. // IsErrUploadNotExist checks if an error is a ErrUploadNotExist.
  1147. func IsErrUploadNotExist(err error) bool {
  1148. _, ok := err.(ErrAttachmentNotExist)
  1149. return ok
  1150. }
  1151. func (err ErrUploadNotExist) Error() string {
  1152. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  1153. }
  1154. // ___________ __ .__ .____ .__ ____ ___
  1155. // \_ _____/__ ____/ |_ ___________ ____ _____ | | | | ____ ____ |__| ____ | | \______ ___________
  1156. // | __)_\ \/ /\ __\/ __ \_ __ \/ \\__ \ | | | | / _ \ / ___\| |/ \ | | / ___// __ \_ __ \
  1157. // | \> < | | \ ___/| | \/ | \/ __ \| |__ | |__( <_> ) /_/ > | | \ | | /\___ \\ ___/| | \/
  1158. // /_______ /__/\_ \ |__| \___ >__| |___| (____ /____/ |_______ \____/\___ /|__|___| / |______//____ >\___ >__|
  1159. // \/ \/ \/ \/ \/ \/ /_____/ \/ \/ \/
  1160. // ErrExternalLoginUserAlreadyExist represents a "ExternalLoginUserAlreadyExist" kind of error.
  1161. type ErrExternalLoginUserAlreadyExist struct {
  1162. ExternalID string
  1163. UserID int64
  1164. LoginSourceID int64
  1165. }
  1166. // IsErrExternalLoginUserAlreadyExist checks if an error is a ExternalLoginUserAlreadyExist.
  1167. func IsErrExternalLoginUserAlreadyExist(err error) bool {
  1168. _, ok := err.(ErrExternalLoginUserAlreadyExist)
  1169. return ok
  1170. }
  1171. func (err ErrExternalLoginUserAlreadyExist) Error() string {
  1172. return fmt.Sprintf("external login user already exists [externalID: %s, userID: %d, loginSourceID: %d]", err.ExternalID, err.UserID, err.LoginSourceID)
  1173. }
  1174. // ErrExternalLoginUserNotExist represents a "ExternalLoginUserNotExist" kind of error.
  1175. type ErrExternalLoginUserNotExist struct {
  1176. UserID int64
  1177. LoginSourceID int64
  1178. }
  1179. // IsErrExternalLoginUserNotExist checks if an error is a ExternalLoginUserNotExist.
  1180. func IsErrExternalLoginUserNotExist(err error) bool {
  1181. _, ok := err.(ErrExternalLoginUserNotExist)
  1182. return ok
  1183. }
  1184. func (err ErrExternalLoginUserNotExist) Error() string {
  1185. return fmt.Sprintf("external login user link does not exists [userID: %d, loginSourceID: %d]", err.UserID, err.LoginSourceID)
  1186. }
  1187. // ____ ________________________________ .__ __ __ .__
  1188. // | | \_____ \_ _____/\______ \ ____ ____ |__| _______/ |_____________ _/ |_|__| ____ ____
  1189. // | | // ____/| __) | _// __ \ / ___\| |/ ___/\ __\_ __ \__ \\ __\ |/ _ \ / \
  1190. // | | // \| \ | | \ ___// /_/ > |\___ \ | | | | \// __ \| | | ( <_> ) | \
  1191. // |______/ \_______ \___ / |____|_ /\___ >___ /|__/____ > |__| |__| (____ /__| |__|\____/|___| /
  1192. // \/ \/ \/ \/_____/ \/ \/ \/
  1193. // ErrU2FRegistrationNotExist represents a "ErrU2FRegistrationNotExist" kind of error.
  1194. type ErrU2FRegistrationNotExist struct {
  1195. ID int64
  1196. }
  1197. func (err ErrU2FRegistrationNotExist) Error() string {
  1198. return fmt.Sprintf("U2F registration does not exist [id: %d]", err.ID)
  1199. }
  1200. // IsErrU2FRegistrationNotExist checks if an error is a ErrU2FRegistrationNotExist.
  1201. func IsErrU2FRegistrationNotExist(err error) bool {
  1202. _, ok := err.(ErrU2FRegistrationNotExist)
  1203. return ok
  1204. }
  1205. // .___ ________ .___ .__
  1206. // | | ______ ________ __ ____ \______ \ ____ ______ ____ ____ __| _/____ ____ ____ |__| ____ ______
  1207. // | |/ ___// ___/ | \_/ __ \ | | \_/ __ \\____ \_/ __ \ / \ / __ |/ __ \ / \_/ ___\| |/ __ \ / ___/
  1208. // | |\___ \ \___ \| | /\ ___/ | ` \ ___/| |_> > ___/| | \/ /_/ \ ___/| | \ \___| \ ___/ \___ \
  1209. // |___/____ >____ >____/ \___ >_______ /\___ > __/ \___ >___| /\____ |\___ >___| /\___ >__|\___ >____ >
  1210. // \/ \/ \/ \/ \/|__| \/ \/ \/ \/ \/ \/ \/ \/
  1211. // ErrDependencyExists represents a "DependencyAlreadyExists" kind of error.
  1212. type ErrDependencyExists struct {
  1213. IssueID int64
  1214. DependencyID int64
  1215. }
  1216. // IsErrDependencyExists checks if an error is a ErrDependencyExists.
  1217. func IsErrDependencyExists(err error) bool {
  1218. _, ok := err.(ErrDependencyExists)
  1219. return ok
  1220. }
  1221. func (err ErrDependencyExists) Error() string {
  1222. return fmt.Sprintf("issue dependency does already exist [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1223. }
  1224. // ErrDependencyNotExists represents a "DependencyAlreadyExists" kind of error.
  1225. type ErrDependencyNotExists struct {
  1226. IssueID int64
  1227. DependencyID int64
  1228. }
  1229. // IsErrDependencyNotExists checks if an error is a ErrDependencyExists.
  1230. func IsErrDependencyNotExists(err error) bool {
  1231. _, ok := err.(ErrDependencyNotExists)
  1232. return ok
  1233. }
  1234. func (err ErrDependencyNotExists) Error() string {
  1235. return fmt.Sprintf("issue dependency does not exist [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1236. }
  1237. // ErrCircularDependency represents a "DependencyCircular" kind of error.
  1238. type ErrCircularDependency struct {
  1239. IssueID int64
  1240. DependencyID int64
  1241. }
  1242. // IsErrCircularDependency checks if an error is a ErrCircularDependency.
  1243. func IsErrCircularDependency(err error) bool {
  1244. _, ok := err.(ErrCircularDependency)
  1245. return ok
  1246. }
  1247. func (err ErrCircularDependency) Error() string {
  1248. return fmt.Sprintf("circular dependencies exists (two issues blocking each other) [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1249. }
  1250. // ErrDependenciesLeft represents an error where the issue you're trying to close still has dependencies left.
  1251. type ErrDependenciesLeft struct {
  1252. IssueID int64
  1253. }
  1254. // IsErrDependenciesLeft checks if an error is a ErrDependenciesLeft.
  1255. func IsErrDependenciesLeft(err error) bool {
  1256. _, ok := err.(ErrDependenciesLeft)
  1257. return ok
  1258. }
  1259. func (err ErrDependenciesLeft) Error() string {
  1260. return fmt.Sprintf("issue has open dependencies [issue id: %d]", err.IssueID)
  1261. }
  1262. // ErrUnknownDependencyType represents an error where an unknown dependency type was passed
  1263. type ErrUnknownDependencyType struct {
  1264. Type DependencyType
  1265. }
  1266. // IsErrUnknownDependencyType checks if an error is ErrUnknownDependencyType
  1267. func IsErrUnknownDependencyType(err error) bool {
  1268. _, ok := err.(ErrUnknownDependencyType)
  1269. return ok
  1270. }
  1271. func (err ErrUnknownDependencyType) Error() string {
  1272. return fmt.Sprintf("unknown dependency type [type: %d]", err.Type)
  1273. }
  1274. // __________ .__
  1275. // \______ \ _______ _|__| ______ _ __
  1276. // | _// __ \ \/ / |/ __ \ \/ \/ /
  1277. // | | \ ___/\ /| \ ___/\ /
  1278. // |____|_ /\___ >\_/ |__|\___ >\/\_/
  1279. // \/ \/ \/
  1280. // ErrReviewNotExist represents a "ReviewNotExist" kind of error.
  1281. type ErrReviewNotExist struct {
  1282. ID int64
  1283. }
  1284. // IsErrReviewNotExist checks if an error is a ErrReviewNotExist.
  1285. func IsErrReviewNotExist(err error) bool {
  1286. _, ok := err.(ErrReviewNotExist)
  1287. return ok
  1288. }
  1289. func (err ErrReviewNotExist) Error() string {
  1290. return fmt.Sprintf("review does not exist [id: %d]", err.ID)
  1291. }
  1292. // ________ _____ __ .__
  1293. // \_____ \ / _ \ __ ___/ |_| |__
  1294. // / | \ / /_\ \| | \ __\ | \
  1295. // / | \/ | \ | /| | | Y \
  1296. // \_______ /\____|__ /____/ |__| |___| /
  1297. // \/ \/ \/
  1298. // ErrOAuthClientIDInvalid will be thrown if client id cannot be found
  1299. type ErrOAuthClientIDInvalid struct {
  1300. ClientID string
  1301. }
  1302. // IsErrOauthClientIDInvalid checks if an error is a ErrReviewNotExist.
  1303. func IsErrOauthClientIDInvalid(err error) bool {
  1304. _, ok := err.(ErrOAuthClientIDInvalid)
  1305. return ok
  1306. }
  1307. // Error returns the error message
  1308. func (err ErrOAuthClientIDInvalid) Error() string {
  1309. return fmt.Sprintf("Client ID invalid [Client ID: %s]", err.ClientID)
  1310. }
  1311. // ErrOAuthApplicationNotFound will be thrown if id cannot be found
  1312. type ErrOAuthApplicationNotFound struct {
  1313. ID int64
  1314. }
  1315. // IsErrOAuthApplicationNotFound checks if an error is a ErrReviewNotExist.
  1316. func IsErrOAuthApplicationNotFound(err error) bool {
  1317. _, ok := err.(ErrOAuthApplicationNotFound)
  1318. return ok
  1319. }
  1320. // Error returns the error message
  1321. func (err ErrOAuthApplicationNotFound) Error() string {
  1322. return fmt.Sprintf("OAuth application not found [ID: %d]", err.ID)
  1323. }