error.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 ErrInvalidCloneAddr struct {
  114. IsURLError bool
  115. IsInvalidPath bool
  116. IsPermissionDenied bool
  117. IsBlockedLocalAddress bool
  118. }
  119. func IsErrInvalidCloneAddr(err error) bool {
  120. _, ok := err.(ErrInvalidCloneAddr)
  121. return ok
  122. }
  123. func (err ErrInvalidCloneAddr) Error() string {
  124. return fmt.Sprintf("invalid clone address [is_url_error: %v, is_invalid_path: %v, is_permission_denied: %v, is_blocked_local_address: %v]",
  125. err.IsURLError, err.IsInvalidPath, err.IsPermissionDenied, err.IsBlockedLocalAddress)
  126. }
  127. type ErrUpdateTaskNotExist struct {
  128. UUID string
  129. }
  130. func IsErrUpdateTaskNotExist(err error) bool {
  131. _, ok := err.(ErrUpdateTaskNotExist)
  132. return ok
  133. }
  134. func (err ErrUpdateTaskNotExist) Error() string {
  135. return fmt.Sprintf("update task does not exist [uuid: %s]", err.UUID)
  136. }
  137. type ErrReleaseAlreadyExist struct {
  138. TagName string
  139. }
  140. func IsErrReleaseAlreadyExist(err error) bool {
  141. _, ok := err.(ErrReleaseAlreadyExist)
  142. return ok
  143. }
  144. func (err ErrReleaseAlreadyExist) Error() string {
  145. return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
  146. }
  147. type ErrInvalidTagName struct {
  148. TagName string
  149. }
  150. func IsErrInvalidTagName(err error) bool {
  151. _, ok := err.(ErrInvalidTagName)
  152. return ok
  153. }
  154. func (err ErrInvalidTagName) Error() string {
  155. return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
  156. }
  157. type ErrRepoFileAlreadyExist struct {
  158. FileName string
  159. }
  160. func IsErrRepoFileAlreadyExist(err error) bool {
  161. _, ok := err.(ErrRepoFileAlreadyExist)
  162. return ok
  163. }
  164. func (err ErrRepoFileAlreadyExist) Error() string {
  165. return fmt.Sprintf("repository file already exists [file_name: %s]", err.FileName)
  166. }
  167. // ___________
  168. // \__ ___/___ _____ _____
  169. // | |_/ __ \\__ \ / \
  170. // | |\ ___/ / __ \| Y Y \
  171. // |____| \___ >____ /__|_| /
  172. // \/ \/ \/
  173. type ErrTeamAlreadyExist struct {
  174. ID int64
  175. OrgID int64
  176. Name string
  177. }
  178. func IsErrTeamAlreadyExist(err error) bool {
  179. _, ok := err.(ErrTeamAlreadyExist)
  180. return ok
  181. }
  182. func (err ErrTeamAlreadyExist) Error() string {
  183. return fmt.Sprintf("team already exists [id: %d, org_id: %d, name: %s]", err.ID, err.OrgID, err.Name)
  184. }
  185. // ____ ___ .__ .___
  186. // | | \______ | | _________ __| _/
  187. // | | /\____ \| | / _ \__ \ / __ |
  188. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  189. // |______/ | __/|____/\____(____ /\____ |
  190. // |__| \/ \/
  191. //
  192. type ErrUploadNotExist struct {
  193. ID int64
  194. UUID string
  195. }
  196. func IsErrUploadNotExist(err error) bool {
  197. _, ok := err.(ErrAttachmentNotExist)
  198. return ok
  199. }
  200. func (err ErrUploadNotExist) Error() string {
  201. return fmt.Sprintf("attachment does not exist [id: %d, uuid: %s]", err.ID, err.UUID)
  202. }