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 64KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  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. // ErrNotExist represents a non-exist error.
  11. type ErrNotExist struct {
  12. ID int64
  13. }
  14. // IsErrNotExist checks if an error is an ErrNotExist
  15. func IsErrNotExist(err error) bool {
  16. _, ok := err.(ErrNotExist)
  17. return ok
  18. }
  19. func (err ErrNotExist) Error() string {
  20. return fmt.Sprintf("record does not exist [id: %d]", err.ID)
  21. }
  22. // ErrNameReserved represents a "reserved name" error.
  23. type ErrNameReserved struct {
  24. Name string
  25. }
  26. // IsErrNameReserved checks if an error is a ErrNameReserved.
  27. func IsErrNameReserved(err error) bool {
  28. _, ok := err.(ErrNameReserved)
  29. return ok
  30. }
  31. func (err ErrNameReserved) Error() string {
  32. return fmt.Sprintf("name is reserved [name: %s]", err.Name)
  33. }
  34. // ErrNamePatternNotAllowed represents a "pattern not allowed" error.
  35. type ErrNamePatternNotAllowed struct {
  36. Pattern string
  37. }
  38. // IsErrNamePatternNotAllowed checks if an error is an ErrNamePatternNotAllowed.
  39. func IsErrNamePatternNotAllowed(err error) bool {
  40. _, ok := err.(ErrNamePatternNotAllowed)
  41. return ok
  42. }
  43. func (err ErrNamePatternNotAllowed) Error() string {
  44. return fmt.Sprintf("name pattern is not allowed [pattern: %s]", err.Pattern)
  45. }
  46. // ErrNameCharsNotAllowed represents a "character not allowed in name" error.
  47. type ErrNameCharsNotAllowed struct {
  48. Name string
  49. }
  50. // IsErrNameCharsNotAllowed checks if an error is an ErrNameCharsNotAllowed.
  51. func IsErrNameCharsNotAllowed(err error) bool {
  52. _, ok := err.(ErrNameCharsNotAllowed)
  53. return ok
  54. }
  55. func (err ErrNameCharsNotAllowed) Error() string {
  56. return fmt.Sprintf("User name is invalid [%s]: must be valid alpha or numeric or dash(-_) or dot characters", err.Name)
  57. }
  58. // ErrSSHDisabled represents an "SSH disabled" error.
  59. type ErrSSHDisabled struct{}
  60. // IsErrSSHDisabled checks if an error is a ErrSSHDisabled.
  61. func IsErrSSHDisabled(err error) bool {
  62. _, ok := err.(ErrSSHDisabled)
  63. return ok
  64. }
  65. func (err ErrSSHDisabled) Error() string {
  66. return "SSH is disabled"
  67. }
  68. // ErrCancelled represents an error due to context cancellation
  69. type ErrCancelled struct {
  70. Message string
  71. }
  72. // IsErrCancelled checks if an error is a ErrCancelled.
  73. func IsErrCancelled(err error) bool {
  74. _, ok := err.(ErrCancelled)
  75. return ok
  76. }
  77. func (err ErrCancelled) Error() string {
  78. return "Cancelled: " + err.Message
  79. }
  80. // ErrCancelledf returns an ErrCancelled for the provided format and args
  81. func ErrCancelledf(format string, args ...interface{}) error {
  82. return ErrCancelled{
  83. fmt.Sprintf(format, args...),
  84. }
  85. }
  86. // ____ ___
  87. // | | \______ ___________
  88. // | | / ___// __ \_ __ \
  89. // | | /\___ \\ ___/| | \/
  90. // |______//____ >\___ >__|
  91. // \/ \/
  92. // ErrUserAlreadyExist represents a "user already exists" error.
  93. type ErrUserAlreadyExist struct {
  94. Name string
  95. }
  96. // IsErrUserAlreadyExist checks if an error is a ErrUserAlreadyExists.
  97. func IsErrUserAlreadyExist(err error) bool {
  98. _, ok := err.(ErrUserAlreadyExist)
  99. return ok
  100. }
  101. func (err ErrUserAlreadyExist) Error() string {
  102. return fmt.Sprintf("user already exists [name: %s]", err.Name)
  103. }
  104. // ErrUserNotExist represents a "UserNotExist" kind of error.
  105. type ErrUserNotExist struct {
  106. UID int64
  107. Name string
  108. KeyID int64
  109. }
  110. // IsErrUserNotExist checks if an error is a ErrUserNotExist.
  111. func IsErrUserNotExist(err error) bool {
  112. _, ok := err.(ErrUserNotExist)
  113. return ok
  114. }
  115. func (err ErrUserNotExist) Error() string {
  116. return fmt.Sprintf("user does not exist [uid: %d, name: %s, keyid: %d]", err.UID, err.Name, err.KeyID)
  117. }
  118. // ErrUserRedirectNotExist represents a "UserRedirectNotExist" kind of error.
  119. type ErrUserRedirectNotExist struct {
  120. Name string
  121. }
  122. // IsErrUserRedirectNotExist check if an error is an ErrUserRedirectNotExist.
  123. func IsErrUserRedirectNotExist(err error) bool {
  124. _, ok := err.(ErrUserRedirectNotExist)
  125. return ok
  126. }
  127. func (err ErrUserRedirectNotExist) Error() string {
  128. return fmt.Sprintf("user redirect does not exist [name: %s]", err.Name)
  129. }
  130. // ErrUserProhibitLogin represents a "ErrUserProhibitLogin" kind of error.
  131. type ErrUserProhibitLogin struct {
  132. UID int64
  133. Name string
  134. }
  135. // IsErrUserProhibitLogin checks if an error is a ErrUserProhibitLogin
  136. func IsErrUserProhibitLogin(err error) bool {
  137. _, ok := err.(ErrUserProhibitLogin)
  138. return ok
  139. }
  140. func (err ErrUserProhibitLogin) Error() string {
  141. return fmt.Sprintf("user is not allowed login [uid: %d, name: %s]", err.UID, err.Name)
  142. }
  143. // ErrUserInactive represents a "ErrUserInactive" kind of error.
  144. type ErrUserInactive struct {
  145. UID int64
  146. Name string
  147. }
  148. // IsErrUserInactive checks if an error is a ErrUserInactive
  149. func IsErrUserInactive(err error) bool {
  150. _, ok := err.(ErrUserInactive)
  151. return ok
  152. }
  153. func (err ErrUserInactive) Error() string {
  154. return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
  155. }
  156. // ErrEmailAlreadyUsed represents a "EmailAlreadyUsed" kind of error.
  157. type ErrEmailAlreadyUsed struct {
  158. Email string
  159. }
  160. // IsErrEmailAlreadyUsed checks if an error is a ErrEmailAlreadyUsed.
  161. func IsErrEmailAlreadyUsed(err error) bool {
  162. _, ok := err.(ErrEmailAlreadyUsed)
  163. return ok
  164. }
  165. func (err ErrEmailAlreadyUsed) Error() string {
  166. return fmt.Sprintf("e-mail already in use [email: %s]", err.Email)
  167. }
  168. // ErrEmailInvalid represents an error where the email address does not comply with RFC 5322
  169. type ErrEmailInvalid struct {
  170. Email string
  171. }
  172. // IsErrEmailInvalid checks if an error is an ErrEmailInvalid
  173. func IsErrEmailInvalid(err error) bool {
  174. _, ok := err.(ErrEmailInvalid)
  175. return ok
  176. }
  177. func (err ErrEmailInvalid) Error() string {
  178. return fmt.Sprintf("e-mail invalid [email: %s]", err.Email)
  179. }
  180. // ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
  181. type ErrOpenIDAlreadyUsed struct {
  182. OpenID string
  183. }
  184. // IsErrOpenIDAlreadyUsed checks if an error is a ErrOpenIDAlreadyUsed.
  185. func IsErrOpenIDAlreadyUsed(err error) bool {
  186. _, ok := err.(ErrOpenIDAlreadyUsed)
  187. return ok
  188. }
  189. func (err ErrOpenIDAlreadyUsed) Error() string {
  190. return fmt.Sprintf("OpenID already in use [oid: %s]", err.OpenID)
  191. }
  192. // ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
  193. type ErrUserOwnRepos struct {
  194. UID int64
  195. }
  196. // IsErrUserOwnRepos checks if an error is a ErrUserOwnRepos.
  197. func IsErrUserOwnRepos(err error) bool {
  198. _, ok := err.(ErrUserOwnRepos)
  199. return ok
  200. }
  201. func (err ErrUserOwnRepos) Error() string {
  202. return fmt.Sprintf("user still has ownership of repositories [uid: %d]", err.UID)
  203. }
  204. // ErrUserHasOrgs represents a "UserHasOrgs" kind of error.
  205. type ErrUserHasOrgs struct {
  206. UID int64
  207. }
  208. // IsErrUserHasOrgs checks if an error is a ErrUserHasOrgs.
  209. func IsErrUserHasOrgs(err error) bool {
  210. _, ok := err.(ErrUserHasOrgs)
  211. return ok
  212. }
  213. func (err ErrUserHasOrgs) Error() string {
  214. return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
  215. }
  216. // ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error.
  217. type ErrUserNotAllowedCreateOrg struct{}
  218. // IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg.
  219. func IsErrUserNotAllowedCreateOrg(err error) bool {
  220. _, ok := err.(ErrUserNotAllowedCreateOrg)
  221. return ok
  222. }
  223. func (err ErrUserNotAllowedCreateOrg) Error() string {
  224. return "user is not allowed to create organizations"
  225. }
  226. // ErrReachLimitOfRepo represents a "ReachLimitOfRepo" kind of error.
  227. type ErrReachLimitOfRepo struct {
  228. Limit int
  229. }
  230. // IsErrReachLimitOfRepo checks if an error is a ErrReachLimitOfRepo.
  231. func IsErrReachLimitOfRepo(err error) bool {
  232. _, ok := err.(ErrReachLimitOfRepo)
  233. return ok
  234. }
  235. func (err ErrReachLimitOfRepo) Error() string {
  236. return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
  237. }
  238. // __ __.__ __ .__
  239. // / \ / \__| | _|__|
  240. // \ \/\/ / | |/ / |
  241. // \ /| | <| |
  242. // \__/\ / |__|__|_ \__|
  243. // \/ \/
  244. // ErrWikiAlreadyExist represents a "WikiAlreadyExist" kind of error.
  245. type ErrWikiAlreadyExist struct {
  246. Title string
  247. }
  248. // IsErrWikiAlreadyExist checks if an error is an ErrWikiAlreadyExist.
  249. func IsErrWikiAlreadyExist(err error) bool {
  250. _, ok := err.(ErrWikiAlreadyExist)
  251. return ok
  252. }
  253. func (err ErrWikiAlreadyExist) Error() string {
  254. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  255. }
  256. // ErrWikiReservedName represents a reserved name error.
  257. type ErrWikiReservedName struct {
  258. Title string
  259. }
  260. // IsErrWikiReservedName checks if an error is an ErrWikiReservedName.
  261. func IsErrWikiReservedName(err error) bool {
  262. _, ok := err.(ErrWikiReservedName)
  263. return ok
  264. }
  265. func (err ErrWikiReservedName) Error() string {
  266. return fmt.Sprintf("wiki title is reserved: %s", err.Title)
  267. }
  268. // ErrWikiInvalidFileName represents an invalid wiki file name.
  269. type ErrWikiInvalidFileName struct {
  270. FileName string
  271. }
  272. // IsErrWikiInvalidFileName checks if an error is an ErrWikiInvalidFileName.
  273. func IsErrWikiInvalidFileName(err error) bool {
  274. _, ok := err.(ErrWikiInvalidFileName)
  275. return ok
  276. }
  277. func (err ErrWikiInvalidFileName) Error() string {
  278. return fmt.Sprintf("Invalid wiki filename: %s", err.FileName)
  279. }
  280. // __________ ___. .__ .__ ____ __.
  281. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  282. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  283. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  284. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  285. // \/ \/ \/ \/\/
  286. // ErrKeyUnableVerify represents a "KeyUnableVerify" kind of error.
  287. type ErrKeyUnableVerify struct {
  288. Result string
  289. }
  290. // IsErrKeyUnableVerify checks if an error is a ErrKeyUnableVerify.
  291. func IsErrKeyUnableVerify(err error) bool {
  292. _, ok := err.(ErrKeyUnableVerify)
  293. return ok
  294. }
  295. func (err ErrKeyUnableVerify) Error() string {
  296. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  297. }
  298. // ErrKeyNotExist represents a "KeyNotExist" kind of error.
  299. type ErrKeyNotExist struct {
  300. ID int64
  301. }
  302. // IsErrKeyNotExist checks if an error is a ErrKeyNotExist.
  303. func IsErrKeyNotExist(err error) bool {
  304. _, ok := err.(ErrKeyNotExist)
  305. return ok
  306. }
  307. func (err ErrKeyNotExist) Error() string {
  308. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  309. }
  310. // ErrKeyAlreadyExist represents a "KeyAlreadyExist" kind of error.
  311. type ErrKeyAlreadyExist struct {
  312. OwnerID int64
  313. Fingerprint string
  314. Content string
  315. }
  316. // IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.
  317. func IsErrKeyAlreadyExist(err error) bool {
  318. _, ok := err.(ErrKeyAlreadyExist)
  319. return ok
  320. }
  321. func (err ErrKeyAlreadyExist) Error() string {
  322. return fmt.Sprintf("public key already exists [owner_id: %d, finger_print: %s, content: %s]",
  323. err.OwnerID, err.Fingerprint, err.Content)
  324. }
  325. // ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
  326. type ErrKeyNameAlreadyUsed struct {
  327. OwnerID int64
  328. Name string
  329. }
  330. // IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  331. func IsErrKeyNameAlreadyUsed(err error) bool {
  332. _, ok := err.(ErrKeyNameAlreadyUsed)
  333. return ok
  334. }
  335. func (err ErrKeyNameAlreadyUsed) Error() string {
  336. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  337. }
  338. // ErrGPGNoEmailFound represents a "ErrGPGNoEmailFound" kind of error.
  339. type ErrGPGNoEmailFound struct {
  340. FailedEmails []string
  341. }
  342. // IsErrGPGNoEmailFound checks if an error is a ErrGPGNoEmailFound.
  343. func IsErrGPGNoEmailFound(err error) bool {
  344. _, ok := err.(ErrGPGNoEmailFound)
  345. return ok
  346. }
  347. func (err ErrGPGNoEmailFound) Error() string {
  348. return fmt.Sprintf("none of the emails attached to the GPG key could be found: %v", err.FailedEmails)
  349. }
  350. // ErrGPGKeyParsing represents a "ErrGPGKeyParsing" kind of error.
  351. type ErrGPGKeyParsing struct {
  352. ParseError error
  353. }
  354. // IsErrGPGKeyParsing checks if an error is a ErrGPGKeyParsing.
  355. func IsErrGPGKeyParsing(err error) bool {
  356. _, ok := err.(ErrGPGKeyParsing)
  357. return ok
  358. }
  359. func (err ErrGPGKeyParsing) Error() string {
  360. return fmt.Sprintf("failed to parse gpg key %s", err.ParseError.Error())
  361. }
  362. // ErrGPGKeyNotExist represents a "GPGKeyNotExist" kind of error.
  363. type ErrGPGKeyNotExist struct {
  364. ID int64
  365. }
  366. // IsErrGPGKeyNotExist checks if an error is a ErrGPGKeyNotExist.
  367. func IsErrGPGKeyNotExist(err error) bool {
  368. _, ok := err.(ErrGPGKeyNotExist)
  369. return ok
  370. }
  371. func (err ErrGPGKeyNotExist) Error() string {
  372. return fmt.Sprintf("public gpg key does not exist [id: %d]", err.ID)
  373. }
  374. // ErrGPGKeyImportNotExist represents a "GPGKeyImportNotExist" kind of error.
  375. type ErrGPGKeyImportNotExist struct {
  376. ID string
  377. }
  378. // IsErrGPGKeyImportNotExist checks if an error is a ErrGPGKeyImportNotExist.
  379. func IsErrGPGKeyImportNotExist(err error) bool {
  380. _, ok := err.(ErrGPGKeyImportNotExist)
  381. return ok
  382. }
  383. func (err ErrGPGKeyImportNotExist) Error() string {
  384. return fmt.Sprintf("public gpg key import does not exist [id: %s]", err.ID)
  385. }
  386. // ErrGPGKeyIDAlreadyUsed represents a "GPGKeyIDAlreadyUsed" kind of error.
  387. type ErrGPGKeyIDAlreadyUsed struct {
  388. KeyID string
  389. }
  390. // IsErrGPGKeyIDAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
  391. func IsErrGPGKeyIDAlreadyUsed(err error) bool {
  392. _, ok := err.(ErrGPGKeyIDAlreadyUsed)
  393. return ok
  394. }
  395. func (err ErrGPGKeyIDAlreadyUsed) Error() string {
  396. return fmt.Sprintf("public key already exists [key_id: %s]", err.KeyID)
  397. }
  398. // ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error.
  399. type ErrGPGKeyAccessDenied struct {
  400. UserID int64
  401. KeyID int64
  402. }
  403. // IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.
  404. func IsErrGPGKeyAccessDenied(err error) bool {
  405. _, ok := err.(ErrGPGKeyAccessDenied)
  406. return ok
  407. }
  408. // Error pretty-prints an error of type ErrGPGKeyAccessDenied.
  409. func (err ErrGPGKeyAccessDenied) Error() string {
  410. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d]",
  411. err.UserID, err.KeyID)
  412. }
  413. // ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
  414. type ErrKeyAccessDenied struct {
  415. UserID int64
  416. KeyID int64
  417. Note string
  418. }
  419. // IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.
  420. func IsErrKeyAccessDenied(err error) bool {
  421. _, ok := err.(ErrKeyAccessDenied)
  422. return ok
  423. }
  424. func (err ErrKeyAccessDenied) Error() string {
  425. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  426. err.UserID, err.KeyID, err.Note)
  427. }
  428. // ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
  429. type ErrDeployKeyNotExist struct {
  430. ID int64
  431. KeyID int64
  432. RepoID int64
  433. }
  434. // IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.
  435. func IsErrDeployKeyNotExist(err error) bool {
  436. _, ok := err.(ErrDeployKeyNotExist)
  437. return ok
  438. }
  439. func (err ErrDeployKeyNotExist) Error() string {
  440. return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
  441. }
  442. // ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
  443. type ErrDeployKeyAlreadyExist struct {
  444. KeyID int64
  445. RepoID int64
  446. }
  447. // IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.
  448. func IsErrDeployKeyAlreadyExist(err error) bool {
  449. _, ok := err.(ErrDeployKeyAlreadyExist)
  450. return ok
  451. }
  452. func (err ErrDeployKeyAlreadyExist) Error() string {
  453. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  454. }
  455. // ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
  456. type ErrDeployKeyNameAlreadyUsed struct {
  457. RepoID int64
  458. Name string
  459. }
  460. // IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.
  461. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  462. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  463. return ok
  464. }
  465. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  466. return fmt.Sprintf("public key with name already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  467. }
  468. // _____ ___________ __
  469. // / _ \ ____ ____ ____ ______ _____\__ ___/___ | | __ ____ ____
  470. // / /_\ \_/ ___\/ ___\/ __ \ / ___// ___/ | | / _ \| |/ // __ \ / \
  471. // / | \ \__\ \__\ ___/ \___ \ \___ \ | |( <_> ) <\ ___/| | \
  472. // \____|__ /\___ >___ >___ >____ >____ > |____| \____/|__|_ \\___ >___| /
  473. // \/ \/ \/ \/ \/ \/ \/ \/ \/
  474. // ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.
  475. type ErrAccessTokenNotExist struct {
  476. Token string
  477. }
  478. // IsErrAccessTokenNotExist checks if an error is a ErrAccessTokenNotExist.
  479. func IsErrAccessTokenNotExist(err error) bool {
  480. _, ok := err.(ErrAccessTokenNotExist)
  481. return ok
  482. }
  483. func (err ErrAccessTokenNotExist) Error() string {
  484. return fmt.Sprintf("access token does not exist [sha: %s]", err.Token)
  485. }
  486. // ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
  487. type ErrAccessTokenEmpty struct{}
  488. // IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
  489. func IsErrAccessTokenEmpty(err error) bool {
  490. _, ok := err.(ErrAccessTokenEmpty)
  491. return ok
  492. }
  493. func (err ErrAccessTokenEmpty) Error() string {
  494. return "access token is empty"
  495. }
  496. // ________ .__ __ .__
  497. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  498. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  499. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  500. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  501. // \/ /_____/ \/ \/ \/ \/ \/
  502. // ErrOrgNotExist represents a "OrgNotExist" kind of error.
  503. type ErrOrgNotExist struct {
  504. ID int64
  505. Name string
  506. }
  507. // IsErrOrgNotExist checks if an error is a ErrOrgNotExist.
  508. func IsErrOrgNotExist(err error) bool {
  509. _, ok := err.(ErrOrgNotExist)
  510. return ok
  511. }
  512. func (err ErrOrgNotExist) Error() string {
  513. return fmt.Sprintf("org does not exist [id: %d, name: %s]", err.ID, err.Name)
  514. }
  515. // ErrLastOrgOwner represents a "LastOrgOwner" kind of error.
  516. type ErrLastOrgOwner struct {
  517. UID int64
  518. }
  519. // IsErrLastOrgOwner checks if an error is a ErrLastOrgOwner.
  520. func IsErrLastOrgOwner(err error) bool {
  521. _, ok := err.(ErrLastOrgOwner)
  522. return ok
  523. }
  524. func (err ErrLastOrgOwner) Error() string {
  525. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  526. }
  527. //.____ ____________________
  528. //| | \_ _____/ _____/
  529. //| | | __) \_____ \
  530. //| |___| \ / \
  531. //|_______ \___ / /_______ /
  532. // \/ \/ \/
  533. // ErrLFSLockNotExist represents a "LFSLockNotExist" kind of error.
  534. type ErrLFSLockNotExist struct {
  535. ID int64
  536. RepoID int64
  537. Path string
  538. }
  539. // IsErrLFSLockNotExist checks if an error is a ErrLFSLockNotExist.
  540. func IsErrLFSLockNotExist(err error) bool {
  541. _, ok := err.(ErrLFSLockNotExist)
  542. return ok
  543. }
  544. func (err ErrLFSLockNotExist) Error() string {
  545. return fmt.Sprintf("lfs lock does not exist [id: %d, rid: %d, path: %s]", err.ID, err.RepoID, err.Path)
  546. }
  547. // ErrLFSUnauthorizedAction represents a "LFSUnauthorizedAction" kind of error.
  548. type ErrLFSUnauthorizedAction struct {
  549. RepoID int64
  550. UserName string
  551. Mode AccessMode
  552. }
  553. // IsErrLFSUnauthorizedAction checks if an error is a ErrLFSUnauthorizedAction.
  554. func IsErrLFSUnauthorizedAction(err error) bool {
  555. _, ok := err.(ErrLFSUnauthorizedAction)
  556. return ok
  557. }
  558. func (err ErrLFSUnauthorizedAction) Error() string {
  559. if err.Mode == AccessModeWrite {
  560. return fmt.Sprintf("User %s doesn't have write access for lfs lock [rid: %d]", err.UserName, err.RepoID)
  561. }
  562. return fmt.Sprintf("User %s doesn't have read access for lfs lock [rid: %d]", err.UserName, err.RepoID)
  563. }
  564. // ErrLFSLockAlreadyExist represents a "LFSLockAlreadyExist" kind of error.
  565. type ErrLFSLockAlreadyExist struct {
  566. RepoID int64
  567. Path string
  568. }
  569. // IsErrLFSLockAlreadyExist checks if an error is a ErrLFSLockAlreadyExist.
  570. func IsErrLFSLockAlreadyExist(err error) bool {
  571. _, ok := err.(ErrLFSLockAlreadyExist)
  572. return ok
  573. }
  574. func (err ErrLFSLockAlreadyExist) Error() string {
  575. return fmt.Sprintf("lfs lock already exists [rid: %d, path: %s]", err.RepoID, err.Path)
  576. }
  577. // ErrLFSFileLocked represents a "LFSFileLocked" kind of error.
  578. type ErrLFSFileLocked struct {
  579. RepoID int64
  580. Path string
  581. UserName string
  582. }
  583. // IsErrLFSFileLocked checks if an error is a ErrLFSFileLocked.
  584. func IsErrLFSFileLocked(err error) bool {
  585. _, ok := err.(ErrLFSFileLocked)
  586. return ok
  587. }
  588. func (err ErrLFSFileLocked) Error() string {
  589. return fmt.Sprintf("File is lfs locked [repo: %d, locked by: %s, path: %s]", err.RepoID, err.UserName, err.Path)
  590. }
  591. // __________ .__ __
  592. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  593. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  594. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  595. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  596. // \/ \/|__| \/ \/
  597. // ErrRepoNotExist represents a "RepoNotExist" kind of error.
  598. type ErrRepoNotExist struct {
  599. ID int64
  600. UID int64
  601. OwnerName string
  602. Name string
  603. }
  604. // IsErrRepoNotExist checks if an error is a ErrRepoNotExist.
  605. func IsErrRepoNotExist(err error) bool {
  606. _, ok := err.(ErrRepoNotExist)
  607. return ok
  608. }
  609. func (err ErrRepoNotExist) Error() string {
  610. return fmt.Sprintf("repository does not exist [id: %d, uid: %d, owner_name: %s, name: %s]",
  611. err.ID, err.UID, err.OwnerName, err.Name)
  612. }
  613. // ErrNoPendingRepoTransfer is an error type for repositories without a pending
  614. // transfer request
  615. type ErrNoPendingRepoTransfer struct {
  616. RepoID int64
  617. }
  618. func (e ErrNoPendingRepoTransfer) Error() string {
  619. return fmt.Sprintf("repository doesn't have a pending transfer [repo_id: %d]", e.RepoID)
  620. }
  621. // IsErrNoPendingTransfer is an error type when a repository has no pending
  622. // transfers
  623. func IsErrNoPendingTransfer(err error) bool {
  624. _, ok := err.(ErrNoPendingRepoTransfer)
  625. return ok
  626. }
  627. // ErrRepoTransferInProgress represents the state of a repository that has an
  628. // ongoing transfer
  629. type ErrRepoTransferInProgress struct {
  630. Uname string
  631. Name string
  632. }
  633. // IsErrRepoTransferInProgress checks if an error is a ErrRepoTransferInProgress.
  634. func IsErrRepoTransferInProgress(err error) bool {
  635. _, ok := err.(ErrRepoTransferInProgress)
  636. return ok
  637. }
  638. func (err ErrRepoTransferInProgress) Error() string {
  639. return fmt.Sprintf("repository is already being transferred [uname: %s, name: %s]", err.Uname, err.Name)
  640. }
  641. // ErrRepoAlreadyExist represents a "RepoAlreadyExist" kind of error.
  642. type ErrRepoAlreadyExist struct {
  643. Uname string
  644. Name string
  645. }
  646. // IsErrRepoAlreadyExist checks if an error is a ErrRepoAlreadyExist.
  647. func IsErrRepoAlreadyExist(err error) bool {
  648. _, ok := err.(ErrRepoAlreadyExist)
  649. return ok
  650. }
  651. func (err ErrRepoAlreadyExist) Error() string {
  652. return fmt.Sprintf("repository already exists [uname: %s, name: %s]", err.Uname, err.Name)
  653. }
  654. // ErrRepoFilesAlreadyExist represents a "RepoFilesAlreadyExist" kind of error.
  655. type ErrRepoFilesAlreadyExist struct {
  656. Uname string
  657. Name string
  658. }
  659. // IsErrRepoFilesAlreadyExist checks if an error is a ErrRepoAlreadyExist.
  660. func IsErrRepoFilesAlreadyExist(err error) bool {
  661. _, ok := err.(ErrRepoFilesAlreadyExist)
  662. return ok
  663. }
  664. func (err ErrRepoFilesAlreadyExist) Error() string {
  665. return fmt.Sprintf("repository files already exist [uname: %s, name: %s]", err.Uname, err.Name)
  666. }
  667. // ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error.
  668. type ErrForkAlreadyExist struct {
  669. Uname string
  670. RepoName string
  671. ForkName string
  672. }
  673. // IsErrForkAlreadyExist checks if an error is an ErrForkAlreadyExist.
  674. func IsErrForkAlreadyExist(err error) bool {
  675. _, ok := err.(ErrForkAlreadyExist)
  676. return ok
  677. }
  678. func (err ErrForkAlreadyExist) Error() string {
  679. return fmt.Sprintf("repository is already forked by user [uname: %s, repo path: %s, fork path: %s]", err.Uname, err.RepoName, err.ForkName)
  680. }
  681. // ErrRepoRedirectNotExist represents a "RepoRedirectNotExist" kind of error.
  682. type ErrRepoRedirectNotExist struct {
  683. OwnerID int64
  684. RepoName string
  685. }
  686. // IsErrRepoRedirectNotExist check if an error is an ErrRepoRedirectNotExist.
  687. func IsErrRepoRedirectNotExist(err error) bool {
  688. _, ok := err.(ErrRepoRedirectNotExist)
  689. return ok
  690. }
  691. func (err ErrRepoRedirectNotExist) Error() string {
  692. return fmt.Sprintf("repository redirect does not exist [uid: %d, name: %s]", err.OwnerID, err.RepoName)
  693. }
  694. // ErrInvalidCloneAddr represents a "InvalidCloneAddr" kind of error.
  695. type ErrInvalidCloneAddr struct {
  696. Host string
  697. IsURLError bool
  698. IsInvalidPath bool
  699. IsProtocolInvalid bool
  700. IsPermissionDenied bool
  701. LocalPath bool
  702. NotResolvedIP bool
  703. PrivateNet string
  704. }
  705. // IsErrInvalidCloneAddr checks if an error is a ErrInvalidCloneAddr.
  706. func IsErrInvalidCloneAddr(err error) bool {
  707. _, ok := err.(*ErrInvalidCloneAddr)
  708. return ok
  709. }
  710. func (err *ErrInvalidCloneAddr) Error() string {
  711. if err.NotResolvedIP {
  712. return fmt.Sprintf("migration/cloning from '%s' is not allowed: unknown hostname", err.Host)
  713. }
  714. if len(err.PrivateNet) != 0 {
  715. return fmt.Sprintf("migration/cloning from '%s' is not allowed: the host resolve to a private ip address '%s'", err.Host, err.PrivateNet)
  716. }
  717. if err.IsInvalidPath {
  718. return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided path is invalid", err.Host)
  719. }
  720. if err.IsProtocolInvalid {
  721. return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided url protocol is not allowed", err.Host)
  722. }
  723. if err.IsPermissionDenied {
  724. return fmt.Sprintf("migration/cloning from '%s' is not allowed.", err.Host)
  725. }
  726. if err.IsURLError {
  727. return fmt.Sprintf("migration/cloning from '%s' is not allowed: the provided url is invalid", err.Host)
  728. }
  729. return fmt.Sprintf("migration/cloning from '%s' is not allowed", err.Host)
  730. }
  731. // ErrUpdateTaskNotExist represents a "UpdateTaskNotExist" kind of error.
  732. type ErrUpdateTaskNotExist struct {
  733. UUID string
  734. }
  735. // IsErrUpdateTaskNotExist checks if an error is a ErrUpdateTaskNotExist.
  736. func IsErrUpdateTaskNotExist(err error) bool {
  737. _, ok := err.(ErrUpdateTaskNotExist)
  738. return ok
  739. }
  740. func (err ErrUpdateTaskNotExist) Error() string {
  741. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  742. }
  743. // ErrReleaseAlreadyExist represents a "ReleaseAlreadyExist" kind of error.
  744. type ErrReleaseAlreadyExist struct {
  745. TagName string
  746. }
  747. // IsErrReleaseAlreadyExist checks if an error is a ErrReleaseAlreadyExist.
  748. func IsErrReleaseAlreadyExist(err error) bool {
  749. _, ok := err.(ErrReleaseAlreadyExist)
  750. return ok
  751. }
  752. func (err ErrReleaseAlreadyExist) Error() string {
  753. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  754. }
  755. // ErrReleaseNotExist represents a "ReleaseNotExist" kind of error.
  756. type ErrReleaseNotExist struct {
  757. ID int64
  758. TagName string
  759. }
  760. // IsErrReleaseNotExist checks if an error is a ErrReleaseNotExist.
  761. func IsErrReleaseNotExist(err error) bool {
  762. _, ok := err.(ErrReleaseNotExist)
  763. return ok
  764. }
  765. func (err ErrReleaseNotExist) Error() string {
  766. return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
  767. }
  768. // ErrInvalidTagName represents a "InvalidTagName" kind of error.
  769. type ErrInvalidTagName struct {
  770. TagName string
  771. }
  772. // IsErrInvalidTagName checks if an error is a ErrInvalidTagName.
  773. func IsErrInvalidTagName(err error) bool {
  774. _, ok := err.(ErrInvalidTagName)
  775. return ok
  776. }
  777. func (err ErrInvalidTagName) Error() string {
  778. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  779. }
  780. // ErrRepoFileAlreadyExists represents a "RepoFileAlreadyExist" kind of error.
  781. type ErrRepoFileAlreadyExists struct {
  782. Path string
  783. }
  784. // IsErrRepoFileAlreadyExists checks if an error is a ErrRepoFileAlreadyExists.
  785. func IsErrRepoFileAlreadyExists(err error) bool {
  786. _, ok := err.(ErrRepoFileAlreadyExists)
  787. return ok
  788. }
  789. func (err ErrRepoFileAlreadyExists) Error() string {
  790. return fmt.Sprintf("repository file already exists [path: %s]", err.Path)
  791. }
  792. // ErrRepoFileDoesNotExist represents a "RepoFileDoesNotExist" kind of error.
  793. type ErrRepoFileDoesNotExist struct {
  794. Path string
  795. Name string
  796. }
  797. // IsErrRepoFileDoesNotExist checks if an error is a ErrRepoDoesNotExist.
  798. func IsErrRepoFileDoesNotExist(err error) bool {
  799. _, ok := err.(ErrRepoFileDoesNotExist)
  800. return ok
  801. }
  802. func (err ErrRepoFileDoesNotExist) Error() string {
  803. return fmt.Sprintf("repository file does not exist [path: %s]", err.Path)
  804. }
  805. // ErrFilenameInvalid represents a "FilenameInvalid" kind of error.
  806. type ErrFilenameInvalid struct {
  807. Path string
  808. }
  809. // IsErrFilenameInvalid checks if an error is an ErrFilenameInvalid.
  810. func IsErrFilenameInvalid(err error) bool {
  811. _, ok := err.(ErrFilenameInvalid)
  812. return ok
  813. }
  814. func (err ErrFilenameInvalid) Error() string {
  815. return fmt.Sprintf("path contains a malformed path component [path: %s]", err.Path)
  816. }
  817. // ErrUserCannotCommit represents "UserCannotCommit" kind of error.
  818. type ErrUserCannotCommit struct {
  819. UserName string
  820. }
  821. // IsErrUserCannotCommit checks if an error is an ErrUserCannotCommit.
  822. func IsErrUserCannotCommit(err error) bool {
  823. _, ok := err.(ErrUserCannotCommit)
  824. return ok
  825. }
  826. func (err ErrUserCannotCommit) Error() string {
  827. return fmt.Sprintf("user cannot commit to repo [user: %s]", err.UserName)
  828. }
  829. // ErrFilePathInvalid represents a "FilePathInvalid" kind of error.
  830. type ErrFilePathInvalid struct {
  831. Message string
  832. Path string
  833. Name string
  834. Type git.EntryMode
  835. }
  836. // IsErrFilePathInvalid checks if an error is an ErrFilePathInvalid.
  837. func IsErrFilePathInvalid(err error) bool {
  838. _, ok := err.(ErrFilePathInvalid)
  839. return ok
  840. }
  841. func (err ErrFilePathInvalid) Error() string {
  842. if err.Message != "" {
  843. return err.Message
  844. }
  845. return fmt.Sprintf("path is invalid [path: %s]", err.Path)
  846. }
  847. // ErrFilePathProtected represents a "FilePathProtected" kind of error.
  848. type ErrFilePathProtected struct {
  849. Message string
  850. Path string
  851. }
  852. // IsErrFilePathProtected checks if an error is an ErrFilePathProtected.
  853. func IsErrFilePathProtected(err error) bool {
  854. _, ok := err.(ErrFilePathProtected)
  855. return ok
  856. }
  857. func (err ErrFilePathProtected) Error() string {
  858. if err.Message != "" {
  859. return err.Message
  860. }
  861. return fmt.Sprintf("path is protected and can not be changed [path: %s]", err.Path)
  862. }
  863. // ErrUserDoesNotHaveAccessToRepo represets an error where the user doesn't has access to a given repo.
  864. type ErrUserDoesNotHaveAccessToRepo struct {
  865. UserID int64
  866. RepoName string
  867. }
  868. // IsErrUserDoesNotHaveAccessToRepo checks if an error is a ErrRepoFileAlreadyExists.
  869. func IsErrUserDoesNotHaveAccessToRepo(err error) bool {
  870. _, ok := err.(ErrUserDoesNotHaveAccessToRepo)
  871. return ok
  872. }
  873. func (err ErrUserDoesNotHaveAccessToRepo) Error() string {
  874. return fmt.Sprintf("user doesn't have acces to repo [user_id: %d, repo_name: %s]", err.UserID, err.RepoName)
  875. }
  876. // ErrWontSign explains the first reason why a commit would not be signed
  877. // There may be other reasons - this is just the first reason found
  878. type ErrWontSign struct {
  879. Reason signingMode
  880. }
  881. func (e *ErrWontSign) Error() string {
  882. return fmt.Sprintf("wont sign: %s", e.Reason)
  883. }
  884. // IsErrWontSign checks if an error is a ErrWontSign
  885. func IsErrWontSign(err error) bool {
  886. _, ok := err.(*ErrWontSign)
  887. return ok
  888. }
  889. // __________ .__
  890. // \______ \____________ ____ ____ | |__
  891. // | | _/\_ __ \__ \ / \_/ ___\| | \
  892. // | | \ | | \// __ \| | \ \___| Y \
  893. // |______ / |__| (____ /___| /\___ >___| /
  894. // \/ \/ \/ \/ \/
  895. // ErrBranchDoesNotExist represents an error that branch with such name does not exist.
  896. type ErrBranchDoesNotExist struct {
  897. BranchName string
  898. }
  899. // IsErrBranchDoesNotExist checks if an error is an ErrBranchDoesNotExist.
  900. func IsErrBranchDoesNotExist(err error) bool {
  901. _, ok := err.(ErrBranchDoesNotExist)
  902. return ok
  903. }
  904. func (err ErrBranchDoesNotExist) Error() string {
  905. return fmt.Sprintf("branch does not exist [name: %s]", err.BranchName)
  906. }
  907. // ErrBranchAlreadyExists represents an error that branch with such name already exists.
  908. type ErrBranchAlreadyExists struct {
  909. BranchName string
  910. }
  911. // IsErrBranchAlreadyExists checks if an error is an ErrBranchAlreadyExists.
  912. func IsErrBranchAlreadyExists(err error) bool {
  913. _, ok := err.(ErrBranchAlreadyExists)
  914. return ok
  915. }
  916. func (err ErrBranchAlreadyExists) Error() string {
  917. return fmt.Sprintf("branch already exists [name: %s]", err.BranchName)
  918. }
  919. // ErrBranchNameConflict represents an error that branch name conflicts with other branch.
  920. type ErrBranchNameConflict struct {
  921. BranchName string
  922. }
  923. // IsErrBranchNameConflict checks if an error is an ErrBranchNameConflict.
  924. func IsErrBranchNameConflict(err error) bool {
  925. _, ok := err.(ErrBranchNameConflict)
  926. return ok
  927. }
  928. func (err ErrBranchNameConflict) Error() string {
  929. return fmt.Sprintf("branch conflicts with existing branch [name: %s]", err.BranchName)
  930. }
  931. // ErrBranchesEqual represents an error that branch name conflicts with other branch.
  932. type ErrBranchesEqual struct {
  933. BaseBranchName string
  934. HeadBranchName string
  935. }
  936. // IsErrBranchesEqual checks if an error is an ErrBranchesEqual.
  937. func IsErrBranchesEqual(err error) bool {
  938. _, ok := err.(ErrBranchesEqual)
  939. return ok
  940. }
  941. func (err ErrBranchesEqual) Error() string {
  942. return fmt.Sprintf("branches are equal [head: %sm base: %s]", err.HeadBranchName, err.BaseBranchName)
  943. }
  944. // ErrNotAllowedToMerge represents an error that a branch is protected and the current user is not allowed to modify it.
  945. type ErrNotAllowedToMerge struct {
  946. Reason string
  947. }
  948. // IsErrNotAllowedToMerge checks if an error is an ErrNotAllowedToMerge.
  949. func IsErrNotAllowedToMerge(err error) bool {
  950. _, ok := err.(ErrNotAllowedToMerge)
  951. return ok
  952. }
  953. func (err ErrNotAllowedToMerge) Error() string {
  954. return fmt.Sprintf("not allowed to merge [reason: %s]", err.Reason)
  955. }
  956. // ErrTagAlreadyExists represents an error that tag with such name already exists.
  957. type ErrTagAlreadyExists struct {
  958. TagName string
  959. }
  960. // IsErrTagAlreadyExists checks if an error is an ErrTagAlreadyExists.
  961. func IsErrTagAlreadyExists(err error) bool {
  962. _, ok := err.(ErrTagAlreadyExists)
  963. return ok
  964. }
  965. func (err ErrTagAlreadyExists) Error() string {
  966. return fmt.Sprintf("tag already exists [name: %s]", err.TagName)
  967. }
  968. // ErrSHADoesNotMatch represents a "SHADoesNotMatch" kind of error.
  969. type ErrSHADoesNotMatch struct {
  970. Path string
  971. GivenSHA string
  972. CurrentSHA string
  973. }
  974. // IsErrSHADoesNotMatch checks if an error is a ErrSHADoesNotMatch.
  975. func IsErrSHADoesNotMatch(err error) bool {
  976. _, ok := err.(ErrSHADoesNotMatch)
  977. return ok
  978. }
  979. func (err ErrSHADoesNotMatch) Error() string {
  980. return fmt.Sprintf("sha does not match [given: %s, expected: %s]", err.GivenSHA, err.CurrentSHA)
  981. }
  982. // ErrSHANotFound represents a "SHADoesNotMatch" kind of error.
  983. type ErrSHANotFound struct {
  984. SHA string
  985. }
  986. // IsErrSHANotFound checks if an error is a ErrSHANotFound.
  987. func IsErrSHANotFound(err error) bool {
  988. _, ok := err.(ErrSHANotFound)
  989. return ok
  990. }
  991. func (err ErrSHANotFound) Error() string {
  992. return fmt.Sprintf("sha not found [%s]", err.SHA)
  993. }
  994. // ErrCommitIDDoesNotMatch represents a "CommitIDDoesNotMatch" kind of error.
  995. type ErrCommitIDDoesNotMatch struct {
  996. GivenCommitID string
  997. CurrentCommitID string
  998. }
  999. // IsErrCommitIDDoesNotMatch checks if an error is a ErrCommitIDDoesNotMatch.
  1000. func IsErrCommitIDDoesNotMatch(err error) bool {
  1001. _, ok := err.(ErrCommitIDDoesNotMatch)
  1002. return ok
  1003. }
  1004. func (err ErrCommitIDDoesNotMatch) Error() string {
  1005. return fmt.Sprintf("file CommitID does not match [given: %s, expected: %s]", err.GivenCommitID, err.CurrentCommitID)
  1006. }
  1007. // ErrSHAOrCommitIDNotProvided represents a "SHAOrCommitIDNotProvided" kind of error.
  1008. type ErrSHAOrCommitIDNotProvided struct{}
  1009. // IsErrSHAOrCommitIDNotProvided checks if an error is a ErrSHAOrCommitIDNotProvided.
  1010. func IsErrSHAOrCommitIDNotProvided(err error) bool {
  1011. _, ok := err.(ErrSHAOrCommitIDNotProvided)
  1012. return ok
  1013. }
  1014. func (err ErrSHAOrCommitIDNotProvided) Error() string {
  1015. return "a SHA or commmit ID must be proved when updating a file"
  1016. }
  1017. // __ __ ___. .__ __
  1018. // / \ / \ ____\_ |__ | |__ ____ ____ | | __
  1019. // \ \/\/ // __ \| __ \| | \ / _ \ / _ \| |/ /
  1020. // \ /\ ___/| \_\ \ Y ( <_> | <_> ) <
  1021. // \__/\ / \___ >___ /___| /\____/ \____/|__|_ \
  1022. // \/ \/ \/ \/ \/
  1023. // ErrWebhookNotExist represents a "WebhookNotExist" kind of error.
  1024. type ErrWebhookNotExist struct {
  1025. ID int64
  1026. }
  1027. // IsErrWebhookNotExist checks if an error is a ErrWebhookNotExist.
  1028. func IsErrWebhookNotExist(err error) bool {
  1029. _, ok := err.(ErrWebhookNotExist)
  1030. return ok
  1031. }
  1032. func (err ErrWebhookNotExist) Error() string {
  1033. return fmt.Sprintf("webhook does not exist [id: %d]", err.ID)
  1034. }
  1035. // .___
  1036. // | | ______ ________ __ ____
  1037. // | |/ ___// ___/ | \_/ __ \
  1038. // | |\___ \ \___ \| | /\ ___/
  1039. // |___/____ >____ >____/ \___ >
  1040. // \/ \/ \/
  1041. // ErrIssueNotExist represents a "IssueNotExist" kind of error.
  1042. type ErrIssueNotExist struct {
  1043. ID int64
  1044. RepoID int64
  1045. Index int64
  1046. }
  1047. // IsErrIssueNotExist checks if an error is a ErrIssueNotExist.
  1048. func IsErrIssueNotExist(err error) bool {
  1049. _, ok := err.(ErrIssueNotExist)
  1050. return ok
  1051. }
  1052. func (err ErrIssueNotExist) Error() string {
  1053. return fmt.Sprintf("issue does not exist [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  1054. }
  1055. // ErrIssueIsClosed represents a "IssueIsClosed" kind of error.
  1056. type ErrIssueIsClosed struct {
  1057. ID int64
  1058. RepoID int64
  1059. Index int64
  1060. }
  1061. // IsErrIssueIsClosed checks if an error is a ErrIssueNotExist.
  1062. func IsErrIssueIsClosed(err error) bool {
  1063. _, ok := err.(ErrIssueIsClosed)
  1064. return ok
  1065. }
  1066. func (err ErrIssueIsClosed) Error() string {
  1067. return fmt.Sprintf("issue is closed [id: %d, repo_id: %d, index: %d]", err.ID, err.RepoID, err.Index)
  1068. }
  1069. // ErrIssueLabelTemplateLoad represents a "ErrIssueLabelTemplateLoad" kind of error.
  1070. type ErrIssueLabelTemplateLoad struct {
  1071. TemplateFile string
  1072. OriginalError error
  1073. }
  1074. // IsErrIssueLabelTemplateLoad checks if an error is a ErrIssueLabelTemplateLoad.
  1075. func IsErrIssueLabelTemplateLoad(err error) bool {
  1076. _, ok := err.(ErrIssueLabelTemplateLoad)
  1077. return ok
  1078. }
  1079. func (err ErrIssueLabelTemplateLoad) Error() string {
  1080. return fmt.Sprintf("Failed to load label template file '%s': %v", err.TemplateFile, err.OriginalError)
  1081. }
  1082. // ErrNewIssueInsert is used when the INSERT statement in newIssue fails
  1083. type ErrNewIssueInsert struct {
  1084. OriginalError error
  1085. }
  1086. // IsErrNewIssueInsert checks if an error is a ErrNewIssueInsert.
  1087. func IsErrNewIssueInsert(err error) bool {
  1088. _, ok := err.(ErrNewIssueInsert)
  1089. return ok
  1090. }
  1091. func (err ErrNewIssueInsert) Error() string {
  1092. return err.OriginalError.Error()
  1093. }
  1094. // ErrIssueWasClosed is used when close a closed issue
  1095. type ErrIssueWasClosed struct {
  1096. ID int64
  1097. Index int64
  1098. }
  1099. // IsErrIssueWasClosed checks if an error is a ErrIssueWasClosed.
  1100. func IsErrIssueWasClosed(err error) bool {
  1101. _, ok := err.(ErrIssueWasClosed)
  1102. return ok
  1103. }
  1104. func (err ErrIssueWasClosed) Error() string {
  1105. return fmt.Sprintf("Issue [%d] %d was already closed", err.ID, err.Index)
  1106. }
  1107. // ErrPullWasClosed is used close a closed pull request
  1108. type ErrPullWasClosed struct {
  1109. ID int64
  1110. Index int64
  1111. }
  1112. // IsErrPullWasClosed checks if an error is a ErrErrPullWasClosed.
  1113. func IsErrPullWasClosed(err error) bool {
  1114. _, ok := err.(ErrPullWasClosed)
  1115. return ok
  1116. }
  1117. func (err ErrPullWasClosed) Error() string {
  1118. return fmt.Sprintf("Pull request [%d] %d was already closed", err.ID, err.Index)
  1119. }
  1120. // ErrForbiddenIssueReaction is used when a forbidden reaction was try to created
  1121. type ErrForbiddenIssueReaction struct {
  1122. Reaction string
  1123. }
  1124. // IsErrForbiddenIssueReaction checks if an error is a ErrForbiddenIssueReaction.
  1125. func IsErrForbiddenIssueReaction(err error) bool {
  1126. _, ok := err.(ErrForbiddenIssueReaction)
  1127. return ok
  1128. }
  1129. func (err ErrForbiddenIssueReaction) Error() string {
  1130. return fmt.Sprintf("'%s' is not an allowed reaction", err.Reaction)
  1131. }
  1132. // ErrReactionAlreadyExist is used when a existing reaction was try to created
  1133. type ErrReactionAlreadyExist struct {
  1134. Reaction string
  1135. }
  1136. // IsErrReactionAlreadyExist checks if an error is a ErrReactionAlreadyExist.
  1137. func IsErrReactionAlreadyExist(err error) bool {
  1138. _, ok := err.(ErrReactionAlreadyExist)
  1139. return ok
  1140. }
  1141. func (err ErrReactionAlreadyExist) Error() string {
  1142. return fmt.Sprintf("reaction '%s' already exists", err.Reaction)
  1143. }
  1144. // __________ .__ .__ __________ __
  1145. // \______ \__ __| | | |\______ \ ____ ________ __ ____ _______/ |_
  1146. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  1147. // | | | | / |_| |_| | \ ___< <_| | | /\ ___/ \___ \ | |
  1148. // |____| |____/|____/____/____|_ /\___ >__ |____/ \___ >____ > |__|
  1149. // \/ \/ |__| \/ \/
  1150. // ErrPullRequestNotExist represents a "PullRequestNotExist" kind of error.
  1151. type ErrPullRequestNotExist struct {
  1152. ID int64
  1153. IssueID int64
  1154. HeadRepoID int64
  1155. BaseRepoID int64
  1156. HeadBranch string
  1157. BaseBranch string
  1158. }
  1159. // IsErrPullRequestNotExist checks if an error is a ErrPullRequestNotExist.
  1160. func IsErrPullRequestNotExist(err error) bool {
  1161. _, ok := err.(ErrPullRequestNotExist)
  1162. return ok
  1163. }
  1164. func (err ErrPullRequestNotExist) Error() string {
  1165. 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]",
  1166. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  1167. }
  1168. // ErrPullRequestAlreadyExists represents a "PullRequestAlreadyExists"-error
  1169. type ErrPullRequestAlreadyExists struct {
  1170. ID int64
  1171. IssueID int64
  1172. HeadRepoID int64
  1173. BaseRepoID int64
  1174. HeadBranch string
  1175. BaseBranch string
  1176. }
  1177. // IsErrPullRequestAlreadyExists checks if an error is a ErrPullRequestAlreadyExists.
  1178. func IsErrPullRequestAlreadyExists(err error) bool {
  1179. _, ok := err.(ErrPullRequestAlreadyExists)
  1180. return ok
  1181. }
  1182. // Error does pretty-printing :D
  1183. func (err ErrPullRequestAlreadyExists) Error() string {
  1184. 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]",
  1185. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  1186. }
  1187. // ErrPullRequestHeadRepoMissing represents a "ErrPullRequestHeadRepoMissing" error
  1188. type ErrPullRequestHeadRepoMissing struct {
  1189. ID int64
  1190. HeadRepoID int64
  1191. }
  1192. // IsErrErrPullRequestHeadRepoMissing checks if an error is a ErrPullRequestHeadRepoMissing.
  1193. func IsErrErrPullRequestHeadRepoMissing(err error) bool {
  1194. _, ok := err.(ErrPullRequestHeadRepoMissing)
  1195. return ok
  1196. }
  1197. // Error does pretty-printing :D
  1198. func (err ErrPullRequestHeadRepoMissing) Error() string {
  1199. return fmt.Sprintf("pull request head repo missing [id: %d, head_repo_id: %d]",
  1200. err.ID, err.HeadRepoID)
  1201. }
  1202. // ErrInvalidMergeStyle represents an error if merging with disabled merge strategy
  1203. type ErrInvalidMergeStyle struct {
  1204. ID int64
  1205. Style MergeStyle
  1206. }
  1207. // IsErrInvalidMergeStyle checks if an error is a ErrInvalidMergeStyle.
  1208. func IsErrInvalidMergeStyle(err error) bool {
  1209. _, ok := err.(ErrInvalidMergeStyle)
  1210. return ok
  1211. }
  1212. func (err ErrInvalidMergeStyle) Error() string {
  1213. return fmt.Sprintf("merge strategy is not allowed or is invalid [repo_id: %d, strategy: %s]",
  1214. err.ID, err.Style)
  1215. }
  1216. // ErrMergeConflicts represents an error if merging fails with a conflict
  1217. type ErrMergeConflicts struct {
  1218. Style MergeStyle
  1219. StdOut string
  1220. StdErr string
  1221. Err error
  1222. }
  1223. // IsErrMergeConflicts checks if an error is a ErrMergeConflicts.
  1224. func IsErrMergeConflicts(err error) bool {
  1225. _, ok := err.(ErrMergeConflicts)
  1226. return ok
  1227. }
  1228. func (err ErrMergeConflicts) Error() string {
  1229. return fmt.Sprintf("Merge Conflict Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut)
  1230. }
  1231. // ErrMergeUnrelatedHistories represents an error if merging fails due to unrelated histories
  1232. type ErrMergeUnrelatedHistories struct {
  1233. Style MergeStyle
  1234. StdOut string
  1235. StdErr string
  1236. Err error
  1237. }
  1238. // IsErrMergeUnrelatedHistories checks if an error is a ErrMergeUnrelatedHistories.
  1239. func IsErrMergeUnrelatedHistories(err error) bool {
  1240. _, ok := err.(ErrMergeUnrelatedHistories)
  1241. return ok
  1242. }
  1243. func (err ErrMergeUnrelatedHistories) Error() string {
  1244. return fmt.Sprintf("Merge UnrelatedHistories Error: %v: %s\n%s", err.Err, err.StdErr, err.StdOut)
  1245. }
  1246. // ErrRebaseConflicts represents an error if rebase fails with a conflict
  1247. type ErrRebaseConflicts struct {
  1248. Style MergeStyle
  1249. CommitSHA string
  1250. StdOut string
  1251. StdErr string
  1252. Err error
  1253. }
  1254. // IsErrRebaseConflicts checks if an error is a ErrRebaseConflicts.
  1255. func IsErrRebaseConflicts(err error) bool {
  1256. _, ok := err.(ErrRebaseConflicts)
  1257. return ok
  1258. }
  1259. func (err ErrRebaseConflicts) Error() string {
  1260. return fmt.Sprintf("Rebase Error: %v: Whilst Rebasing: %s\n%s\n%s", err.Err, err.CommitSHA, err.StdErr, err.StdOut)
  1261. }
  1262. // ErrPullRequestHasMerged represents a "PullRequestHasMerged"-error
  1263. type ErrPullRequestHasMerged struct {
  1264. ID int64
  1265. IssueID int64
  1266. HeadRepoID int64
  1267. BaseRepoID int64
  1268. HeadBranch string
  1269. BaseBranch string
  1270. }
  1271. // IsErrPullRequestHasMerged checks if an error is a ErrPullRequestHasMerged.
  1272. func IsErrPullRequestHasMerged(err error) bool {
  1273. _, ok := err.(ErrPullRequestHasMerged)
  1274. return ok
  1275. }
  1276. // Error does pretty-printing :D
  1277. func (err ErrPullRequestHasMerged) Error() string {
  1278. return fmt.Sprintf("pull request has merged [id: %d, issue_id: %d, head_repo_id: %d, base_repo_id: %d, head_branch: %s, base_branch: %s]",
  1279. err.ID, err.IssueID, err.HeadRepoID, err.BaseRepoID, err.HeadBranch, err.BaseBranch)
  1280. }
  1281. // _________ __
  1282. // \_ ___ \ ____ _____ _____ ____ _____/ |_
  1283. // / \ \/ / _ \ / \ / \_/ __ \ / \ __\
  1284. // \ \___( <_> ) Y Y \ Y Y \ ___/| | \ |
  1285. // \______ /\____/|__|_| /__|_| /\___ >___| /__|
  1286. // \/ \/ \/ \/ \/
  1287. // ErrCommentNotExist represents a "CommentNotExist" kind of error.
  1288. type ErrCommentNotExist struct {
  1289. ID int64
  1290. IssueID int64
  1291. }
  1292. // IsErrCommentNotExist checks if an error is a ErrCommentNotExist.
  1293. func IsErrCommentNotExist(err error) bool {
  1294. _, ok := err.(ErrCommentNotExist)
  1295. return ok
  1296. }
  1297. func (err ErrCommentNotExist) Error() string {
  1298. return fmt.Sprintf("comment does not exist [id: %d, issue_id: %d]", err.ID, err.IssueID)
  1299. }
  1300. // _________ __ __ .__
  1301. // / _____// |_ ____ ________ _ _______ _/ |_ ____ | |__
  1302. // \_____ \\ __\/ _ \\____ \ \/ \/ /\__ \\ __\/ ___\| | \
  1303. // / \| | ( <_> ) |_> > / / __ \| | \ \___| Y \
  1304. // /_______ /|__| \____/| __/ \/\_/ (____ /__| \___ >___| /
  1305. // \/ |__| \/ \/ \/
  1306. // ErrStopwatchNotExist represents a "Stopwatch Not Exist" kind of error.
  1307. type ErrStopwatchNotExist struct {
  1308. ID int64
  1309. }
  1310. // IsErrStopwatchNotExist checks if an error is a ErrStopwatchNotExist.
  1311. func IsErrStopwatchNotExist(err error) bool {
  1312. _, ok := err.(ErrStopwatchNotExist)
  1313. return ok
  1314. }
  1315. func (err ErrStopwatchNotExist) Error() string {
  1316. return fmt.Sprintf("stopwatch does not exist [id: %d]", err.ID)
  1317. }
  1318. // ___________ __ .______________.__
  1319. // \__ ___/___________ ____ | | __ ____ __| _/\__ ___/|__| _____ ____
  1320. // | | \_ __ \__ \ _/ ___\| |/ // __ \ / __ | | | | |/ \_/ __ \
  1321. // | | | | \// __ \\ \___| <\ ___// /_/ | | | | | Y Y \ ___/
  1322. // |____| |__| (____ /\___ >__|_ \\___ >____ | |____| |__|__|_| /\___ >
  1323. // \/ \/ \/ \/ \/ \/ \/
  1324. // ErrTrackedTimeNotExist represents a "TrackedTime Not Exist" kind of error.
  1325. type ErrTrackedTimeNotExist struct {
  1326. ID int64
  1327. }
  1328. // IsErrTrackedTimeNotExist checks if an error is a ErrTrackedTimeNotExist.
  1329. func IsErrTrackedTimeNotExist(err error) bool {
  1330. _, ok := err.(ErrTrackedTimeNotExist)
  1331. return ok
  1332. }
  1333. func (err ErrTrackedTimeNotExist) Error() string {
  1334. return fmt.Sprintf("tracked time does not exist [id: %d]", err.ID)
  1335. }
  1336. // .____ ___. .__
  1337. // | | _____ \_ |__ ____ | |
  1338. // | | \__ \ | __ \_/ __ \| |
  1339. // | |___ / __ \| \_\ \ ___/| |__
  1340. // |_______ (____ /___ /\___ >____/
  1341. // \/ \/ \/ \/
  1342. // ErrRepoLabelNotExist represents a "RepoLabelNotExist" kind of error.
  1343. type ErrRepoLabelNotExist struct {
  1344. LabelID int64
  1345. RepoID int64
  1346. }
  1347. // IsErrRepoLabelNotExist checks if an error is a RepoErrLabelNotExist.
  1348. func IsErrRepoLabelNotExist(err error) bool {
  1349. _, ok := err.(ErrRepoLabelNotExist)
  1350. return ok
  1351. }
  1352. func (err ErrRepoLabelNotExist) Error() string {
  1353. return fmt.Sprintf("label does not exist [label_id: %d, repo_id: %d]", err.LabelID, err.RepoID)
  1354. }
  1355. // ErrOrgLabelNotExist represents a "OrgLabelNotExist" kind of error.
  1356. type ErrOrgLabelNotExist struct {
  1357. LabelID int64
  1358. OrgID int64
  1359. }
  1360. // IsErrOrgLabelNotExist checks if an error is a OrgErrLabelNotExist.
  1361. func IsErrOrgLabelNotExist(err error) bool {
  1362. _, ok := err.(ErrOrgLabelNotExist)
  1363. return ok
  1364. }
  1365. func (err ErrOrgLabelNotExist) Error() string {
  1366. return fmt.Sprintf("label does not exist [label_id: %d, org_id: %d]", err.LabelID, err.OrgID)
  1367. }
  1368. // ErrLabelNotExist represents a "LabelNotExist" kind of error.
  1369. type ErrLabelNotExist struct {
  1370. LabelID int64
  1371. }
  1372. // IsErrLabelNotExist checks if an error is a ErrLabelNotExist.
  1373. func IsErrLabelNotExist(err error) bool {
  1374. _, ok := err.(ErrLabelNotExist)
  1375. return ok
  1376. }
  1377. func (err ErrLabelNotExist) Error() string {
  1378. return fmt.Sprintf("label does not exist [label_id: %d]", err.LabelID)
  1379. }
  1380. // __________ __ __
  1381. // \______ \_______ ____ |__| ____ _____/ |_ ______
  1382. // | ___/\_ __ \/ _ \ | |/ __ \_/ ___\ __\/ ___/
  1383. // | | | | \( <_> ) | \ ___/\ \___| | \___ \
  1384. // |____| |__| \____/\__| |\___ >\___ >__| /____ >
  1385. // \______| \/ \/ \/
  1386. // ErrProjectNotExist represents a "ProjectNotExist" kind of error.
  1387. type ErrProjectNotExist struct {
  1388. ID int64
  1389. RepoID int64
  1390. }
  1391. // IsErrProjectNotExist checks if an error is a ErrProjectNotExist
  1392. func IsErrProjectNotExist(err error) bool {
  1393. _, ok := err.(ErrProjectNotExist)
  1394. return ok
  1395. }
  1396. func (err ErrProjectNotExist) Error() string {
  1397. return fmt.Sprintf("projects does not exist [id: %d]", err.ID)
  1398. }
  1399. // ErrProjectBoardNotExist represents a "ProjectBoardNotExist" kind of error.
  1400. type ErrProjectBoardNotExist struct {
  1401. BoardID int64
  1402. }
  1403. // IsErrProjectBoardNotExist checks if an error is a ErrProjectBoardNotExist
  1404. func IsErrProjectBoardNotExist(err error) bool {
  1405. _, ok := err.(ErrProjectBoardNotExist)
  1406. return ok
  1407. }
  1408. func (err ErrProjectBoardNotExist) Error() string {
  1409. return fmt.Sprintf("project board does not exist [id: %d]", err.BoardID)
  1410. }
  1411. // _____ .__.__ __
  1412. // / \ |__| | ____ _______/ |_ ____ ____ ____
  1413. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  1414. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  1415. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  1416. // \/ \/ \/ \/ \/
  1417. // ErrMilestoneNotExist represents a "MilestoneNotExist" kind of error.
  1418. type ErrMilestoneNotExist struct {
  1419. ID int64
  1420. RepoID int64
  1421. Name string
  1422. }
  1423. // IsErrMilestoneNotExist checks if an error is a ErrMilestoneNotExist.
  1424. func IsErrMilestoneNotExist(err error) bool {
  1425. _, ok := err.(ErrMilestoneNotExist)
  1426. return ok
  1427. }
  1428. func (err ErrMilestoneNotExist) Error() string {
  1429. if len(err.Name) > 0 {
  1430. return fmt.Sprintf("milestone does not exist [name: %s, repo_id: %d]", err.Name, err.RepoID)
  1431. }
  1432. return fmt.Sprintf("milestone does not exist [id: %d, repo_id: %d]", err.ID, err.RepoID)
  1433. }
  1434. // _____ __ __ .__ __
  1435. // / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
  1436. // / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
  1437. // / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
  1438. // \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
  1439. // \/ \/ \/ \/ \/ \/ \/
  1440. // ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
  1441. type ErrAttachmentNotExist struct {
  1442. ID int64
  1443. UUID string
  1444. }
  1445. // IsErrAttachmentNotExist checks if an error is a ErrAttachmentNotExist.
  1446. func IsErrAttachmentNotExist(err error) bool {
  1447. _, ok := err.(ErrAttachmentNotExist)
  1448. return ok
  1449. }
  1450. func (err ErrAttachmentNotExist) Error() string {
  1451. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  1452. }
  1453. // .____ .__ _________
  1454. // | | ____ ____ |__| ____ / _____/ ____ __ _________ ____ ____
  1455. // | | / _ \ / ___\| |/ \ \_____ \ / _ \| | \_ __ \_/ ___\/ __ \
  1456. // | |__( <_> ) /_/ > | | \ / ( <_> ) | /| | \/\ \__\ ___/
  1457. // |_______ \____/\___ /|__|___| / /_______ /\____/|____/ |__| \___ >___ >
  1458. // \/ /_____/ \/ \/ \/ \/
  1459. // ErrLoginSourceNotExist represents a "LoginSourceNotExist" kind of error.
  1460. type ErrLoginSourceNotExist struct {
  1461. ID int64
  1462. }
  1463. // IsErrLoginSourceNotExist checks if an error is a ErrLoginSourceNotExist.
  1464. func IsErrLoginSourceNotExist(err error) bool {
  1465. _, ok := err.(ErrLoginSourceNotExist)
  1466. return ok
  1467. }
  1468. func (err ErrLoginSourceNotExist) Error() string {
  1469. return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
  1470. }
  1471. // ErrLoginSourceAlreadyExist represents a "LoginSourceAlreadyExist" kind of error.
  1472. type ErrLoginSourceAlreadyExist struct {
  1473. Name string
  1474. }
  1475. // IsErrLoginSourceAlreadyExist checks if an error is a ErrLoginSourceAlreadyExist.
  1476. func IsErrLoginSourceAlreadyExist(err error) bool {
  1477. _, ok := err.(ErrLoginSourceAlreadyExist)
  1478. return ok
  1479. }
  1480. func (err ErrLoginSourceAlreadyExist) Error() string {
  1481. return fmt.Sprintf("login source already exists [name: %s]", err.Name)
  1482. }
  1483. // ErrLoginSourceInUse represents a "LoginSourceInUse" kind of error.
  1484. type ErrLoginSourceInUse struct {
  1485. ID int64
  1486. }
  1487. // IsErrLoginSourceInUse checks if an error is a ErrLoginSourceInUse.
  1488. func IsErrLoginSourceInUse(err error) bool {
  1489. _, ok := err.(ErrLoginSourceInUse)
  1490. return ok
  1491. }
  1492. func (err ErrLoginSourceInUse) Error() string {
  1493. return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
  1494. }
  1495. // ___________
  1496. // \__ ___/___ _____ _____
  1497. // | |_/ __ \\__ \ / \
  1498. // | |\ ___/ / __ \| Y Y \
  1499. // |____| \___ >____ /__|_| /
  1500. // \/ \/ \/
  1501. // ErrTeamAlreadyExist represents a "TeamAlreadyExist" kind of error.
  1502. type ErrTeamAlreadyExist struct {
  1503. OrgID int64
  1504. Name string
  1505. }
  1506. // IsErrTeamAlreadyExist checks if an error is a ErrTeamAlreadyExist.
  1507. func IsErrTeamAlreadyExist(err error) bool {
  1508. _, ok := err.(ErrTeamAlreadyExist)
  1509. return ok
  1510. }
  1511. func (err ErrTeamAlreadyExist) Error() string {
  1512. return fmt.Sprintf("team already exists [org_id: %d, name: %s]", err.OrgID, err.Name)
  1513. }
  1514. // ErrTeamNotExist represents a "TeamNotExist" error
  1515. type ErrTeamNotExist struct {
  1516. OrgID int64
  1517. TeamID int64
  1518. Name string
  1519. }
  1520. // IsErrTeamNotExist checks if an error is a ErrTeamNotExist.
  1521. func IsErrTeamNotExist(err error) bool {
  1522. _, ok := err.(ErrTeamNotExist)
  1523. return ok
  1524. }
  1525. func (err ErrTeamNotExist) Error() string {
  1526. return fmt.Sprintf("team does not exist [org_id %d, team_id %d, name: %s]", err.OrgID, err.TeamID, err.Name)
  1527. }
  1528. //
  1529. // Two-factor authentication
  1530. //
  1531. // ErrTwoFactorNotEnrolled indicates that a user is not enrolled in two-factor authentication.
  1532. type ErrTwoFactorNotEnrolled struct {
  1533. UID int64
  1534. }
  1535. // IsErrTwoFactorNotEnrolled checks if an error is a ErrTwoFactorNotEnrolled.
  1536. func IsErrTwoFactorNotEnrolled(err error) bool {
  1537. _, ok := err.(ErrTwoFactorNotEnrolled)
  1538. return ok
  1539. }
  1540. func (err ErrTwoFactorNotEnrolled) Error() string {
  1541. return fmt.Sprintf("user not enrolled in 2FA [uid: %d]", err.UID)
  1542. }
  1543. // ____ ___ .__ .___
  1544. // | | \______ | | _________ __| _/
  1545. // | | /\____ \| | / _ \__ \ / __ |
  1546. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  1547. // |______/ | __/|____/\____(____ /\____ |
  1548. // |__| \/ \/
  1549. //
  1550. // ErrUploadNotExist represents a "UploadNotExist" kind of error.
  1551. type ErrUploadNotExist struct {
  1552. ID int64
  1553. UUID string
  1554. }
  1555. // IsErrUploadNotExist checks if an error is a ErrUploadNotExist.
  1556. func IsErrUploadNotExist(err error) bool {
  1557. _, ok := err.(ErrAttachmentNotExist)
  1558. return ok
  1559. }
  1560. func (err ErrUploadNotExist) Error() string {
  1561. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  1562. }
  1563. // ___________ __ .__ .____ .__ ____ ___
  1564. // \_ _____/__ ____/ |_ ___________ ____ _____ | | | | ____ ____ |__| ____ | | \______ ___________
  1565. // | __)_\ \/ /\ __\/ __ \_ __ \/ \\__ \ | | | | / _ \ / ___\| |/ \ | | / ___// __ \_ __ \
  1566. // | \> < | | \ ___/| | \/ | \/ __ \| |__ | |__( <_> ) /_/ > | | \ | | /\___ \\ ___/| | \/
  1567. // /_______ /__/\_ \ |__| \___ >__| |___| (____ /____/ |_______ \____/\___ /|__|___| / |______//____ >\___ >__|
  1568. // \/ \/ \/ \/ \/ \/ /_____/ \/ \/ \/
  1569. // ErrExternalLoginUserAlreadyExist represents a "ExternalLoginUserAlreadyExist" kind of error.
  1570. type ErrExternalLoginUserAlreadyExist struct {
  1571. ExternalID string
  1572. UserID int64
  1573. LoginSourceID int64
  1574. }
  1575. // IsErrExternalLoginUserAlreadyExist checks if an error is a ExternalLoginUserAlreadyExist.
  1576. func IsErrExternalLoginUserAlreadyExist(err error) bool {
  1577. _, ok := err.(ErrExternalLoginUserAlreadyExist)
  1578. return ok
  1579. }
  1580. func (err ErrExternalLoginUserAlreadyExist) Error() string {
  1581. return fmt.Sprintf("external login user already exists [externalID: %s, userID: %d, loginSourceID: %d]", err.ExternalID, err.UserID, err.LoginSourceID)
  1582. }
  1583. // ErrExternalLoginUserNotExist represents a "ExternalLoginUserNotExist" kind of error.
  1584. type ErrExternalLoginUserNotExist struct {
  1585. UserID int64
  1586. LoginSourceID int64
  1587. }
  1588. // IsErrExternalLoginUserNotExist checks if an error is a ExternalLoginUserNotExist.
  1589. func IsErrExternalLoginUserNotExist(err error) bool {
  1590. _, ok := err.(ErrExternalLoginUserNotExist)
  1591. return ok
  1592. }
  1593. func (err ErrExternalLoginUserNotExist) Error() string {
  1594. return fmt.Sprintf("external login user link does not exists [userID: %d, loginSourceID: %d]", err.UserID, err.LoginSourceID)
  1595. }
  1596. // ____ ________________________________ .__ __ __ .__
  1597. // | | \_____ \_ _____/\______ \ ____ ____ |__| _______/ |_____________ _/ |_|__| ____ ____
  1598. // | | // ____/| __) | _// __ \ / ___\| |/ ___/\ __\_ __ \__ \\ __\ |/ _ \ / \
  1599. // | | // \| \ | | \ ___// /_/ > |\___ \ | | | | \// __ \| | | ( <_> ) | \
  1600. // |______/ \_______ \___ / |____|_ /\___ >___ /|__/____ > |__| |__| (____ /__| |__|\____/|___| /
  1601. // \/ \/ \/ \/_____/ \/ \/ \/
  1602. // ErrU2FRegistrationNotExist represents a "ErrU2FRegistrationNotExist" kind of error.
  1603. type ErrU2FRegistrationNotExist struct {
  1604. ID int64
  1605. }
  1606. func (err ErrU2FRegistrationNotExist) Error() string {
  1607. return fmt.Sprintf("U2F registration does not exist [id: %d]", err.ID)
  1608. }
  1609. // IsErrU2FRegistrationNotExist checks if an error is a ErrU2FRegistrationNotExist.
  1610. func IsErrU2FRegistrationNotExist(err error) bool {
  1611. _, ok := err.(ErrU2FRegistrationNotExist)
  1612. return ok
  1613. }
  1614. // .___ ________ .___ .__
  1615. // | | ______ ________ __ ____ \______ \ ____ ______ ____ ____ __| _/____ ____ ____ |__| ____ ______
  1616. // | |/ ___// ___/ | \_/ __ \ | | \_/ __ \\____ \_/ __ \ / \ / __ |/ __ \ / \_/ ___\| |/ __ \ / ___/
  1617. // | |\___ \ \___ \| | /\ ___/ | ` \ ___/| |_> > ___/| | \/ /_/ \ ___/| | \ \___| \ ___/ \___ \
  1618. // |___/____ >____ >____/ \___ >_______ /\___ > __/ \___ >___| /\____ |\___ >___| /\___ >__|\___ >____ >
  1619. // \/ \/ \/ \/ \/|__| \/ \/ \/ \/ \/ \/ \/ \/
  1620. // ErrDependencyExists represents a "DependencyAlreadyExists" kind of error.
  1621. type ErrDependencyExists struct {
  1622. IssueID int64
  1623. DependencyID int64
  1624. }
  1625. // IsErrDependencyExists checks if an error is a ErrDependencyExists.
  1626. func IsErrDependencyExists(err error) bool {
  1627. _, ok := err.(ErrDependencyExists)
  1628. return ok
  1629. }
  1630. func (err ErrDependencyExists) Error() string {
  1631. return fmt.Sprintf("issue dependency does already exist [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1632. }
  1633. // ErrDependencyNotExists represents a "DependencyAlreadyExists" kind of error.
  1634. type ErrDependencyNotExists struct {
  1635. IssueID int64
  1636. DependencyID int64
  1637. }
  1638. // IsErrDependencyNotExists checks if an error is a ErrDependencyExists.
  1639. func IsErrDependencyNotExists(err error) bool {
  1640. _, ok := err.(ErrDependencyNotExists)
  1641. return ok
  1642. }
  1643. func (err ErrDependencyNotExists) Error() string {
  1644. return fmt.Sprintf("issue dependency does not exist [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1645. }
  1646. // ErrCircularDependency represents a "DependencyCircular" kind of error.
  1647. type ErrCircularDependency struct {
  1648. IssueID int64
  1649. DependencyID int64
  1650. }
  1651. // IsErrCircularDependency checks if an error is a ErrCircularDependency.
  1652. func IsErrCircularDependency(err error) bool {
  1653. _, ok := err.(ErrCircularDependency)
  1654. return ok
  1655. }
  1656. func (err ErrCircularDependency) Error() string {
  1657. return fmt.Sprintf("circular dependencies exists (two issues blocking each other) [issue id: %d, dependency id: %d]", err.IssueID, err.DependencyID)
  1658. }
  1659. // ErrDependenciesLeft represents an error where the issue you're trying to close still has dependencies left.
  1660. type ErrDependenciesLeft struct {
  1661. IssueID int64
  1662. }
  1663. // IsErrDependenciesLeft checks if an error is a ErrDependenciesLeft.
  1664. func IsErrDependenciesLeft(err error) bool {
  1665. _, ok := err.(ErrDependenciesLeft)
  1666. return ok
  1667. }
  1668. func (err ErrDependenciesLeft) Error() string {
  1669. return fmt.Sprintf("issue has open dependencies [issue id: %d]", err.IssueID)
  1670. }
  1671. // ErrUnknownDependencyType represents an error where an unknown dependency type was passed
  1672. type ErrUnknownDependencyType struct {
  1673. Type DependencyType
  1674. }
  1675. // IsErrUnknownDependencyType checks if an error is ErrUnknownDependencyType
  1676. func IsErrUnknownDependencyType(err error) bool {
  1677. _, ok := err.(ErrUnknownDependencyType)
  1678. return ok
  1679. }
  1680. func (err ErrUnknownDependencyType) Error() string {
  1681. return fmt.Sprintf("unknown dependency type [type: %d]", err.Type)
  1682. }
  1683. // __________ .__
  1684. // \______ \ _______ _|__| ______ _ __
  1685. // | _// __ \ \/ / |/ __ \ \/ \/ /
  1686. // | | \ ___/\ /| \ ___/\ /
  1687. // |____|_ /\___ >\_/ |__|\___ >\/\_/
  1688. // \/ \/ \/
  1689. // ErrReviewNotExist represents a "ReviewNotExist" kind of error.
  1690. type ErrReviewNotExist struct {
  1691. ID int64
  1692. }
  1693. // IsErrReviewNotExist checks if an error is a ErrReviewNotExist.
  1694. func IsErrReviewNotExist(err error) bool {
  1695. _, ok := err.(ErrReviewNotExist)
  1696. return ok
  1697. }
  1698. func (err ErrReviewNotExist) Error() string {
  1699. return fmt.Sprintf("review does not exist [id: %d]", err.ID)
  1700. }
  1701. // ErrNotValidReviewRequest an not allowed review request modify
  1702. type ErrNotValidReviewRequest struct {
  1703. Reason string
  1704. UserID int64
  1705. RepoID int64
  1706. }
  1707. // IsErrNotValidReviewRequest checks if an error is a ErrNotValidReviewRequest.
  1708. func IsErrNotValidReviewRequest(err error) bool {
  1709. _, ok := err.(ErrNotValidReviewRequest)
  1710. return ok
  1711. }
  1712. func (err ErrNotValidReviewRequest) Error() string {
  1713. return fmt.Sprintf("%s [user_id: %d, repo_id: %d]",
  1714. err.Reason,
  1715. err.UserID,
  1716. err.RepoID)
  1717. }
  1718. // ________ _____ __ .__
  1719. // \_____ \ / _ \ __ ___/ |_| |__
  1720. // / | \ / /_\ \| | \ __\ | \
  1721. // / | \/ | \ | /| | | Y \
  1722. // \_______ /\____|__ /____/ |__| |___| /
  1723. // \/ \/ \/
  1724. // ErrOAuthClientIDInvalid will be thrown if client id cannot be found
  1725. type ErrOAuthClientIDInvalid struct {
  1726. ClientID string
  1727. }
  1728. // IsErrOauthClientIDInvalid checks if an error is a ErrReviewNotExist.
  1729. func IsErrOauthClientIDInvalid(err error) bool {
  1730. _, ok := err.(ErrOAuthClientIDInvalid)
  1731. return ok
  1732. }
  1733. // Error returns the error message
  1734. func (err ErrOAuthClientIDInvalid) Error() string {
  1735. return fmt.Sprintf("Client ID invalid [Client ID: %s]", err.ClientID)
  1736. }
  1737. // ErrOAuthApplicationNotFound will be thrown if id cannot be found
  1738. type ErrOAuthApplicationNotFound struct {
  1739. ID int64
  1740. }
  1741. // IsErrOAuthApplicationNotFound checks if an error is a ErrReviewNotExist.
  1742. func IsErrOAuthApplicationNotFound(err error) bool {
  1743. _, ok := err.(ErrOAuthApplicationNotFound)
  1744. return ok
  1745. }
  1746. // Error returns the error message
  1747. func (err ErrOAuthApplicationNotFound) Error() string {
  1748. return fmt.Sprintf("OAuth application not found [ID: %d]", err.ID)
  1749. }