github.com/matrixorigin/matrixone@v1.2.0/pkg/common/moerr/error_no_ctx.go (about) 1 // Copyright 2021 - 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package moerr 16 17 import ( 18 "encoding/hex" 19 "fmt" 20 ) 21 22 func NewInfoNoCtx(msg string) *Error { 23 return newError(Context(), ErrInfo, msg) 24 } 25 26 func NewBadS3ConfigNoCtx(msg string) *Error { 27 return newError(Context(), ErrBadS3Config, msg) 28 } 29 30 func NewInternalErrorNoCtx(msg string, args ...any) *Error { 31 xmsg := fmt.Sprintf(msg, args...) 32 return newError(Context(), ErrInternal, xmsg) 33 } 34 35 func NewNYINoCtx(msg string, args ...any) *Error { 36 xmsg := fmt.Sprintf(msg, args...) 37 return newError(Context(), ErrNYI, xmsg) 38 } 39 40 func NewNotSupportedNoCtx(msg string, args ...any) *Error { 41 xmsg := fmt.Sprintf(msg, args...) 42 return newError(Context(), ErrNotSupported, xmsg) 43 } 44 45 func NewOOMNoCtx() *Error { 46 return newError(Context(), ErrOOM) 47 } 48 49 func NewDivByZeroNoCtx() *Error { 50 return newError(Context(), ErrDivByZero) 51 } 52 53 func NewOutOfRangeNoCtx(typ string, msg string, args ...any) *Error { 54 xmsg := fmt.Sprintf(msg, args...) 55 return newError(Context(), ErrOutOfRange, typ, xmsg) 56 } 57 58 func NewDataTruncatedNoCtx(typ string, msg string, args ...any) *Error { 59 xmsg := fmt.Sprintf(msg, args...) 60 return newError(Context(), ErrDataTruncated, typ, xmsg) 61 } 62 63 func NewInvalidArgNoCtx(arg string, val any) *Error { 64 return newError(Context(), ErrInvalidArg, arg, fmt.Sprintf("%v", val)) 65 } 66 67 func NewBadConfigNoCtx(msg string, args ...any) *Error { 68 xmsg := fmt.Sprintf(msg, args...) 69 return newError(Context(), ErrBadConfig, xmsg) 70 } 71 72 func NewInvalidInputNoCtx(msg string, args ...any) *Error { 73 xmsg := fmt.Sprintf(msg, args...) 74 return newError(Context(), ErrInvalidInput, xmsg) 75 } 76 77 func NewArrayInvalidOpNoCtx(expected, actual int) *Error { 78 xmsg := fmt.Sprintf("vector ops between different dimensions (%v, %v) is not permitted.", expected, actual) 79 return newError(Context(), ErrInvalidInput, xmsg) 80 } 81 82 func NewArrayDefMismatchNoCtx(expected, actual int) *Error { 83 xmsg := fmt.Sprintf("expected vector dimension %v != actual dimension %v.", expected, actual) 84 return newError(Context(), ErrInvalidInput, xmsg) 85 } 86 87 func NewSyntaxErrorNoCtx(msg string, args ...any) *Error { 88 xmsg := fmt.Sprintf(msg, args...) 89 return newError(Context(), ErrSyntaxError, xmsg) 90 } 91 92 func NewParseErrorNoCtx(msg string, args ...any) *Error { 93 xmsg := fmt.Sprintf(msg, args...) 94 return newError(Context(), ErrParseError, xmsg) 95 } 96 97 func NewConstraintViolationNoCtx(msg string, args ...any) *Error { 98 xmsg := fmt.Sprintf(msg, args...) 99 return newError(Context(), ErrConstraintViolation, xmsg) 100 } 101 102 func NewEmptyVectorNoCtx() *Error { 103 return newError(Context(), ErrEmptyVector) 104 } 105 106 func NewFileNotFoundNoCtx(f string) *Error { 107 return newError(Context(), ErrFileNotFound, f) 108 } 109 110 func NewFileAlreadyExistsNoCtx(f string) *Error { 111 return newError(Context(), ErrFileAlreadyExists, f) 112 } 113 114 func NewDBAlreadyExistsNoCtx(db string) *Error { 115 return newError(Context(), ErrDBAlreadyExists, db) 116 } 117 118 func NewTableAlreadyExistsNoCtx(t string) *Error { 119 return newError(Context(), ErrTableAlreadyExists, t) 120 } 121 122 func NewUnexpectedEOFNoCtx(f string) *Error { 123 return newError(Context(), ErrUnexpectedEOF, f) 124 } 125 126 func NewEmptyRangeNoCtx(f string) *Error { 127 return newError(Context(), ErrEmptyRange, f) 128 } 129 130 func NewSizeNotMatchNoCtx(f string) *Error { 131 return newError(Context(), ErrSizeNotMatch, f) 132 } 133 134 func NewInvalidPathNoCtx(f string) *Error { 135 return newError(Context(), ErrInvalidPath, f) 136 } 137 138 func NewInvalidStateNoCtx(msg string, args ...any) *Error { 139 xmsg := fmt.Sprintf(msg, args...) 140 return newError(Context(), ErrInvalidState, xmsg) 141 } 142 143 func NewInvalidServiceIndexNoCtx(idx int) *Error { 144 return newError(Context(), ErrInvalidServiceIndex, idx) 145 } 146 147 func NewBadDBNoCtx(name string) *Error { 148 return newError(Context(), ErrBadDB, name) 149 } 150 151 func NewNoDBNoCtx() *Error { 152 return newError(Context(), ErrNoDB) 153 } 154 155 func NewNoWorkingStoreNoCtx() *Error { 156 return newError(Context(), ErrNoWorkingStore) 157 } 158 159 func NewNoServiceNoCtx(name string) *Error { 160 return newError(Context(), ErrNoService, name) 161 } 162 163 func NewDupServiceNameNoCtx(name string) *Error { 164 return newError(Context(), ErrDupServiceName, name) 165 } 166 167 func NewWrongServiceNoCtx(exp, got string) *Error { 168 return newError(Context(), ErrWrongService, exp, got) 169 } 170 171 func NewNoSuchTableNoCtx(db, tbl string) *Error { 172 return newError(Context(), ErrNoSuchTable, db, tbl) 173 } 174 175 func NewClientClosedNoCtx() *Error { 176 return newError(Context(), ErrClientClosed) 177 } 178 179 func NewBackendClosedNoCtx() *Error { 180 return newError(Context(), ErrBackendClosed) 181 } 182 183 func NewStreamClosedNoCtx() *Error { 184 return newError(Context(), ErrStreamClosed) 185 } 186 187 func NewNoAvailableBackendNoCtx() *Error { 188 return newError(Context(), ErrNoAvailableBackend) 189 } 190 191 func NewBackendCannotConnectNoCtx(args ...any) *Error { 192 if len(args) == 0 { 193 return newError(Context(), ErrBackendCannotConnect, "none") 194 } 195 return newError(Context(), ErrBackendCannotConnect, args...) 196 } 197 198 func NewTxnClosedNoCtx(txnID []byte) *Error { 199 id := "unknown" 200 if len(txnID) > 0 { 201 id = hex.EncodeToString(txnID) 202 } 203 return newError(Context(), ErrTxnClosed, id) 204 } 205 206 func NewTxnWriteConflictNoCtx(msg string, args ...any) *Error { 207 xmsg := fmt.Sprintf(msg, args...) 208 return newError(Context(), ErrTxnWriteConflict, xmsg) 209 } 210 211 func NewMissingTxnNoCtx() *Error { 212 return newError(Context(), ErrMissingTxn) 213 } 214 215 func NewTAEErrorNoCtx(msg string, args ...any) *Error { 216 xmsg := fmt.Sprintf(msg, args...) 217 return newError(Context(), ErrTAEError, xmsg) 218 } 219 220 func NewTNShardNotFoundNoCtx(uuid string, id uint64) *Error { 221 return newError(Context(), ErrTNShardNotFound, uuid, id) 222 } 223 224 func NewShardNotReportedNoCtx(uuid string, id uint64) *Error { 225 return newError(Context(), ErrShardNotReported, uuid, id) 226 } 227 228 func NewRpcErrorNoCtx(msg string) *Error { 229 return newError(Context(), ErrRpcError, msg) 230 } 231 232 func NewTxnNotFoundNoCtx() *Error { 233 return newError(Context(), ErrTxnNotFound) 234 } 235 236 func NewTxnNotActiveNoCtx(st string) *Error { 237 return newError(Context(), ErrTxnNotActive, st) 238 } 239 240 func NewTAECommitNoCtx(msg string, args ...any) *Error { 241 xmsg := fmt.Sprintf(msg, args...) 242 return newError(Context(), ErrTAECommit, xmsg) 243 } 244 245 func NewTAERollbackNoCtx(msg string, args ...any) *Error { 246 xmsg := fmt.Sprintf(msg, args...) 247 return newError(Context(), ErrTAERollback, xmsg) 248 } 249 250 func NewTAEPrepareNoCtx(msg string, args ...any) *Error { 251 xmsg := fmt.Sprintf(msg, args...) 252 return newError(Context(), ErrTAEPrepare, xmsg) 253 } 254 255 func NewTxnRWConflictNoCtx() *Error { 256 return newError(Context(), ErrTxnRWConflict) 257 } 258 259 func NewTxnWWConflictNoCtx( 260 tableID uint64, 261 s string) *Error { 262 return NewTxnWWConflict(Context(), tableID, s) 263 } 264 265 func NewTAENeedRetryNoCtx() *Error { 266 return newError(Context(), ErrTAENeedRetry) 267 } 268 269 func NewTxnStaleNoCtx() *Error { 270 return newError(Context(), ErrTxnStale) 271 } 272 273 func NewWaiterPausedNoCtx() *Error { 274 return newError(Context(), ErrWaiterPaused) 275 } 276 277 func NewRetryForCNRollingRestart() *Error { 278 return newError(Context(), ErrRetryForCNRollingRestart) 279 } 280 281 func NewNewTxnInCNRollingRestart() *Error { 282 return newError(Context(), ErrNewTxnInCNRollingRestart) 283 } 284 285 func NewPrevCheckpointNotFinished() *Error { 286 return newError(Context(), ErrPrevCheckpointNotFinished) 287 } 288 289 func NewNotFoundNoCtx() *Error { 290 return newError(Context(), ErrNotFound) 291 } 292 293 func NewDuplicateNoCtx() *Error { 294 return newError(Context(), ErrDuplicate) 295 } 296 297 func NewDuplicateEntryNoCtx(entry string, key string) *Error { 298 return newError(Context(), ErrDuplicateEntry, entry, key) 299 } 300 301 func NewRoleGrantedToSelfNoCtx(from, to string) *Error { 302 return newError(Context(), ErrRoleGrantedToSelf, from, to) 303 } 304 305 func NewTxnReadConflictNoCtx(msg string, args ...any) *Error { 306 xmsg := fmt.Sprintf(msg, args...) 307 return newError(Context(), ErrTxnReadConflict, xmsg) 308 } 309 310 func NewAppendableObjectNotFoundNoCtx() *Error { 311 return newError(Context(), ErrAppendableObjectNotFound) 312 } 313 314 func NewAppendableBlockNotFoundNoCtx() *Error { 315 return newError(Context(), ErrAppendableBlockNotFound) 316 } 317 318 func NewDeadLockDetectedNoCtx() *Error { 319 return newError(Context(), ErrDeadLockDetected) 320 } 321 322 func NewDeadlockCheckBusyNoCtx() *Error { 323 return newError(Context(), ErrDeadlockCheckBusy) 324 } 325 326 func NewCannotCommitOrphanNoCtx() *Error { 327 return NewCannotCommitOrphan(Context()) 328 } 329 330 func NewLockTableBindChangedNoCtx() *Error { 331 return newError(Context(), ErrLockTableBindChanged) 332 } 333 334 func NewLockTableNotFoundNoCtx() *Error { 335 return newError(Context(), ErrLockTableNotFound) 336 } 337 338 func NewLockConflictNoCtx() *Error { 339 return newError(Context(), ErrLockConflict) 340 } 341 342 func NewUDFAlreadyExistsNoCtx(f string) *Error { 343 return newError(Context(), ErrFunctionAlreadyExists, f) 344 } 345 346 func NewNoUDFNoCtx(f string) *Error { 347 return newError(Context(), ErrDropNonExistsFunction, f) 348 } 349 350 func NewProcedureAlreadyExistsNoCtx(f string) *Error { 351 return newError(Context(), ErrProcedureAlreadyExists, f) 352 } 353 354 func NewTxnNeedRetryNoCtx() *Error { 355 return newError(Context(), ErrTxnNeedRetry) 356 } 357 358 func NewTxnNeedRetryWithDefChangedNoCtx() *Error { 359 return newError(Context(), ErrTxnNeedRetryWithDefChanged) 360 } 361 362 func NewTxnCannotRetryNoCtx() *Error { 363 return newError(Context(), ErrTxnCannotRetry) 364 } 365 366 func NewRPCTimeoutNoCtx() *Error { 367 return NewRPCTimeout(Context()) 368 } 369 370 func NewKeyAlreadyExistsNoCtx() *Error { 371 return newError(Context(), ErrKeyAlreadyExists) 372 } 373 374 func NewArenaFullNoCtx() *Error { 375 return newError(Context(), ErrArenaFull) 376 }