error.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 database
  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 ErrGPGKeyNotExist struct {
  114. args map[string]any
  115. }
  116. func IsErrGPGKeyNotExist(err error) bool {
  117. _, ok := err.(ErrGPGKeyNotExist)
  118. return ok
  119. }
  120. func (err ErrGPGKeyNotExist) Error() string {
  121. return fmt.Sprintf("GPG key does not exist %v", err.args)
  122. }
  123. type ErrGPGKeyAlreadyExist struct {
  124. KeyID string
  125. }
  126. func IsErrGPGKeyAlreadyExist(err error) bool {
  127. _, ok := err.(ErrGPGKeyAlreadyExist)
  128. return ok
  129. }
  130. func (err ErrGPGKeyAlreadyExist) Error() string {
  131. return fmt.Sprintf("GPG key already exists [key_id: %s]", err.KeyID)
  132. }
  133. type ErrGPGKeyAccessDenied struct {
  134. UserID int64
  135. KeyID int64
  136. }
  137. func IsErrGPGKeyAccessDenied(err error) bool {
  138. _, ok := err.(ErrGPGKeyAccessDenied)
  139. return ok
  140. }
  141. func (err ErrGPGKeyAccessDenied) Error() string {
  142. return fmt.Sprintf("user does not have access to GPG key [user_id: %d, key_id: %d]", err.UserID, err.KeyID)
  143. }
  144. // ________ .__ __ .__
  145. // \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
  146. // / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
  147. // / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
  148. // \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
  149. // \/ /_____/ \/ \/ \/ \/ \/
  150. type ErrLastOrgOwner struct {
  151. UID int64
  152. }
  153. func IsErrLastOrgOwner(err error) bool {
  154. _, ok := err.(ErrLastOrgOwner)
  155. return ok
  156. }
  157. func (err ErrLastOrgOwner) Error() string {
  158. return fmt.Sprintf("user is the last member of owner team [uid: %d]", err.UID)
  159. }
  160. // __________ .__ __
  161. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  162. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  163. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  164. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  165. // \/ \/|__| \/ \/
  166. type ErrInvalidCloneAddr struct {
  167. IsURLError bool
  168. IsInvalidPath bool
  169. IsPermissionDenied bool
  170. IsBlockedLocalAddress bool
  171. }
  172. func IsErrInvalidCloneAddr(err error) bool {
  173. _, ok := err.(ErrInvalidCloneAddr)
  174. return ok
  175. }
  176. func (err ErrInvalidCloneAddr) Error() string {
  177. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v, is_blocked_local_address: %v]",
  178. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied, err.IsBlockedLocalAddress)
  179. }
  180. type ErrUpdateTaskNotExist struct {
  181. UUID string
  182. }
  183. func IsErrUpdateTaskNotExist(err error) bool {
  184. _, ok := err.(ErrUpdateTaskNotExist)
  185. return ok
  186. }
  187. func (err ErrUpdateTaskNotExist) Error() string {
  188. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  189. }
  190. type ErrReleaseAlreadyExist struct {
  191. TagName string
  192. }
  193. func IsErrReleaseAlreadyExist(err error) bool {
  194. _, ok := err.(ErrReleaseAlreadyExist)
  195. return ok
  196. }
  197. func (err ErrReleaseAlreadyExist) Error() string {
  198. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  199. }
  200. type ErrInvalidTagName struct {
  201. TagName string
  202. }
  203. func IsErrInvalidTagName(err error) bool {
  204. _, ok := err.(ErrInvalidTagName)
  205. return ok
  206. }
  207. func (err ErrInvalidTagName) Error() string {
  208. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  209. }
  210. type ErrRepoFileAlreadyExist struct {
  211. FileName string
  212. }
  213. func IsErrRepoFileAlreadyExist(err error) bool {
  214. _, ok := err.(ErrRepoFileAlreadyExist)
  215. return ok
  216. }
  217. func (err ErrRepoFileAlreadyExist) Error() string {
  218. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  219. }
  220. // ___________
  221. // \__ ___/___ _____ _____
  222. // | |_/ __ \\__ \ / \
  223. // | |\ ___/ / __ \| Y Y \
  224. // |____| \___ >____ /__|_| /
  225. // \/ \/ \/
  226. type ErrTeamAlreadyExist struct {
  227. ID int64
  228. OrgID int64
  229. Name string
  230. }
  231. func IsErrTeamAlreadyExist(err error) bool {
  232. _, ok := err.(ErrTeamAlreadyExist)
  233. return ok
  234. }
  235. func (err ErrTeamAlreadyExist) Error() string {
  236. return fmt.Sprintf("team already exists [id: %d, org_id: %d, name: %s]", err.ID, err.OrgID, err.Name)
  237. }
  238. // ____ ___ .__ .___
  239. // | | \______ | | _________ __| _/
  240. // | | /\____ \| | / _ \__ \ / __ |
  241. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  242. // |______/ | __/|____/\____(____ /\____ |
  243. // |__| \/ \/
  244. //
  245. type ErrUploadNotExist struct {
  246. ID int64
  247. UUID string
  248. }
  249. func IsErrUploadNotExist(err error) bool {
  250. _, ok := err.(ErrAttachmentNotExist)
  251. return ok
  252. }
  253. func (err ErrUploadNotExist) Error() string {
  254. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  255. }