error.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package db
  5. import (
  6. "fmt"
  7. )
  8. // __ __.__ __ .__
  9. // / \ / \__| | _|__|
  10. // \ \/\/ / | |/ / |
  11. // \ /| | <| |
  12. // \__/\ / |__|__|_ \__|
  13. // \/ \/
  14. type ErrWikiAlreadyExist struct {
  15. Title string
  16. }
  17. func IsErrWikiAlreadyExist(err error) bool {
  18. _, ok := err.(ErrWikiAlreadyExist)
  19. return ok
  20. }
  21. func (err ErrWikiAlreadyExist) Error() string {
  22. return fmt.Sprintf("wiki page already exists [title: %s]", err.Title)
  23. }
  24. // __________ ___. .__ .__ ____ __.
  25. // \______ \__ _\_ |__ | | |__| ____ | |/ _|____ ___.__.
  26. // | ___/ | \ __ \| | | |/ ___\ | <_/ __ < | |
  27. // | | | | / \_\ \ |_| \ \___ | | \ ___/\___ |
  28. // |____| |____/|___ /____/__|\___ > |____|__ \___ > ____|
  29. // \/ \/ \/ \/\/
  30. type ErrKeyUnableVerify struct {
  31. Result string
  32. }
  33. func IsErrKeyUnableVerify(err error) bool {
  34. _, ok := err.(ErrKeyUnableVerify)
  35. return ok
  36. }
  37. func (err ErrKeyUnableVerify) Error() string {
  38. return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
  39. }
  40. type ErrKeyNotExist struct {
  41. ID int64
  42. }
  43. func IsErrKeyNotExist(err error) bool {
  44. _, ok := err.(ErrKeyNotExist)
  45. return ok
  46. }
  47. func (err ErrKeyNotExist) Error() string {
  48. return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
  49. }
  50. type ErrKeyAlreadyExist struct {
  51. OwnerID int64
  52. Content string
  53. }
  54. func IsErrKeyAlreadyExist(err error) bool {
  55. _, ok := err.(ErrKeyAlreadyExist)
  56. return ok
  57. }
  58. func (err ErrKeyAlreadyExist) Error() string {
  59. return fmt.Sprintf("public key already exists [owner_id: %d, content: %s]", err.OwnerID, err.Content)
  60. }
  61. type ErrKeyNameAlreadyUsed struct {
  62. OwnerID int64
  63. Name string
  64. }
  65. func IsErrKeyNameAlreadyUsed(err error) bool {
  66. _, ok := err.(ErrKeyNameAlreadyUsed)
  67. return ok
  68. }
  69. func (err ErrKeyNameAlreadyUsed) Error() string {
  70. return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
  71. }
  72. type ErrKeyAccessDenied struct {
  73. UserID int64
  74. KeyID int64
  75. Note string
  76. }
  77. func IsErrKeyAccessDenied(err error) bool {
  78. _, ok := err.(ErrKeyAccessDenied)
  79. return ok
  80. }
  81. func (err ErrKeyAccessDenied) Error() string {
  82. return fmt.Sprintf("user does not have access to the key [user_id: %d, key_id: %d, note: %s]",
  83. err.UserID, err.KeyID, err.Note)
  84. }
  85. type ErrDeployKeyAlreadyExist struct {
  86. KeyID int64
  87. RepoID int64
  88. }
  89. func IsErrDeployKeyAlreadyExist(err error) bool {
  90. _, ok := err.(ErrDeployKeyAlreadyExist)
  91. return ok
  92. }
  93. func (err ErrDeployKeyAlreadyExist) Error() string {
  94. return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
  95. }
  96. type ErrDeployKeyNameAlreadyUsed struct {
  97. RepoID int64
  98. Name string
  99. }
  100. func IsErrDeployKeyNameAlreadyUsed(err error) bool {
  101. _, ok := err.(ErrDeployKeyNameAlreadyUsed)
  102. return ok
  103. }
  104. func (err ErrDeployKeyNameAlreadyUsed) Error() string {
  105. return fmt.Sprintf("public key already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
  106. }
  107. // ________ .__ __ .__
  108. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  109. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  110. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  111. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  112. // \/ /_____/ \/ \/ \/ \/ \/
  113. type ErrLastOrgOwner struct {
  114. UID int64
  115. }
  116. func IsErrLastOrgOwner(err error) bool {
  117. _, ok := err.(ErrLastOrgOwner)
  118. return ok
  119. }
  120. func (err ErrLastOrgOwner) Error() string {
  121. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  122. }
  123. // __________ .__ __
  124. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  125. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  126. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  127. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  128. // \/ \/|__| \/ \/
  129. type ErrInvalidCloneAddr struct {
  130. IsURLError bool
  131. IsInvalidPath bool
  132. IsPermissionDenied bool
  133. IsBlockedLocalAddress bool
  134. }
  135. func IsErrInvalidCloneAddr(err error) bool {
  136. _, ok := err.(ErrInvalidCloneAddr)
  137. return ok
  138. }
  139. func (err ErrInvalidCloneAddr) Error() string {
  140. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v, is_blocked_local_address: %v]",
  141. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied, err.IsBlockedLocalAddress)
  142. }
  143. type ErrUpdateTaskNotExist struct {
  144. UUID string
  145. }
  146. func IsErrUpdateTaskNotExist(err error) bool {
  147. _, ok := err.(ErrUpdateTaskNotExist)
  148. return ok
  149. }
  150. func (err ErrUpdateTaskNotExist) Error() string {
  151. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  152. }
  153. type ErrReleaseAlreadyExist struct {
  154. TagName string
  155. }
  156. func IsErrReleaseAlreadyExist(err error) bool {
  157. _, ok := err.(ErrReleaseAlreadyExist)
  158. return ok
  159. }
  160. func (err ErrReleaseAlreadyExist) Error() string {
  161. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  162. }
  163. type ErrInvalidTagName struct {
  164. TagName string
  165. }
  166. func IsErrInvalidTagName(err error) bool {
  167. _, ok := err.(ErrInvalidTagName)
  168. return ok
  169. }
  170. func (err ErrInvalidTagName) Error() string {
  171. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  172. }
  173. type ErrRepoFileAlreadyExist struct {
  174. FileName string
  175. }
  176. func IsErrRepoFileAlreadyExist(err error) bool {
  177. _, ok := err.(ErrRepoFileAlreadyExist)
  178. return ok
  179. }
  180. func (err ErrRepoFileAlreadyExist) Error() string {
  181. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  182. }
  183. // ___________
  184. // \__ ___/___ _____ _____
  185. // | |_/ __ \\__ \ / \
  186. // | |\ ___/ / __ \| Y Y \
  187. // |____| \___ >____ /__|_| /
  188. // \/ \/ \/
  189. type ErrTeamAlreadyExist struct {
  190. ID int64
  191. OrgID int64
  192. Name string
  193. }
  194. func IsErrTeamAlreadyExist(err error) bool {
  195. _, ok := err.(ErrTeamAlreadyExist)
  196. return ok
  197. }
  198. func (err ErrTeamAlreadyExist) Error() string {
  199. return fmt.Sprintf("team already exists [id: %d, org_id: %d, name: %s]", err.ID, err.OrgID, err.Name)
  200. }
  201. // ____ ___ .__ .___
  202. // | | \______ | | _________ __| _/
  203. // | | /\____ \| | / _ \__ \ / __ |
  204. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  205. // |______/ | __/|____/\____(____ /\____ |
  206. // |__| \/ \/
  207. //
  208. type ErrUploadNotExist struct {
  209. ID int64
  210. UUID string
  211. }
  212. func IsErrUploadNotExist(err error) bool {
  213. _, ok := err.(ErrAttachmentNotExist)
  214. return ok
  215. }
  216. func (err ErrUploadNotExist) Error() string {
  217. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  218. }