error.go 7.5 KB

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