github.com/mithrandie/csvq@v1.18.1/lib/query/error.go (about) 1 package query 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 "reflect" 8 "runtime" 9 "strconv" 10 "strings" 11 12 "github.com/mithrandie/csvq/lib/file" 13 "github.com/mithrandie/csvq/lib/parser" 14 "github.com/mithrandie/csvq/lib/value" 15 ) 16 17 const ExitMessage = "exit" 18 const DefaultUserTriggeredErrorMessage = "triggered error" 19 20 const ( 21 ErrorMessageTemplate = "[L:%d C:%d] %s" 22 ErrorMessageWithFilepathTemplate = "%s [L:%d C:%d] %s" 23 ErrorMessageWithCustomPrefixTemplate = "[%s] %s" 24 25 ErrMsgSignalReceived = "signal received: %s" 26 27 ErrMsgIncorrectCommandUsage = "incorrect usage: %s" 28 ErrMsgInvalidValueExpression = "%s: cannot evaluate as a value" 29 ErrMsgInvalidPath = "%s: %s" 30 ErrMsgIO = "%s" 31 ErrMsgCommit = "failed to commit: %s" 32 ErrMsgRollback = "failed to rollback: %s" 33 ErrMsgCannotDetectFileEncoding = "cannot detect character encoding: %s" 34 ErrMsgFieldAmbiguous = "field %s is ambiguous" 35 ErrMsgFieldNotExist = "field %s does not exist" 36 ErrMsgFieldNotGroupKey = "field %s is not a group key" 37 ErrMsgDuplicateFieldName = "field name %s is a duplicate" 38 ErrMsgNotGroupingRecords = "function %s cannot aggregate not grouping records" 39 ErrMsgNotAllowedAnalyticFunction = "analytic function %s is only available in select clause or order by clause" 40 ErrMsgUndeclaredVariable = "variable %s is undeclared" 41 ErrMsgVariableRedeclared = "variable %s is redeclared" 42 ErrMsgUndefinedConstant = "constant %s is not defined" 43 ErrMsgInvalidUrl = "failed to parse %q as url" 44 ErrMsgUnsupportedUrlScheme = "url scheme %s is not supported" 45 ErrMsgFunctionNotExist = "function %s does not exist" 46 ErrMsgFunctionArgumentsLength = "function %s takes %s" 47 ErrMsgFunctionInvalidArgument = "%s for function %s" 48 ErrMsgNestedAggregateFunctions = "aggregate functions are nested at %s" 49 ErrMsgFunctionRedeclared = "function %s is redeclared" 50 ErrMsgBuiltInFunctionDeclared = "function %s is a built-in function" 51 ErrMsgDuplicateParameter = "parameter %s is a duplicate" 52 ErrMsgSubqueryTooManyRecords = "subquery returns too many records, should return only one record" 53 ErrMsgSubqueryTooManyFields = "subquery returns too many fields, should return only one field" 54 ErrMsgJsonQueryTooManyRecords = "json query returns too many records, should return only one record" 55 ErrMsgLoadJson = "json loading error: %s" 56 ErrMsgJsonLinesStructure = "json lines must be an array of objects" 57 ErrMsgIncorrectLateralUsage = "LATERAL cannot to be used in a RIGHT or FULL outer join" 58 ErrMsgEmptyInlineTable = "inline table is empty" 59 ErrMsgInvalidTableObject = "invalid table object: %s" 60 ErrMsgTableObjectInvalidDelimiter = "invalid delimiter: %s" 61 ErrMsgTableObjectInvalidDelimiterPositions = "invalid delimiter positions: %s" 62 ErrMsgTableObjectInvalidJsonQuery = "invalid json query: %s" 63 ErrMsgTableObjectArgumentsLength = "table object %s takes at most %d arguments" 64 ErrMsgTableObjectJsonArgumentsLength = "table object %s takes exactly %d arguments" 65 ErrMsgTableObjectInvalidArgument = "invalid argument for %s: %s" 66 ErrMsgCursorRedeclared = "cursor %s is redeclared" 67 ErrMsgUndeclaredCursor = "cursor %s is undeclared" 68 ErrMsgCursorClosed = "cursor %s is closed" 69 ErrMsgCursorOpen = "cursor %s is already open" 70 ErrMsgInvalidCursorStatement = "invalid cursor statement: %s" 71 ErrMsgPseudoCursor = "cursor %s is a pseudo cursor" 72 ErrMsgCursorFetchLength = "fetching from cursor %s returns %s" 73 ErrMsgInvalidFetchPosition = "fetching position %s is not an integer value" 74 ErrMsgInlineTableRedefined = "inline table %s is redefined" 75 ErrMsgUndefinedInlineTable = "inline table %s is undefined" 76 ErrMsgInlineTableFieldLength = "select query should return exactly %s for inline table %s" 77 ErrMsgFileNotExist = "file %s does not exist" 78 ErrMsgFileAlreadyExist = "file %s already exists" 79 ErrMsgFileUnableToRead = "file %s is unable to be read" 80 ErrMsgFileLockTimeout = "file %s: lock wait timeout period exceeded" 81 ErrMsgFileNameAmbiguous = "filename %s is ambiguous" 82 ErrMsgDataParsing = "data parse error in %s: %s" 83 ErrMsgDataEncoding = "data encode error: %s" 84 ErrMsgTableFieldLength = "select query should return exactly %s for table %s" 85 ErrMsgTemporaryTableRedeclared = "view %s is redeclared" 86 ErrMsgUndeclaredTemporaryTable = "view %s is undeclared" 87 ErrMsgTemporaryTableFieldLength = "select query should return exactly %s for view %s" 88 ErrMsgDuplicateTableName = "table name %s is a duplicate" 89 ErrMsgTableNotLoaded = "table %s is not loaded" 90 ErrMsgStdinEmpty = "STDIN is empty" 91 ErrMsgInlineTableCannotBeUpdated = "inline table cannot be updated" 92 ErrMsgAliasMustBeSpecifiedForUpdate = "alias to table identification function or URL must be specified for update" 93 ErrMsgRowValueLengthInComparison = "row value should contain exactly %s" 94 ErrMsgFieldLengthInComparison = "select query should return exactly %s" 95 ErrMsgInvalidLimitPercentage = "limit percentage %s is not a float value" 96 ErrMsgInvalidLimitNumber = "limit number of records %s is not an integer value" 97 ErrMsgInvalidOffsetNumber = "offset number %s is not an integer value" 98 ErrMsgCombinedSetFieldLength = "result set to be combined should contain exactly %s" 99 ErrMsgRecursionExceededLimit = "iteration of recursive query exceeded the limit %d" 100 ErrMsgNestedRecursion = "recursive queries are nested" 101 ErrMsgInsertRowValueLength = "row value should contain exactly %s" 102 ErrMsgInsertSelectFieldLength = "select query should return exactly %s" 103 ErrMsgUpdateFieldNotExist = "field %s does not exist in the tables to update" 104 ErrMsgUpdateValueAmbiguous = "value %s to set in the field %s is ambiguous" 105 ErrMsgReplaceKeyNotSet = "replace Key %s is not set" 106 ErrMsgDeleteTableNotSpecified = "tables to delete records are not specified" 107 ErrMsgShowInvalidObjectType = "object type %s is invalid" 108 ErrMsgReplaceValueLength = "%s" 109 ErrMsgSourceInvalidFilePath = "%s is a invalid file path" 110 ErrMsgInvalidFlagName = "%s is an unknown flag" 111 ErrMsgFlagValueNowAllowedFormat = "%s for %s is not allowed" 112 ErrMsgInvalidFlagValue = "%s" 113 ErrMsgAddFlagNotSupportedName = "add flag element syntax does not support %s" 114 ErrMsgRemoveFlagNotSupportedName = "remove flag element syntax does not support %s" 115 ErrMsgInvalidFlagValueToBeRemoved = "%s is an invalid value for %s to specify the element" 116 ErrMsgInvalidRuntimeInformation = "%s is an unknown runtime information" 117 ErrMsgNotTable = "table attributes can only be set on files" 118 ErrMsgInvalidTableAttributeName = "table attribute %s does not exist" 119 ErrMsgTableAttributeValueNotAllowedFormat = "%s for %s is not allowed" 120 ErrMsgInvalidTableAttributeValue = "%s" 121 ErrMsgInvalidEventName = "%s is an unknown event" 122 ErrMsgInternalRecordIdNotExist = "internal record id does not exist" 123 ErrMsgInternalRecordIdEmpty = "internal record id is empty" 124 ErrMsgFieldLengthNotMatch = "field length does not match" 125 ErrMsgRowValueLengthInList = "row value length does not match at index %d" 126 ErrMsgFormatStringLengthNotMatch = "number of replace values does not match" 127 ErrMsgUnknownFormatPlaceholder = "%q is an unknown placeholder" 128 ErrMsgFormatUnexpectedTermination = "unexpected termination of format string" 129 ErrMsgExternalCommand = "external command: %s" 130 ErrMsgHttpRequest = "failed to get resource from %s: %s" 131 ErrMsgInvalidReloadType = "%s is an unknown reload type" 132 ErrMsgLoadConfiguration = "configuration loading error: %s" 133 ErrMsgDuplicateStatementName = "statement %s is a duplicate" 134 ErrMsgStatementNotExist = "statement %s does not exist" 135 ErrMsgStatementReplaceValueNotSpecified = "replace value for %s is not specified" 136 ErrMsgSelectIntoQueryFieldLengthNotMatch = "select into query should return exactly %s" 137 ErrMsgSelectIntoQueryTooManyRecords = "select into query returns too many records, should return only one record" 138 ErrMsgIntegerDevidedByZero = "integer divided by zero" 139 ) 140 141 type Error interface { 142 Error() string 143 Message() string 144 Code() int 145 Number() int 146 Line() int 147 Char() int 148 Source() string 149 appendCompositeError(Error) 150 } 151 152 type BaseError struct { 153 source string 154 line int 155 char int 156 message string 157 code int 158 number int 159 prefix string 160 compositeErrs []Error 161 } 162 163 func (e *BaseError) Error() string { 164 msg := e.err() 165 if e.compositeErrs != nil { 166 msglist := make([]string, 0, len(e.compositeErrs)+1) 167 msglist = append(msglist, "composite error:") 168 msglist = append(msglist, msg) 169 for _, ce := range e.compositeErrs { 170 msglist = append(msglist, ce.Error()) 171 } 172 msg = strings.Join(msglist, "\n ") 173 } 174 return msg 175 } 176 177 func (e *BaseError) err() string { 178 if 0 < len(e.prefix) { 179 return fmt.Sprintf(ErrorMessageWithCustomPrefixTemplate, e.prefix, e.message) 180 } 181 if e.line < 1 { 182 return e.message 183 } 184 if 0 < len(e.source) { 185 return fmt.Sprintf(ErrorMessageWithFilepathTemplate, e.source, e.line, e.char, e.message) 186 } 187 return fmt.Sprintf(ErrorMessageTemplate, e.line, e.char, e.message) 188 } 189 190 func (e *BaseError) Message() string { 191 return e.message 192 } 193 194 func (e *BaseError) Code() int { 195 return e.code 196 } 197 198 func (e *BaseError) Number() int { 199 return e.number 200 } 201 202 func (e *BaseError) Line() int { 203 return e.line 204 } 205 206 func (e *BaseError) Char() int { 207 return e.char 208 } 209 210 func (e *BaseError) Source() string { 211 return e.source 212 } 213 214 func (e *BaseError) appendCompositeError(err Error) { 215 e.compositeErrs = append(e.compositeErrs, err) 216 } 217 218 func appendCompositeError(e1 error, e2 error) error { 219 if e1 == nil { 220 return e2 221 } 222 if e2 == nil { 223 return e1 224 } 225 appe1, ok := e1.(Error) 226 if !ok { 227 appe1 = NewSystemError(e1.Error()).(Error) 228 } 229 appe2, ok := e2.(Error) 230 if !ok { 231 appe2 = NewSystemError(e2.Error()).(Error) 232 } 233 appe1.appendCompositeError(appe2) 234 return appe1 235 } 236 237 func NewBaseError(expr parser.Expression, message string, code int, number int) *BaseError { 238 var sourceFile string 239 var line int 240 var char int 241 if expr != nil && expr.HasParseInfo() { 242 sourceFile = expr.SourceFile() 243 line = expr.Line() 244 char = expr.Char() 245 } 246 247 return &BaseError{ 248 source: sourceFile, 249 line: line, 250 char: char, 251 message: message, 252 code: code, 253 number: number, 254 prefix: "", 255 } 256 } 257 258 func NewBaseErrorWithPrefix(prefix string, message string, code int, number int) *BaseError { 259 return &BaseError{ 260 source: "", 261 line: 0, 262 char: 0, 263 message: message, 264 code: code, 265 number: number, 266 prefix: prefix, 267 } 268 } 269 270 type FatalError struct { 271 *BaseError 272 } 273 274 func NewFatalError(panicReport interface{}) error { 275 stacks := make([]string, 0, 30) 276 for depth := 0; ; depth++ { 277 pc, src, line, ok := runtime.Caller(depth) 278 if !ok { 279 break 280 } 281 if depth == 0 { 282 continue 283 } 284 stacks = append(stacks, fmt.Sprintf(" %d: %s [%s:%d]", depth-1, runtime.FuncForPC(pc).Name(), src, line)) 285 } 286 287 message := fmt.Sprintf("%v\n", panicReport) + 288 "An unexpected error has occurred. Please report this problem to: https://github.com/mithrandie/csvq/issues\n" + 289 "\n" + 290 "Stack:\n" + 291 strings.Join(stacks, "\n") 292 293 return &FatalError{ 294 NewBaseErrorWithPrefix("Fatal Error", message, ReturnCodeApplicationError, ErrorFatal), 295 } 296 } 297 298 type SystemError struct { 299 *BaseError 300 } 301 302 func NewSystemError(message string) error { 303 return &SystemError{ 304 NewBaseErrorWithPrefix("System Error", message, ReturnCodeSystemError, ErrorSystemError), 305 } 306 } 307 308 type ForcedExit struct { 309 *BaseError 310 } 311 312 func NewForcedExit(code int) error { 313 return &ForcedExit{&BaseError{message: ExitMessage, code: code, number: ErrorExit}} 314 } 315 316 type UserTriggeredError struct { 317 *BaseError 318 } 319 320 func NewUserTriggeredError(expr parser.Trigger, message string) error { 321 code := ReturnCodeDefaultUserTriggeredError 322 if expr.Code != nil { 323 code = int(expr.Code.(*value.Integer).Raw()) 324 } 325 326 if len(message) < 1 { 327 message = DefaultUserTriggeredErrorMessage 328 } 329 330 return &UserTriggeredError{ 331 NewBaseError(expr, message, code, ErrorUserTriggered), 332 } 333 } 334 335 type SignalReceived struct { 336 *BaseError 337 } 338 339 func NewSignalReceived(sig os.Signal) error { 340 v := reflect.ValueOf(sig) 341 code := int(v.Int()) 342 return &SignalReceived{ 343 NewBaseErrorWithPrefix("", fmt.Sprintf(ErrMsgSignalReceived, sig.String()), returnCodeBaseSignal+code, errorSignalBase+code), 344 } 345 } 346 347 type SyntaxError struct { 348 *BaseError 349 } 350 351 func NewSyntaxError(err *parser.SyntaxError) error { 352 return &SyntaxError{ 353 &BaseError{ 354 source: err.SourceFile, 355 line: err.Line, 356 char: err.Char, 357 message: err.Message, 358 code: ReturnCodeSyntaxError, 359 number: ErrorSyntaxError, 360 }, 361 } 362 } 363 364 type PreparedStatementSyntaxError struct { 365 *BaseError 366 } 367 368 func NewPreparedStatementSyntaxError(err *parser.SyntaxError) error { 369 return &PreparedStatementSyntaxError{ 370 &BaseError{ 371 source: fmt.Sprintf("prepare %s", err.SourceFile), 372 line: err.Line, 373 char: err.Char, 374 message: err.Message, 375 code: ReturnCodeSyntaxError, 376 number: ErrorPreparedStatementSyntaxError, 377 }, 378 } 379 } 380 381 type ContextCanceled struct { 382 *BaseError 383 } 384 385 func NewContextCanceled(message string) error { 386 return &ContextDone{ 387 NewBaseErrorWithPrefix("Context", message, ReturnCodeContextDone, ErrorContextCanceled), 388 } 389 } 390 391 type ContextDone struct { 392 *BaseError 393 } 394 395 func NewContextDone(message string) error { 396 return &ContextDone{ 397 NewBaseErrorWithPrefix("Context", message, ReturnCodeContextDone, ErrorContextDone), 398 } 399 } 400 401 type IncorrectCommandUsageError struct { 402 *BaseError 403 } 404 405 func NewIncorrectCommandUsageError(message string) error { 406 return &IncorrectCommandUsageError{ 407 NewBaseErrorWithPrefix("", fmt.Sprintf(ErrMsgIncorrectCommandUsage, message), ReturnCodeIncorrectUsage, ErrorIncorrectCommandUsage), 408 } 409 } 410 411 type InvalidValueExpressionError struct { 412 *BaseError 413 } 414 415 func NewInvalidValueExpressionError(expr parser.QueryExpression) error { 416 return &InvalidValueExpressionError{ 417 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidValueExpression, expr), ReturnCodeSyntaxError, ErrorInvalidValueExpression), 418 } 419 } 420 421 type InvalidPathError struct { 422 *BaseError 423 } 424 425 func NewInvalidPathError(expr parser.Expression, path string, message string) error { 426 return &InvalidPathError{ 427 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidPath, path, message), ReturnCodeIOError, ErrorInvalidPath), 428 } 429 } 430 431 type IOError struct { 432 *BaseError 433 } 434 435 func NewIOError(expr parser.QueryExpression, message string) error { 436 return &IOError{ 437 NewBaseError(expr, fmt.Sprintf(ErrMsgIO, message), ReturnCodeIOError, ErrorIO), 438 } 439 } 440 441 type CommitError struct { 442 *BaseError 443 } 444 445 func NewCommitError(expr parser.Expression, message string) error { 446 if expr == nil { 447 return &CommitError{ 448 NewBaseErrorWithPrefix("Auto Commit", fmt.Sprintf(ErrMsgCommit, message), ReturnCodeIOError, ErrorCommit), 449 } 450 } 451 return &CommitError{ 452 NewBaseError(expr, fmt.Sprintf(ErrMsgCommit, message), ReturnCodeIOError, ErrorCommit), 453 } 454 } 455 456 type RollbackError struct { 457 *BaseError 458 } 459 460 func NewRollbackError(expr parser.Expression, message string) error { 461 if expr == nil { 462 return &RollbackError{ 463 NewBaseErrorWithPrefix("Auto Rollback", fmt.Sprintf(ErrMsgRollback, message), ReturnCodeIOError, ErrorRollback), 464 } 465 } 466 return &RollbackError{ 467 NewBaseError(expr, fmt.Sprintf(ErrMsgRollback, message), ReturnCodeIOError, ErrorRollback), 468 } 469 } 470 471 type CannotDetectFileEncodingError struct { 472 *BaseError 473 } 474 475 func NewCannotDetectFileEncodingError(file parser.QueryExpression) error { 476 return &CannotDetectFileEncodingError{ 477 NewBaseError(file, fmt.Sprintf(ErrMsgCannotDetectFileEncoding, file), ReturnCodeApplicationError, ErrorCannotDetectFileEncoding), 478 } 479 } 480 481 type FieldAmbiguousError struct { 482 *BaseError 483 } 484 485 func NewFieldAmbiguousError(field parser.QueryExpression) error { 486 return &FieldAmbiguousError{ 487 NewBaseError(field, fmt.Sprintf(ErrMsgFieldAmbiguous, field), ReturnCodeApplicationError, ErrorFieldAmbiguous), 488 } 489 } 490 491 type FieldNotExistError struct { 492 *BaseError 493 } 494 495 func NewFieldNotExistError(field parser.QueryExpression) error { 496 return &FieldNotExistError{ 497 NewBaseError(field, fmt.Sprintf(ErrMsgFieldNotExist, field), ReturnCodeApplicationError, ErrorFieldNotExist), 498 } 499 } 500 501 type FieldNotGroupKeyError struct { 502 *BaseError 503 } 504 505 func NewFieldNotGroupKeyError(field parser.QueryExpression) error { 506 return &FieldNotGroupKeyError{ 507 NewBaseError(field, fmt.Sprintf(ErrMsgFieldNotGroupKey, field), ReturnCodeApplicationError, ErrorFieldNotGroupKey), 508 } 509 } 510 511 type DuplicateFieldNameError struct { 512 *BaseError 513 } 514 515 func NewDuplicateFieldNameError(fieldName parser.Identifier) error { 516 return &DuplicateFieldNameError{ 517 NewBaseError(fieldName, fmt.Sprintf(ErrMsgDuplicateFieldName, fieldName), ReturnCodeApplicationError, ErrorDuplicateFieldName), 518 } 519 } 520 521 type NotGroupingRecordsError struct { 522 *BaseError 523 } 524 525 func NewNotGroupingRecordsError(expr parser.QueryExpression, funcname string) error { 526 return &NotGroupingRecordsError{ 527 NewBaseError(expr, fmt.Sprintf(ErrMsgNotGroupingRecords, funcname), ReturnCodeApplicationError, ErrorNotGroupingRecords), 528 } 529 } 530 531 type NotAllowedAnalyticFunctionError struct { 532 *BaseError 533 } 534 535 func NewNotAllowedAnalyticFunctionError(expr parser.AnalyticFunction) error { 536 return &NotAllowedAnalyticFunctionError{ 537 NewBaseError(expr, fmt.Sprintf(ErrMsgNotAllowedAnalyticFunction, expr.Name), ReturnCodeApplicationError, ErrorNotAllowedAnalyticFunction), 538 } 539 } 540 541 type UndeclaredVariableError struct { 542 *BaseError 543 } 544 545 func NewUndeclaredVariableError(expr parser.Variable) error { 546 return &UndeclaredVariableError{ 547 NewBaseError(expr, fmt.Sprintf(ErrMsgUndeclaredVariable, expr), ReturnCodeApplicationError, ErrorUndeclaredVariable), 548 } 549 } 550 551 type VariableRedeclaredError struct { 552 *BaseError 553 } 554 555 func NewVariableRedeclaredError(expr parser.Variable) error { 556 return &VariableRedeclaredError{ 557 NewBaseError(expr, fmt.Sprintf(ErrMsgVariableRedeclared, expr), ReturnCodeApplicationError, ErrorVariableRedeclared), 558 } 559 } 560 561 type UndefinedConstantError struct { 562 *BaseError 563 } 564 565 func NewUndefinedConstantError(expr parser.Constant) error { 566 return &UndefinedConstantError{ 567 NewBaseError(expr, fmt.Sprintf(ErrMsgUndefinedConstant, expr), ReturnCodeApplicationError, ErrorUndefinedConstant), 568 } 569 } 570 571 type InvalidUrlError struct { 572 *BaseError 573 } 574 575 func NewInvalidUrlError(expr parser.Url) error { 576 return &InvalidUrlError{ 577 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidUrl, expr), ReturnCodeApplicationError, ErrorInvalidUrl), 578 } 579 } 580 581 type UnsupportedUrlSchemeError struct { 582 *BaseError 583 } 584 585 func NewUnsupportedUrlSchemeError(expr parser.Url, scheme string) error { 586 return &UnsupportedUrlSchemeError{ 587 NewBaseError(expr, fmt.Sprintf(ErrMsgUnsupportedUrlScheme, scheme), ReturnCodeApplicationError, ErrorUnsupportedUrlScheme), 588 } 589 } 590 591 type FunctionNotExistError struct { 592 *BaseError 593 } 594 595 func NewFunctionNotExistError(expr parser.QueryExpression, funcname string) error { 596 return &FunctionNotExistError{ 597 NewBaseError(expr, fmt.Sprintf(ErrMsgFunctionNotExist, funcname), ReturnCodeApplicationError, ErrorFunctionNotExist), 598 } 599 } 600 601 type FunctionArgumentLengthError struct { 602 *BaseError 603 } 604 605 func NewFunctionArgumentLengthError(expr parser.QueryExpression, funcname string, argslen []int) error { 606 var argstr string 607 if 1 < len(argslen) { 608 first := argslen[0] 609 last := argslen[len(argslen)-1] 610 lastarg := FormatCount(last, "argument") 611 if len(argslen) == 2 { 612 argstr = strconv.Itoa(first) + " or " + lastarg 613 } else { 614 argstr = strconv.Itoa(first) + " to " + lastarg 615 } 616 } else { 617 argstr = FormatCount(argslen[0], "argument") 618 if 0 < argslen[0] { 619 argstr = "exactly " + argstr 620 } 621 } 622 return &FunctionArgumentLengthError{ 623 NewBaseError(expr, fmt.Sprintf(ErrMsgFunctionArgumentsLength, funcname, argstr), ReturnCodeApplicationError, ErrorFunctionArgumentsLength), 624 } 625 } 626 627 func NewFunctionArgumentLengthErrorWithCustomArgs(expr parser.QueryExpression, funcname string, argstr string) error { 628 return &FunctionArgumentLengthError{ 629 NewBaseError(expr, fmt.Sprintf(ErrMsgFunctionArgumentsLength, funcname, argstr), ReturnCodeApplicationError, ErrorFunctionArgumentsLength), 630 } 631 } 632 633 type FunctionInvalidArgumentError struct { 634 *BaseError 635 } 636 637 func NewFunctionInvalidArgumentError(function parser.QueryExpression, funcname string, message string) error { 638 return &FunctionInvalidArgumentError{ 639 NewBaseError(function, fmt.Sprintf(ErrMsgFunctionInvalidArgument, message, funcname), ReturnCodeApplicationError, ErrorFunctionInvalidArgument), 640 } 641 } 642 643 type NestedAggregateFunctionsError struct { 644 *BaseError 645 } 646 647 func NewNestedAggregateFunctionsError(expr parser.QueryExpression) error { 648 return &NestedAggregateFunctionsError{ 649 NewBaseError(expr, fmt.Sprintf(ErrMsgNestedAggregateFunctions, expr), ReturnCodeSyntaxError, ErrorNestedAggregateFunctions), 650 } 651 } 652 653 type FunctionRedeclaredError struct { 654 *BaseError 655 } 656 657 func NewFunctionRedeclaredError(expr parser.Identifier) error { 658 return &FunctionRedeclaredError{ 659 NewBaseError(expr, fmt.Sprintf(ErrMsgFunctionRedeclared, expr.Literal), ReturnCodeApplicationError, ErrorFunctionRedeclared), 660 } 661 } 662 663 type BuiltInFunctionDeclaredError struct { 664 *BaseError 665 } 666 667 func NewBuiltInFunctionDeclaredError(expr parser.Identifier) error { 668 return &BuiltInFunctionDeclaredError{ 669 NewBaseError(expr, fmt.Sprintf(ErrMsgBuiltInFunctionDeclared, expr.Literal), ReturnCodeApplicationError, ErrorBuiltInFunctionDeclared), 670 } 671 } 672 673 type DuplicateParameterError struct { 674 *BaseError 675 } 676 677 func NewDuplicateParameterError(expr parser.Variable) error { 678 return &DuplicateParameterError{ 679 NewBaseError(expr, fmt.Sprintf(ErrMsgDuplicateParameter, expr.String()), ReturnCodeApplicationError, ErrorDuplicateParameter), 680 } 681 } 682 683 type SubqueryTooManyRecordsError struct { 684 *BaseError 685 } 686 687 func NewSubqueryTooManyRecordsError(expr parser.Subquery) error { 688 return &SubqueryTooManyRecordsError{ 689 NewBaseError(expr, ErrMsgSubqueryTooManyRecords, ReturnCodeApplicationError, ErrorSubqueryTooManyRecords), 690 } 691 } 692 693 type SubqueryTooManyFieldsError struct { 694 *BaseError 695 } 696 697 func NewSubqueryTooManyFieldsError(expr parser.Subquery) error { 698 return &SubqueryTooManyFieldsError{ 699 NewBaseError(expr, ErrMsgSubqueryTooManyFields, ReturnCodeApplicationError, ErrorSubqueryTooManyFields), 700 } 701 } 702 703 type JsonQueryTooManyRecordsError struct { 704 *BaseError 705 } 706 707 func NewJsonQueryTooManyRecordsError(expr parser.JsonQuery) error { 708 return &JsonQueryTooManyRecordsError{ 709 NewBaseError(expr, ErrMsgJsonQueryTooManyRecords, ReturnCodeApplicationError, ErrorJsonQueryTooManyRecords), 710 } 711 } 712 713 type LoadJsonError struct { 714 *BaseError 715 } 716 717 func NewLoadJsonError(expr parser.QueryExpression, message string) error { 718 return &LoadJsonError{ 719 NewBaseError(expr, fmt.Sprintf(ErrMsgLoadJson, message), ReturnCodeApplicationError, ErrorLoadJson), 720 } 721 } 722 723 type JsonLinesStructureError struct { 724 *BaseError 725 } 726 727 func NewJsonLinesStructureError(expr parser.QueryExpression) error { 728 return &JsonLinesStructureError{ 729 NewBaseError(expr, ErrMsgJsonLinesStructure, ReturnCodeApplicationError, ErrorJsonLinesStructure), 730 } 731 } 732 733 type IncorrectLateralUsageError struct { 734 *BaseError 735 } 736 737 func NewIncorrectLateralUsageError(expr parser.Table) error { 738 return &IncorrectLateralUsageError{ 739 NewBaseError(expr, ErrMsgIncorrectLateralUsage, ReturnCodeApplicationError, ErrorIncorrectLateralUsage), 740 } 741 } 742 743 type EmptyInlineTableError struct { 744 *BaseError 745 } 746 747 func NewEmptyInlineTableError(expr parser.FormatSpecifiedFunction) error { 748 return &EmptyInlineTableError{ 749 NewBaseError(expr, ErrMsgEmptyInlineTable, ReturnCodeApplicationError, ErrorEmptyInlineTable), 750 } 751 } 752 753 type InvalidTableObjectError struct { 754 *BaseError 755 } 756 757 func NewInvalidTableObjectError(expr parser.FormatSpecifiedFunction, objectName string) error { 758 return &InvalidTableObjectError{ 759 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidTableObject, objectName), ReturnCodeApplicationError, ErrorInvalidTableObject), 760 } 761 } 762 763 type TableObjectInvalidDelimiterError struct { 764 *BaseError 765 } 766 767 func NewTableObjectInvalidDelimiterError(expr parser.FormatSpecifiedFunction, delimiter string) error { 768 return &InvalidTableObjectError{ 769 NewBaseError(expr, fmt.Sprintf(ErrMsgTableObjectInvalidDelimiter, delimiter), ReturnCodeApplicationError, ErrorTableObjectInvalidDelimiter), 770 } 771 } 772 773 type TableObjectInvalidDelimiterPositionsError struct { 774 *BaseError 775 } 776 777 func NewTableObjectInvalidDelimiterPositionsError(expr parser.FormatSpecifiedFunction, positions string) error { 778 return &InvalidTableObjectError{ 779 NewBaseError(expr, fmt.Sprintf(ErrMsgTableObjectInvalidDelimiterPositions, positions), ReturnCodeApplicationError, ErrorTableObjectInvalidDelimiterPositions), 780 } 781 } 782 783 type TableObjectInvalidJsonQueryError struct { 784 *BaseError 785 } 786 787 func NewTableObjectInvalidJsonQueryError(expr parser.FormatSpecifiedFunction, jsonQuery string) error { 788 return &InvalidTableObjectError{ 789 NewBaseError(expr, fmt.Sprintf(ErrMsgTableObjectInvalidJsonQuery, jsonQuery), ReturnCodeApplicationError, ErrorTableObjectInvalidJsonQuery), 790 } 791 } 792 793 type TableObjectArgumentsLengthError struct { 794 *BaseError 795 } 796 797 func NewTableObjectArgumentsLengthError(expr parser.FormatSpecifiedFunction, argLen int) error { 798 return &TableObjectArgumentsLengthError{ 799 NewBaseError(expr, fmt.Sprintf(ErrMsgTableObjectArgumentsLength, expr.Type.Literal, argLen), ReturnCodeApplicationError, ErrorTableObjectArgumentsLength), 800 } 801 } 802 803 type TableObjectJsonArgumentsLengthError struct { 804 *BaseError 805 } 806 807 func NewTableObjectJsonArgumentsLengthError(expr parser.FormatSpecifiedFunction, argLen int) error { 808 return &TableObjectJsonArgumentsLengthError{ 809 NewBaseError(expr, fmt.Sprintf(ErrMsgTableObjectJsonArgumentsLength, expr.Type.Literal, argLen), ReturnCodeApplicationError, ErrorTableObjectJsonArgumentsLength), 810 } 811 } 812 813 type TableObjectInvalidArgumentError struct { 814 *BaseError 815 } 816 817 func NewTableObjectInvalidArgumentError(expr parser.FormatSpecifiedFunction, message string) error { 818 return &TableObjectInvalidArgumentError{ 819 NewBaseError(expr, fmt.Sprintf(ErrMsgTableObjectInvalidArgument, expr.Type.Literal, message), ReturnCodeApplicationError, ErrorTableObjectInvalidArgument), 820 } 821 } 822 823 type CursorRedeclaredError struct { 824 *BaseError 825 } 826 827 func NewCursorRedeclaredError(cursor parser.Identifier) error { 828 return &CursorRedeclaredError{ 829 NewBaseError(cursor, fmt.Sprintf(ErrMsgCursorRedeclared, cursor), ReturnCodeApplicationError, ErrorCursorRedeclared), 830 } 831 } 832 833 type UndeclaredCursorError struct { 834 *BaseError 835 } 836 837 func NewUndeclaredCursorError(cursor parser.Identifier) error { 838 return &UndeclaredCursorError{ 839 NewBaseError(cursor, fmt.Sprintf(ErrMsgUndeclaredCursor, cursor), ReturnCodeApplicationError, ErrorUndeclaredCursor), 840 } 841 } 842 843 type CursorClosedError struct { 844 *BaseError 845 } 846 847 func NewCursorClosedError(cursor parser.Identifier) error { 848 return &CursorClosedError{ 849 NewBaseError(cursor, fmt.Sprintf(ErrMsgCursorClosed, cursor), ReturnCodeApplicationError, ErrorCursorClosed), 850 } 851 } 852 853 type CursorOpenError struct { 854 *BaseError 855 } 856 857 func NewCursorOpenError(cursor parser.Identifier) error { 858 return &CursorOpenError{ 859 NewBaseError(cursor, fmt.Sprintf(ErrMsgCursorOpen, cursor), ReturnCodeApplicationError, ErrorCursorOpen), 860 } 861 } 862 863 type InvalidCursorStatementError struct { 864 *BaseError 865 } 866 867 func NewInvalidCursorStatementError(statement parser.Identifier) error { 868 return &InvalidCursorStatementError{ 869 NewBaseError(statement, fmt.Sprintf(ErrMsgInvalidCursorStatement, statement), ReturnCodeApplicationError, ErrorInvalidCursorStatement), 870 } 871 } 872 873 type PseudoCursorError struct { 874 *BaseError 875 } 876 877 func NewPseudoCursorError(cursor parser.Identifier) error { 878 return &PseudoCursorError{ 879 NewBaseError(cursor, fmt.Sprintf(ErrMsgPseudoCursor, cursor), ReturnCodeApplicationError, ErrorPseudoCursor), 880 } 881 } 882 883 type CursorFetchLengthError struct { 884 *BaseError 885 } 886 887 func NewCursorFetchLengthError(cursor parser.Identifier, returnLen int) error { 888 return &CursorFetchLengthError{ 889 NewBaseError(cursor, fmt.Sprintf(ErrMsgCursorFetchLength, cursor, FormatCount(returnLen, "value")), ReturnCodeApplicationError, ErrorCursorFetchLength), 890 } 891 } 892 893 type InvalidFetchPositionError struct { 894 *BaseError 895 } 896 897 func NewInvalidFetchPositionError(position parser.FetchPosition) error { 898 return &InvalidFetchPositionError{ 899 NewBaseError(position, fmt.Sprintf(ErrMsgInvalidFetchPosition, position.Number), ReturnCodeApplicationError, ErrorInvalidFetchPosition), 900 } 901 } 902 903 type InLineTableRedefinedError struct { 904 *BaseError 905 } 906 907 func NewInLineTableRedefinedError(table parser.Identifier) error { 908 return &InLineTableRedefinedError{ 909 NewBaseError(table, fmt.Sprintf(ErrMsgInlineTableRedefined, table), ReturnCodeApplicationError, ErrorInlineTableRedefined), 910 } 911 } 912 913 type UndefinedInLineTableError struct { 914 *BaseError 915 } 916 917 func NewUndefinedInLineTableError(table parser.Identifier) error { 918 return &UndefinedInLineTableError{ 919 NewBaseError(table, fmt.Sprintf(ErrMsgUndefinedInlineTable, table), ReturnCodeApplicationError, ErrorUndefinedInlineTable), 920 } 921 } 922 923 type InlineTableFieldLengthError struct { 924 *BaseError 925 } 926 927 func NewInlineTableFieldLengthError(query parser.SelectQuery, table parser.Identifier, fieldLen int) error { 928 selectClause := searchSelectClause(query) 929 930 return &InlineTableFieldLengthError{ 931 NewBaseError(selectClause, fmt.Sprintf(ErrMsgInlineTableFieldLength, FormatCount(fieldLen, "field"), table), ReturnCodeApplicationError, ErrorInlineTableFieldLength), 932 } 933 } 934 935 type FileNotExistError struct { 936 *BaseError 937 } 938 939 func NewFileNotExistError(file parser.QueryExpression) error { 940 return &FileNotExistError{ 941 NewBaseError(file, fmt.Sprintf(ErrMsgFileNotExist, file), ReturnCodeIOError, ErrorFileNotExist), 942 } 943 } 944 945 type FileAlreadyExistError struct { 946 *BaseError 947 } 948 949 func NewFileAlreadyExistError(file parser.Identifier) error { 950 return &FileAlreadyExistError{ 951 NewBaseError(file, fmt.Sprintf(ErrMsgFileAlreadyExist, file), ReturnCodeIOError, ErrorFileAlreadyExist), 952 } 953 } 954 955 type FileUnableToReadError struct { 956 *BaseError 957 } 958 959 func NewFileUnableToReadError(file parser.Identifier) error { 960 return &FileUnableToReadError{ 961 NewBaseError(file, fmt.Sprintf(ErrMsgFileUnableToRead, file), ReturnCodeIOError, ErrorFileUnableToRead), 962 } 963 } 964 965 type FileLockTimeoutError struct { 966 *BaseError 967 } 968 969 func NewFileLockTimeoutError(file parser.Identifier) error { 970 return &FileLockTimeoutError{ 971 NewBaseError(file, fmt.Sprintf(ErrMsgFileLockTimeout, file.Literal), ReturnCodeContextDone, ErrorFileLockTimeout), 972 } 973 } 974 975 type FileNameAmbiguousError struct { 976 *BaseError 977 } 978 979 func NewFileNameAmbiguousError(file parser.Identifier) error { 980 return &FileNameAmbiguousError{ 981 NewBaseError(file, fmt.Sprintf(ErrMsgFileNameAmbiguous, file), ReturnCodeApplicationError, ErrorFileNameAmbiguous), 982 } 983 } 984 985 type DataParsingError struct { 986 *BaseError 987 } 988 989 func NewDataParsingError(file parser.QueryExpression, filepath string, message string) error { 990 return &DataParsingError{ 991 NewBaseError(file, fmt.Sprintf(ErrMsgDataParsing, filepath, message), ReturnCodeApplicationError, ErrorDataParsing), 992 } 993 } 994 995 type DataEncodingError struct { 996 *BaseError 997 } 998 999 func NewDataEncodingError(message string) error { 1000 return &DataEncodingError{ 1001 NewBaseErrorWithPrefix("", fmt.Sprintf(ErrMsgDataEncoding, message), ReturnCodeApplicationError, ErrorDataEncoding), 1002 } 1003 } 1004 1005 type TableFieldLengthError struct { 1006 *BaseError 1007 } 1008 1009 func NewTableFieldLengthError(query parser.SelectQuery, table parser.Identifier, fieldLen int) error { 1010 selectClause := searchSelectClause(query) 1011 1012 return &TableFieldLengthError{ 1013 NewBaseError(selectClause, fmt.Sprintf(ErrMsgTableFieldLength, FormatCount(fieldLen, "field"), table), ReturnCodeApplicationError, ErrorTableFieldLength), 1014 } 1015 } 1016 1017 type TemporaryTableRedeclaredError struct { 1018 *BaseError 1019 } 1020 1021 func NewTemporaryTableRedeclaredError(table parser.Identifier) error { 1022 return &TemporaryTableRedeclaredError{ 1023 NewBaseError(table, fmt.Sprintf(ErrMsgTemporaryTableRedeclared, table), ReturnCodeApplicationError, ErrorTemporaryTableRedeclared), 1024 } 1025 } 1026 1027 type UndeclaredTemporaryTableError struct { 1028 *BaseError 1029 } 1030 1031 func NewUndeclaredTemporaryTableError(table parser.QueryExpression) error { 1032 return &UndeclaredTemporaryTableError{ 1033 NewBaseError(table, fmt.Sprintf(ErrMsgUndeclaredTemporaryTable, table), ReturnCodeApplicationError, ErrorUndeclaredTemporaryTable), 1034 } 1035 } 1036 1037 type TemporaryTableFieldLengthError struct { 1038 *BaseError 1039 } 1040 1041 func NewTemporaryTableFieldLengthError(query parser.SelectQuery, table parser.Identifier, fieldLen int) error { 1042 selectClause := searchSelectClause(query) 1043 1044 return &TemporaryTableFieldLengthError{ 1045 NewBaseError(selectClause, fmt.Sprintf(ErrMsgTemporaryTableFieldLength, FormatCount(fieldLen, "field"), table), ReturnCodeApplicationError, ErrorTemporaryTableFieldLength), 1046 } 1047 } 1048 1049 type DuplicateTableNameError struct { 1050 *BaseError 1051 } 1052 1053 func NewDuplicateTableNameError(table parser.Identifier) error { 1054 return &DuplicateTableNameError{ 1055 NewBaseError(table, fmt.Sprintf(ErrMsgDuplicateTableName, table), ReturnCodeApplicationError, ErrorDuplicateTableName), 1056 } 1057 } 1058 1059 type TableNotLoadedError struct { 1060 *BaseError 1061 } 1062 1063 func NewTableNotLoadedError(table parser.Identifier) error { 1064 return &TableNotLoadedError{ 1065 NewBaseError(table, fmt.Sprintf(ErrMsgTableNotLoaded, table), ReturnCodeApplicationError, ErrorTableNotLoaded), 1066 } 1067 } 1068 1069 type StdinEmptyError struct { 1070 *BaseError 1071 } 1072 1073 func NewStdinEmptyError(stdin parser.Stdin) error { 1074 return &StdinEmptyError{ 1075 NewBaseError(stdin, ErrMsgStdinEmpty, ReturnCodeApplicationError, ErrorStdinEmpty), 1076 } 1077 } 1078 1079 type InlineTableCannotBeUpdatedError struct { 1080 *BaseError 1081 } 1082 1083 func NewInlineTableCannotBeUpdatedError(expr parser.QueryExpression) error { 1084 return &InlineTableCannotBeUpdatedError{ 1085 NewBaseError(expr, ErrMsgInlineTableCannotBeUpdated, ReturnCodeApplicationError, ErrorInlineTableCannotBeUpdated), 1086 } 1087 } 1088 1089 type AliasMustBeSpecifiedForUpdateError struct { 1090 *BaseError 1091 } 1092 1093 func NewAliasMustBeSpecifiedForUpdateError(expr parser.QueryExpression) error { 1094 return &AliasMustBeSpecifiedForUpdateError{ 1095 NewBaseError(expr, ErrMsgAliasMustBeSpecifiedForUpdate, ReturnCodeApplicationError, ErrorAliasMustBeSpecifiedForUpdate), 1096 } 1097 } 1098 1099 type RowValueLengthInComparisonError struct { 1100 *BaseError 1101 } 1102 1103 func NewRowValueLengthInComparisonError(expr parser.QueryExpression, valueLen int) error { 1104 return &RowValueLengthInComparisonError{ 1105 NewBaseError(expr, fmt.Sprintf(ErrMsgRowValueLengthInComparison, FormatCount(valueLen, "value")), ReturnCodeApplicationError, ErrorRowValueLengthInComparison), 1106 } 1107 } 1108 1109 type SelectFieldLengthInComparisonError struct { 1110 *BaseError 1111 } 1112 1113 func NewSelectFieldLengthInComparisonError(query parser.Subquery, valueLen int) error { 1114 return &SelectFieldLengthInComparisonError{ 1115 NewBaseError(query, fmt.Sprintf(ErrMsgFieldLengthInComparison, FormatCount(valueLen, "field")), ReturnCodeApplicationError, ErrorFieldLengthInComparison), 1116 } 1117 } 1118 1119 type InvalidLimitPercentageError struct { 1120 *BaseError 1121 } 1122 1123 func NewInvalidLimitPercentageError(clause parser.LimitClause) error { 1124 return &InvalidLimitPercentageError{ 1125 NewBaseError(clause, fmt.Sprintf(ErrMsgInvalidLimitPercentage, clause.Value), ReturnCodeApplicationError, ErrorInvalidLimitPercentage), 1126 } 1127 } 1128 1129 type InvalidLimitNumberError struct { 1130 *BaseError 1131 } 1132 1133 func NewInvalidLimitNumberError(clause parser.LimitClause) error { 1134 return &InvalidLimitNumberError{ 1135 NewBaseError(clause, fmt.Sprintf(ErrMsgInvalidLimitNumber, clause.Value), ReturnCodeApplicationError, ErrorInvalidLimitNumber), 1136 } 1137 } 1138 1139 type InvalidOffsetNumberError struct { 1140 *BaseError 1141 } 1142 1143 func NewInvalidOffsetNumberError(clause parser.OffsetClause) error { 1144 return &InvalidOffsetNumberError{ 1145 NewBaseError(clause, fmt.Sprintf(ErrMsgInvalidOffsetNumber, clause.Value), ReturnCodeApplicationError, ErrorInvalidOffsetNumber), 1146 } 1147 } 1148 1149 type CombinedSetFieldLengthError struct { 1150 *BaseError 1151 } 1152 1153 func NewCombinedSetFieldLengthError(selectEntity parser.QueryExpression, fieldLen int) error { 1154 selectClause := searchSelectClauseInSelectEntity(selectEntity) 1155 1156 return &CombinedSetFieldLengthError{ 1157 NewBaseError(selectClause, fmt.Sprintf(ErrMsgCombinedSetFieldLength, FormatCount(fieldLen, "field")), ReturnCodeApplicationError, ErrorCombinedSetFieldLength), 1158 } 1159 } 1160 1161 type RecursionExceededLimitError struct { 1162 *BaseError 1163 } 1164 1165 func NewRecursionExceededLimitError(selectEntity parser.QueryExpression, limit int64) error { 1166 selectClause := searchSelectClauseInSelectEntity(selectEntity) 1167 1168 return &RecursionExceededLimitError{ 1169 NewBaseError(selectClause, fmt.Sprintf(ErrMsgRecursionExceededLimit, limit), ReturnCodeApplicationError, ErrorRecursionExceededLimit), 1170 } 1171 } 1172 1173 type NestedRecursionError struct { 1174 *BaseError 1175 } 1176 1177 func NewNestedRecursionError(expr parser.QueryExpression) error { 1178 return &RecursionExceededLimitError{ 1179 NewBaseError(expr, ErrMsgNestedRecursion, ReturnCodeApplicationError, ErrorNestedRecursion), 1180 } 1181 } 1182 1183 type InsertRowValueLengthError struct { 1184 *BaseError 1185 } 1186 1187 func NewInsertRowValueLengthError(rowValue parser.RowValue, valueLen int) error { 1188 return &InsertRowValueLengthError{ 1189 NewBaseError(rowValue, fmt.Sprintf(ErrMsgInsertRowValueLength, FormatCount(valueLen, "value")), ReturnCodeApplicationError, ErrorInsertRowValueLength), 1190 } 1191 } 1192 1193 type InsertSelectFieldLengthError struct { 1194 *BaseError 1195 } 1196 1197 func NewInsertSelectFieldLengthError(query parser.SelectQuery, fieldLen int) error { 1198 selectClause := searchSelectClause(query) 1199 1200 return &InsertSelectFieldLengthError{ 1201 NewBaseError(selectClause, fmt.Sprintf(ErrMsgInsertSelectFieldLength, FormatCount(fieldLen, "field")), ReturnCodeApplicationError, ErrorInsertSelectFieldLength), 1202 } 1203 } 1204 1205 type UpdateFieldNotExistError struct { 1206 *BaseError 1207 } 1208 1209 func NewUpdateFieldNotExistError(field parser.QueryExpression) error { 1210 return &UpdateFieldNotExistError{ 1211 NewBaseError(field, fmt.Sprintf(ErrMsgUpdateFieldNotExist, field), ReturnCodeApplicationError, ErrorUpdateFieldNotExist), 1212 } 1213 } 1214 1215 type UpdateValueAmbiguousError struct { 1216 *BaseError 1217 } 1218 1219 func NewUpdateValueAmbiguousError(field parser.QueryExpression, value parser.QueryExpression) error { 1220 return &UpdateValueAmbiguousError{ 1221 NewBaseError(field, fmt.Sprintf(ErrMsgUpdateValueAmbiguous, value, field), ReturnCodeApplicationError, ErrorUpdateValueAmbiguous), 1222 } 1223 } 1224 1225 type ReplaceKeyNotSetError struct { 1226 *BaseError 1227 } 1228 1229 func NewReplaceKeyNotSetError(key parser.QueryExpression) error { 1230 return &ReplaceKeyNotSetError{ 1231 NewBaseError(key, fmt.Sprintf(ErrMsgReplaceKeyNotSet, key), ReturnCodeApplicationError, ErrorReplaceKeyNotSet), 1232 } 1233 } 1234 1235 type DeleteTableNotSpecifiedError struct { 1236 *BaseError 1237 } 1238 1239 func NewDeleteTableNotSpecifiedError(query parser.DeleteQuery) error { 1240 return &DeleteTableNotSpecifiedError{ 1241 NewBaseError(query, ErrMsgDeleteTableNotSpecified, ReturnCodeApplicationError, ErrorDeleteTableNotSpecified), 1242 } 1243 } 1244 1245 type ShowInvalidObjectTypeError struct { 1246 *BaseError 1247 } 1248 1249 func NewShowInvalidObjectTypeError(expr parser.Expression, objectType string) error { 1250 return &ShowInvalidObjectTypeError{ 1251 NewBaseError(expr, fmt.Sprintf(ErrMsgShowInvalidObjectType, objectType), ReturnCodeApplicationError, ErrorShowInvalidObjectType), 1252 } 1253 } 1254 1255 type ReplaceValueLengthError struct { 1256 *BaseError 1257 } 1258 1259 func NewReplaceValueLengthError(expr parser.Expression, message string) error { 1260 return &ReplaceValueLengthError{ 1261 NewBaseError(expr, fmt.Sprintf(ErrMsgReplaceValueLength, message), ReturnCodeApplicationError, ErrorReplaceValueLength), 1262 } 1263 } 1264 1265 type SourceInvalidFilePathError struct { 1266 *BaseError 1267 } 1268 1269 func NewSourceInvalidFilePathError(source parser.Source, arg parser.QueryExpression) error { 1270 return &SourceInvalidFilePathError{ 1271 NewBaseError(source, fmt.Sprintf(ErrMsgSourceInvalidFilePath, arg), ReturnCodeApplicationError, ErrorSourceInvalidFilePath), 1272 } 1273 } 1274 1275 type InvalidFlagNameError struct { 1276 *BaseError 1277 } 1278 1279 func NewInvalidFlagNameError(expr parser.Flag) error { 1280 return &InvalidFlagNameError{ 1281 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidFlagName, expr.String()), ReturnCodeApplicationError, ErrorInvalidFlagName), 1282 } 1283 } 1284 1285 type InvalidRuntimeInformationError struct { 1286 *BaseError 1287 } 1288 1289 func NewInvalidRuntimeInformationError(expr parser.RuntimeInformation) error { 1290 return &InvalidRuntimeInformationError{ 1291 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidRuntimeInformation, expr), ReturnCodeApplicationError, ErrorInvalidRuntimeInformation), 1292 } 1293 } 1294 1295 type FlagValueNotAllowedFormatError struct { 1296 *BaseError 1297 } 1298 1299 func NewFlagValueNotAllowedFormatError(setFlag parser.SetFlag) error { 1300 return &FlagValueNotAllowedFormatError{ 1301 NewBaseError(setFlag, fmt.Sprintf(ErrMsgFlagValueNowAllowedFormat, setFlag.Value, setFlag.Flag.String()), ReturnCodeApplicationError, ErrorFlagValueNowAllowedFormat), 1302 } 1303 } 1304 1305 type InvalidFlagValueError struct { 1306 *BaseError 1307 } 1308 1309 func NewInvalidFlagValueError(expr parser.SetFlag, message string) error { 1310 return &InvalidFlagValueError{ 1311 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidFlagValue, message), ReturnCodeApplicationError, ErrorInvalidFlagValue), 1312 } 1313 } 1314 1315 type AddFlagNotSupportedNameError struct { 1316 *BaseError 1317 } 1318 1319 func NewAddFlagNotSupportedNameError(expr parser.AddFlagElement) error { 1320 return &AddFlagNotSupportedNameError{ 1321 NewBaseError(expr, fmt.Sprintf(ErrMsgAddFlagNotSupportedName, expr.Flag.String()), ReturnCodeApplicationError, ErrorAddFlagNotSupportedName), 1322 } 1323 } 1324 1325 type RemoveFlagNotSupportedNameError struct { 1326 *BaseError 1327 } 1328 1329 func NewRemoveFlagNotSupportedNameError(expr parser.RemoveFlagElement) error { 1330 return &RemoveFlagNotSupportedNameError{ 1331 NewBaseError(expr, fmt.Sprintf(ErrMsgRemoveFlagNotSupportedName, expr.Flag.String()), ReturnCodeApplicationError, ErrorRemoveFlagNotSupportedName), 1332 } 1333 } 1334 1335 type InvalidFlagValueToBeRemoveError struct { 1336 *BaseError 1337 } 1338 1339 func NewInvalidFlagValueToBeRemovedError(unsetFlag parser.RemoveFlagElement) error { 1340 return &InvalidFlagValueToBeRemoveError{ 1341 NewBaseError(unsetFlag, fmt.Sprintf(ErrMsgInvalidFlagValueToBeRemoved, unsetFlag.Value, unsetFlag.Flag.String()), ReturnCodeApplicationError, ErrorInvalidFlagValueToBeRemoved), 1342 } 1343 } 1344 1345 type NotTableError struct { 1346 *BaseError 1347 } 1348 1349 func NewNotTableError(expr parser.QueryExpression) error { 1350 return &NotTableError{ 1351 NewBaseError(expr, ErrMsgNotTable, ReturnCodeApplicationError, ErrorNotTable), 1352 } 1353 } 1354 1355 type InvalidTableAttributeNameError struct { 1356 *BaseError 1357 } 1358 1359 func NewInvalidTableAttributeNameError(expr parser.Identifier) error { 1360 return &InvalidTableAttributeNameError{ 1361 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidTableAttributeName, expr), ReturnCodeApplicationError, ErrorInvalidTableAttributeName), 1362 } 1363 } 1364 1365 type TableAttributeValueNotAllowedFormatError struct { 1366 *BaseError 1367 } 1368 1369 func NewTableAttributeValueNotAllowedFormatError(expr parser.SetTableAttribute) error { 1370 return &TableAttributeValueNotAllowedFormatError{ 1371 NewBaseError(expr, fmt.Sprintf(ErrMsgTableAttributeValueNotAllowedFormat, expr.Value, expr.Attribute), ReturnCodeApplicationError, ErrorTableAttributeValueNotAllowedFormat), 1372 } 1373 } 1374 1375 type InvalidTableAttributeValueError struct { 1376 *BaseError 1377 } 1378 1379 func NewInvalidTableAttributeValueError(expr parser.SetTableAttribute, message string) error { 1380 return &InvalidTableAttributeValueError{ 1381 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidTableAttributeValue, message), ReturnCodeApplicationError, ErrorInvalidTableAttributeValue), 1382 } 1383 } 1384 1385 type InvalidEventNameError struct { 1386 *BaseError 1387 } 1388 1389 func NewInvalidEventNameError(expr parser.Identifier) error { 1390 return &InvalidEventNameError{ 1391 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidEventName, expr), ReturnCodeApplicationError, ErrorInvalidEventName), 1392 } 1393 } 1394 1395 type InternalRecordIdNotExistError struct { 1396 *BaseError 1397 } 1398 1399 func NewInternalRecordIdNotExistError() error { 1400 return &InternalRecordIdNotExistError{ 1401 NewBaseError(parser.NewNullValue(), ErrMsgInternalRecordIdNotExist, ReturnCodeApplicationError, ErrorInternalRecordIdNotExist), 1402 } 1403 } 1404 1405 type InternalRecordIdEmptyError struct { 1406 *BaseError 1407 } 1408 1409 func NewInternalRecordIdEmptyError() error { 1410 return &InternalRecordIdEmptyError{ 1411 NewBaseError(parser.NewNullValue(), ErrMsgInternalRecordIdEmpty, ReturnCodeApplicationError, ErrorInternalRecordIdEmpty), 1412 } 1413 } 1414 1415 type FieldLengthNotMatchError struct { 1416 *BaseError 1417 } 1418 1419 func NewFieldLengthNotMatchError(expr parser.QueryExpression) error { 1420 return &FieldLengthNotMatchError{ 1421 NewBaseError(expr, ErrMsgFieldLengthNotMatch, ReturnCodeApplicationError, ErrorFieldLengthNotMatch), 1422 } 1423 } 1424 1425 type RowValueLengthInListError struct { 1426 *BaseError 1427 Index int 1428 } 1429 1430 func NewRowValueLengthInListError(i int) error { 1431 return &RowValueLengthInListError{ 1432 BaseError: NewBaseError(parser.NewNullValue(), fmt.Sprintf(ErrMsgRowValueLengthInList, i), ReturnCodeApplicationError, ErrorRowValueLengthInList), 1433 Index: i, 1434 } 1435 } 1436 1437 type FormatStringLengthNotMatchError struct { 1438 *BaseError 1439 } 1440 1441 func NewFormatStringLengthNotMatchError() error { 1442 return &FormatStringLengthNotMatchError{ 1443 BaseError: NewBaseError(parser.NewNullValue(), ErrMsgFormatStringLengthNotMatch, ReturnCodeApplicationError, ErrorFormatStringLengthNotMatch), 1444 } 1445 } 1446 1447 type UnknownFormatPlaceholderError struct { 1448 *BaseError 1449 } 1450 1451 func NewUnknownFormatPlaceholderError(placeholder rune) error { 1452 return &UnknownFormatPlaceholderError{ 1453 BaseError: NewBaseError(parser.NewNullValue(), fmt.Sprintf(ErrMsgUnknownFormatPlaceholder, string(placeholder)), ReturnCodeApplicationError, ErrorUnknownFormatPlaceholder), 1454 } 1455 } 1456 1457 type FormatUnexpectedTerminationError struct { 1458 *BaseError 1459 } 1460 1461 func NewFormatUnexpectedTerminationError() error { 1462 return &FormatUnexpectedTerminationError{ 1463 BaseError: NewBaseError(parser.NewNullValue(), ErrMsgFormatUnexpectedTermination, ReturnCodeApplicationError, ErrorFormatUnexpectedTermination), 1464 } 1465 } 1466 1467 type ExternalCommandError struct { 1468 *BaseError 1469 } 1470 1471 func NewExternalCommandError(expr parser.Expression, message string) error { 1472 return &ExternalCommandError{ 1473 NewBaseError(expr, fmt.Sprintf(ErrMsgExternalCommand, message), ReturnCodeSystemError, ErrorExternalCommand), 1474 } 1475 } 1476 1477 type HttpRequestError struct { 1478 *BaseError 1479 } 1480 1481 func NewHttpRequestError(expr parser.Expression, url string, message string) error { 1482 return &HttpRequestError{ 1483 NewBaseError(expr, fmt.Sprintf(ErrMsgHttpRequest, url, message), ReturnCodeSystemError, ErrorHttpRequestError), 1484 } 1485 } 1486 1487 type InvalidReloadTypeError struct { 1488 *BaseError 1489 } 1490 1491 func NewInvalidReloadTypeError(expr parser.Reload, name string) error { 1492 return &InvalidReloadTypeError{ 1493 NewBaseError(expr, fmt.Sprintf(ErrMsgInvalidReloadType, name), ReturnCodeApplicationError, ErrorInvalidReloadType), 1494 } 1495 } 1496 1497 type LoadConfigurationError struct { 1498 *BaseError 1499 } 1500 1501 func NewLoadConfigurationError(expr parser.Expression, message string) error { 1502 return &LoadConfigurationError{ 1503 NewBaseError(expr, fmt.Sprintf(ErrMsgLoadConfiguration, message), ReturnCodeApplicationError, ErrorLoadConfiguration), 1504 } 1505 } 1506 1507 type DuplicateStatementNameError struct { 1508 *BaseError 1509 } 1510 1511 func NewDuplicateStatementNameError(name parser.Identifier) error { 1512 return &DuplicateStatementNameError{ 1513 NewBaseError(name, fmt.Sprintf(ErrMsgDuplicateStatementName, name.Literal), ReturnCodeApplicationError, ErrorDuplicateStatementName), 1514 } 1515 } 1516 1517 type StatementNotExistError struct { 1518 *BaseError 1519 } 1520 1521 func NewStatementNotExistError(name parser.Identifier) error { 1522 return &DuplicateStatementNameError{ 1523 NewBaseError(name, fmt.Sprintf(ErrMsgStatementNotExist, name.Literal), ReturnCodeApplicationError, ErrorStatementNotExist), 1524 } 1525 } 1526 1527 type StatementReplaceValueNotSpecifiedError struct { 1528 *BaseError 1529 } 1530 1531 func NewStatementReplaceValueNotSpecifiedError(placeholder parser.Placeholder) error { 1532 return &StatementReplaceValueNotSpecifiedError{ 1533 NewBaseError(placeholder, fmt.Sprintf(ErrMsgStatementReplaceValueNotSpecified, placeholder), ReturnCodeApplicationError, ErrorStatementReplaceValueNotSpecified), 1534 } 1535 } 1536 1537 type SelectIntoQueryFieldLengthNotMatchError struct { 1538 *BaseError 1539 } 1540 1541 func NewSelectIntoQueryFieldLengthNotMatchError(query parser.SelectQuery, fieldLen int) error { 1542 selectClause := searchSelectClause(query) 1543 1544 return &SelectIntoQueryFieldLengthNotMatchError{ 1545 NewBaseError(selectClause, fmt.Sprintf(ErrMsgSelectIntoQueryFieldLengthNotMatch, FormatCount(fieldLen, "field")), ReturnCodeApplicationError, ErrorSelectIntoQueryFieldLengthNotMatch), 1546 } 1547 } 1548 1549 type SelectIntoQueryTooManyRecordsError struct { 1550 *BaseError 1551 } 1552 1553 func NewSelectIntoQueryTooManyRecordsError(query parser.SelectQuery) error { 1554 selectClause := searchSelectClause(query) 1555 1556 return &SelectIntoQueryTooManyRecordsError{ 1557 NewBaseError(selectClause, ErrMsgSelectIntoQueryTooManyRecords, ReturnCodeApplicationError, ErrorSelectIntoQueryTooManyRecords), 1558 } 1559 } 1560 1561 type IntegerDevidedByZeroError struct { 1562 *BaseError 1563 } 1564 1565 func NewIntegerDevidedByZeroError(expr parser.Arithmetic) error { 1566 return &IntegerDevidedByZeroError{ 1567 NewBaseError(expr, ErrMsgIntegerDevidedByZero, ReturnCodeApplicationError, ErrorIntegerDevidedByZero), 1568 } 1569 } 1570 1571 func searchSelectClause(query parser.SelectQuery) parser.SelectClause { 1572 return searchSelectClauseInSelectEntity(query.SelectEntity) 1573 } 1574 1575 func searchSelectClauseInSelectEntity(selectEntity parser.QueryExpression) parser.SelectClause { 1576 if entity, ok := selectEntity.(parser.SelectEntity); ok { 1577 return entity.SelectClause.(parser.SelectClause) 1578 } 1579 return searchSelectClauseInSelectSetEntity(selectEntity.(parser.SelectSet).LHS) 1580 } 1581 1582 func searchSelectClauseInSelectSetEntity(selectSetEntity parser.QueryExpression) parser.SelectClause { 1583 if subquery, ok := selectSetEntity.(parser.Subquery); ok { 1584 return searchSelectClause(subquery.Query) 1585 } 1586 return searchSelectClauseInSelectEntity(selectSetEntity) 1587 } 1588 1589 func ConvertFileHandlerError(err error, ident parser.Identifier) error { 1590 switch err.(type) { 1591 case *file.TimeoutError: 1592 err = NewFileLockTimeoutError(ident) 1593 case *file.ContextCanceled: 1594 err = NewContextCanceled(err.Error()) 1595 case *file.ContextDone: 1596 err = NewContextDone(err.Error()) 1597 case *file.NotExistError: 1598 err = NewFileNotExistError(ident) 1599 case *file.AlreadyExistError: 1600 err = NewFileAlreadyExistError(ident) 1601 default: 1602 err = NewIOError(ident, err.Error()) 1603 } 1604 return err 1605 } 1606 1607 func ConvertLoadConfigurationError(err error) error { 1608 switch err.(type) { 1609 case *file.ContextDone: 1610 err = NewContextDone(err.Error()) 1611 default: 1612 err = NewLoadConfigurationError(nil, err.Error()) 1613 } 1614 return err 1615 } 1616 1617 func ConvertContextError(err error) error { 1618 if err == context.Canceled { 1619 return NewContextCanceled(err.Error()) 1620 } 1621 return NewContextDone(err.Error()) 1622 }