github.com/Rookout/GoSDK@v0.1.48/pkg/rookoutErrors/errors.go (about) 1 package rookoutErrors 2 3 import ( 4 "fmt" 5 "reflect" 6 "runtime" 7 8 "github.com/go-errors/errors" 9 ) 10 11 type RookoutError interface { 12 error 13 14 StackFrames() []errors.StackFrame 15 Stack() []byte 16 17 GetType() string 18 19 GetArguments() map[interface{}]interface{} 20 AddArgument(key string, value interface{}) 21 } 22 23 type RookoutErrorImpl struct { 24 ExternalError error 25 Type string `json:"Type"` 26 Arguments map[string]interface{} 27 } 28 29 func (r *RookoutErrorImpl) Error() string { 30 errorString := r.Type 31 32 if nil != r.ExternalError { 33 errorString += ": " + r.ExternalError.Error() 34 } 35 36 if len(r.Arguments) != 0 { 37 errorString = fmt.Sprintf(errorString+" | %v", r.Arguments) 38 } 39 40 if nil != r.ExternalError { 41 errorString += ": " + r.ExternalError.Error() 42 } 43 44 return errorString 45 } 46 47 func (r *RookoutErrorImpl) GetType() string { 48 return r.Type 49 } 50 51 func (r *RookoutErrorImpl) GetArguments() map[interface{}]interface{} { 52 outputMap := make(map[interface{}]interface{}) 53 for key, value := range r.Arguments { 54 outputMap[key] = value 55 } 56 return outputMap 57 } 58 59 func (r *RookoutErrorImpl) AddArgument(key string, value interface{}) { 60 r.Arguments[key] = value 61 } 62 63 func (r *RookoutErrorImpl) StackFrames() []errors.StackFrame { 64 switch e := r.ExternalError.(type) { 65 case *errors.Error: 66 return e.StackFrames() 67 case *RookoutErrorImpl: 68 return e.StackFrames() 69 default: 70 return errors.New(e).StackFrames() 71 } 72 } 73 74 func (r *RookoutErrorImpl) Stack() []byte { 75 switch e := r.ExternalError.(type) { 76 case *errors.Error: 77 return e.Stack() 78 case *RookoutErrorImpl: 79 return e.Stack() 80 default: 81 return errors.New(e).Stack() 82 } 83 } 84 85 func newRookoutError(errorType string, description string, externalError error, arguments map[string]interface{}) *RookoutErrorImpl { 86 if _, ok := externalError.(*errors.Error); !ok { 87 if externalError != nil { 88 externalError = errors.Wrap(externalError.Error(), 2) 89 } else { 90 externalError = errors.Wrap(description, 2) 91 } 92 } 93 94 return &RookoutErrorImpl{ 95 Type: errorType, 96 ExternalError: externalError, 97 Arguments: arguments, 98 } 99 } 100 101 func NewRookoutError(errorType string, description string, externalError error, arguments map[string]interface{}) RookoutError { 102 return newRookoutError(errorType, description, externalError, arguments) 103 } 104 105 func NewContextEnded(externalErr error) RookoutError { 106 return newRookoutError( 107 "ContextEnded", 108 "", 109 externalErr, 110 map[string]interface{}{}) 111 } 112 113 func NewRookMissingToken() RookoutError { 114 return newRookoutError("RookMissingToken", "No Rookout token was supplied. Make sure to pass the Rookout Token when starting the rook", nil, map[string]interface{}{}) 115 } 116 117 func NewRookInvalidOptions(desc string) RookoutError { 118 return newRookoutError("RookInvalidOptions", desc, nil, map[string]interface{}{}) 119 } 120 121 func NewRuntimeError(description string) RookoutError { 122 return newRookoutError("RuntimeError", description, nil, map[string]interface{}{}) 123 } 124 125 func NewObjectHasNoSizeException(obj interface{}) RookoutError { 126 return newRookoutError("ObjectHasNoSize", "Cannot get the size of object (probably isn't an array/list)", nil, map[string]interface{}{ 127 "obj": obj, 128 }) 129 } 130 131 func NewRookMethodNotFound(name string) RookoutError { 132 return newRookoutError("RookMethodNotFound", name, nil, map[string]interface{}{}) 133 } 134 135 func NewNotImplemented() RookoutError { 136 return newRookoutError("NotImplementedException", "", nil, map[string]interface{}{}) 137 } 138 139 func NewAgentKeyNotFoundException(name string, key interface{}, externalErr error) RookoutError { 140 return newRookoutError( 141 "RookKeyNotFoundException", 142 "Failed to get key", 143 externalErr, 144 map[string]interface{}{ 145 "name": name, 146 "key": key, 147 }) 148 } 149 150 func NewInvalidInterfaceVariable(key interface{}) RookoutError { 151 return newRookoutError( 152 "InvalidInterfaceVariable", 153 "Tried extracting inner variable from interface but got another interface", 154 nil, 155 map[string]interface{}{ 156 "key": key, 157 }) 158 } 159 160 func NewRookAttributeNotFoundException(name string) RookoutError { 161 return newRookoutError( 162 "RookAttributeNotFound", 163 "Failed to get attribute", 164 nil, 165 map[string]interface{}{ 166 "attribute": name, 167 }) 168 } 169 170 func NewRookInvalidArithmeticPathException(configuration interface{}, 171 externalError error) RookoutError { 172 return newRookoutError( 173 "RookInvalidArithmeticPath", 174 "Invalid arithmetic path configuration", 175 externalError, 176 map[string]interface{}{ 177 "configuration": configuration, 178 }) 179 } 180 181 func NewArithmeticPathException(externalError error) RookoutError { 182 return newRookoutError( 183 "ArithmeticPathException", 184 "Invalid arithmetic path procedure", 185 externalError, 186 map[string]interface{}{}) 187 } 188 189 func NewRookOperationReadOnlyException(operationType string) RookoutError { 190 return newRookoutError( 191 "RookOperationReadOnly", 192 "Operation does not support write", 193 nil, 194 map[string]interface{}{ 195 "operation": operationType, 196 }) 197 } 198 199 func NewJsonMarshallingException(jsonData interface{}, externalError error) RookoutError { 200 return newRookoutError( 201 "JsonMarshallingException", 202 "", 203 externalError, 204 map[string]interface{}{ 205 "jsonData": jsonData, 206 }) 207 } 208 209 func NewNilProtobufNamespaceException() RookoutError { 210 return newRookoutError( 211 "NilProtobufNamespaceException", 212 "", 213 nil, 214 map[string]interface{}{}) 215 } 216 217 func NewRookAugInvalidKey(key string, aug interface{}) RookoutError { 218 return newRookoutError( 219 "RookAugInvalidKey", 220 "Failed to get key from configuration", 221 nil, 222 map[string]interface{}{ 223 "key": key, 224 "configuration": aug, 225 }) 226 } 227 228 func NewBadTypeException(description string, obj interface{}) RookoutError { 229 return newRookoutError( 230 "BadTypeException", 231 description, 232 nil, 233 map[string]interface{}{ 234 "obj": obj, 235 }) 236 } 237 238 func NewBadFunctionNameException(functionName string) RookoutError { 239 return newRookoutError( 240 "BadFunctionNameException", 241 "", 242 nil, 243 map[string]interface{}{ 244 "functionName": functionName, 245 }) 246 } 247 248 func NewInvalidProcMapsStartAddress(line string, startAddress string, externalErr error) RookoutError { 249 return newRookoutError( 250 "InvalidProcMapsStartEndAddress", 251 "Expected start address in proc maps line to be uint", 252 externalErr, 253 map[string]interface{}{ 254 "line": line, 255 "startAddress": startAddress, 256 }, 257 ) 258 } 259 260 func NewInvalidProcMapsEndAddress(line string, endAddress string, externalErr error) RookoutError { 261 return newRookoutError( 262 "InvalidProcMapsEndAddress", 263 "Expected end address in proc maps line to be uint", 264 externalErr, 265 map[string]interface{}{ 266 "line": line, 267 "endAddress": endAddress, 268 }, 269 ) 270 } 271 272 func NewInvalidProcMapsAddresses(line string, addresses string) RookoutError { 273 return newRookoutError( 274 "InvalidProcMapsAddresses", 275 "Expected startAddress-endAddress in proc maps line", 276 nil, 277 map[string]interface{}{ 278 "line": line, 279 "addresses": addresses, 280 }, 281 ) 282 } 283 284 func NewInvalidProcMapsLine(line string) RookoutError { 285 return newRookoutError( 286 "InvalidProcMapsLine", 287 "Expected at least 5 fields in proc maps line", 288 nil, 289 map[string]interface{}{ 290 "line": line, 291 }, 292 ) 293 } 294 295 func NewFailedToOpenProcMapsFile(externalErr error) RookoutError { 296 return newRookoutError( 297 "FailedToOpenProcMapsFile", 298 "Unable to open /proc/self/maps", 299 externalErr, 300 map[string]interface{}{}, 301 ) 302 } 303 304 func NewFailedToWriteBytes(errno int) *RookoutErrorImpl { 305 return newRookoutError( 306 "FailedToWriteBytes", 307 "Failed to write hook bytes", 308 nil, 309 map[string]interface{}{ 310 "errno": errno, 311 }, 312 ) 313 } 314 315 func NewFailedToCollectGoroutinesInfo(numGoroutines int) RookoutError { 316 return newRookoutError( 317 "FailedToCollectGoroutinesInfo", 318 "Failed to collect all goroutines info", 319 nil, 320 map[string]interface{}{ 321 "numGoroutines": numGoroutines, 322 }, 323 ) 324 } 325 326 func NewUnsafeToInstallHook(reason string) RookoutError { 327 return newRookoutError( 328 "UnsafeToInstallHook", 329 "Detected it's unsafe to install hook at this time", 330 nil, 331 map[string]interface{}{ 332 "reason": reason, 333 }, 334 ) 335 } 336 337 func NewFailedToGetStateEntryAddr(functionEntry uint64, functionEnd uint64, stateID int, externalErr error) RookoutError { 338 return newRookoutError( 339 "FailedToGetStateEntryAddr", 340 "Unable to get state entry addr", 341 externalErr, 342 map[string]interface{}{ 343 "functionEntry": functionEntry, 344 "functionEnd": functionEnd, 345 "stateID": stateID, 346 }) 347 } 348 349 func NewInvalidBranchDest(src uintptr, dst uintptr) RookoutError { 350 return newRookoutError( 351 "InvalidBranchDest", 352 "Tried to encode an invalid branch instruction - relative distance isn't dividable by 4", 353 nil, 354 map[string]interface{}{ 355 "src": src, 356 "dst": dst, 357 }) 358 } 359 360 func NewBranchDestTooFar(src uintptr, dst uintptr) RookoutError { 361 return newRookoutError( 362 "BranchDestTooFar", 363 "Tried to encode an invalid branch instruction - relative distance is too long to be encoded into 26 bit immediate", 364 nil, 365 map[string]interface{}{ 366 "src": src, 367 "dst": dst, 368 }) 369 } 370 371 func NewFailedToGetHookAddress(errorMsg string) RookoutError { 372 return newRookoutError( 373 "FailedToGetHookAddress", 374 "Failed to get hook address from native", 375 nil, 376 map[string]interface{}{ 377 "errorMsg": errorMsg, 378 }) 379 } 380 381 func NewFailedToRetrieveStackTrace() RookoutError { 382 return newRookoutError( 383 "FailedToRetrieveStackTrace", 384 "", 385 nil, 386 map[string]interface{}{}) 387 } 388 389 func NewFailedToRetrieveFrameLocals(externalErr error) RookoutError { 390 return newRookoutError( 391 "FailedToRetrieveFrameLocals", 392 "", 393 externalErr, 394 map[string]interface{}{}) 395 } 396 397 func NewFailedToInitNative(nativeError string) RookoutError { 398 return newRookoutError( 399 "FailedToInitNative", 400 "", 401 nil, 402 map[string]interface{}{ 403 "nativeError": nativeError, 404 }) 405 } 406 407 func NewFailedToDestroyNative(nativeError error) RookoutError { 408 return newRookoutError( 409 "FailedToDestroyNative", 410 "", 411 nil, 412 map[string]interface{}{ 413 "nativeError": nativeError, 414 }) 415 } 416 417 func NewBadVariantType(description string, variant interface{}) RookoutError { 418 return newRookoutError( 419 "BadVariantType", 420 description, 421 nil, 422 map[string]interface{}{"variant": variant}) 423 } 424 425 func NewFailedToCreateID(err error) RookoutError { 426 return newRookoutError( 427 "RookFailedToCreateID", 428 "", 429 err, 430 map[string]interface{}{}) 431 } 432 433 func NewInvalidTokenError() RookoutError { 434 return newRookoutError( 435 "InvalidTokenError", 436 "The Rookout token supplied is not valid; please check the token and try again", 437 nil, 438 map[string]interface{}{}) 439 } 440 441 func NewWebSocketError() RookoutError { 442 return newRookoutError( 443 "WebSocketError", 444 "Received HTTP status 400 from the controller, please make sure WebSocket is enabled on the load balancer.", 445 nil, 446 map[string]interface{}{}) 447 } 448 449 func NewInvalidLabelError(label string) RookoutError { 450 return newRookoutError( 451 "InvalidLabelError", 452 "Invalid label: must not start with the '$' character", 453 nil, 454 map[string]interface{}{"label": label}) 455 } 456 457 func NewRookRuntimeVersionNotSupported(currentVersion string) RookoutError { 458 return newRookoutError( 459 "RookRuntimeVersionNotSupported", 460 "This runtime version is not supported by Rookout.", 461 nil, 462 map[string]interface{}{"currentVersion": currentVersion}) 463 } 464 465 func NewRookObjectNameMissing(configuration interface{}) RookoutError { 466 return newRookoutError( 467 "RookObjectNameMissing", 468 "Failed to find object name", 469 nil, 470 map[string]interface{}{ 471 "configuration": configuration, 472 }) 473 } 474 475 func NewRookUnsupportedLocation(name string) RookoutError { 476 return newRookoutError( 477 "RookUnsupportedLocation", 478 "Unsupported aug location was specified", 479 nil, 480 map[string]interface{}{ 481 "location": name, 482 }, 483 ) 484 } 485 486 func NewRookInvalidActionConfiguration(configuration interface{}) RookoutError { 487 return newRookoutError( 488 "RookInvalidActionConfiguration", 489 "Failed to parse action configuration", 490 nil, 491 map[string]interface{}{ 492 "configuration": configuration, 493 }) 494 } 495 496 func NewRookInvalidOperationConfiguration(configuration interface{}) RookoutError { 497 return newRookoutError( 498 "RookInvalidOperationConfiguration", 499 "Failed to parse operation configuration", 500 nil, 501 map[string]interface{}{ 502 "configuration": configuration, 503 }) 504 } 505 506 func NewRookConnectToControllerTimeout() RookoutError { 507 return newRookoutError( 508 "RookConnectToControllerTimeout", 509 "Failed to connect to the controller - will continue attempting in the background", 510 nil, 511 map[string]interface{}{}) 512 } 513 514 func NewUnknownError(recovered interface{}) RookoutError { 515 err, _ := recovered.(error) 516 517 return newRookoutError( 518 "Unknown", 519 "Unexpected error", 520 err, 521 map[string]interface{}{ 522 "recovered": recovered, 523 }) 524 } 525 526 func NewRookRuleAugRateLimited() RookoutError { 527 return newRookoutError( 528 "RookRuleAugRateLimited", 529 "Breakpoint was disabled due to rate-limiting. \nFor more information: https://docs.rookout.com/docs/breakpoints-tasks.html#rate-limiting", 530 nil, 531 map[string]interface{}{}) 532 } 533 534 func NewRookRuleGlobalRateLimited() RookoutError { 535 return newRookoutError( 536 "RookRuleGlobalRateLimited", 537 "Breakpoint was disabled due to global rate-limiting. \nFor more information: https://docs.rookout.com/docs/breakpoints-tasks.html#rate-limiting", 538 nil, 539 map[string]interface{}{}) 540 } 541 542 var UsingGlobalRateLimiter = false 543 544 func NewRookRuleRateLimited() RookoutError { 545 if UsingGlobalRateLimiter { 546 return NewRookRuleGlobalRateLimited() 547 } 548 return NewRookRuleAugRateLimited() 549 } 550 551 func NewRookInvalidRateLimitConfiguration(config string) RookoutError { 552 return newRookoutError( 553 "RookInvalidRateLimitConfiguration", 554 fmt.Sprintf("Got an invalid value for the rate limit. (got %s) expected XX/YY or XX\\YY, where XX < YY", config), 555 nil, 556 map[string]interface{}{ 557 "config": config, 558 }) 559 } 560 561 func NewRookRuleMaxExecutionTimeReached() RookoutError { 562 return newRookoutError( 563 "RookRuleMaxExecutionTimeReached", 564 "Breakpoint was disabled because it has reached its maximum execution time", 565 nil, 566 map[string]interface{}{}) 567 } 568 569 func NewRookInvalidMethodArguments(method, arguments string) RookoutError { 570 return newRookoutError( 571 "RookInvalidMethodArguments", 572 "Bad method arguments", 573 nil, 574 map[string]interface{}{ 575 "method": method, 576 "arguments": arguments, 577 }) 578 } 579 580 func NewFileNotFound(filename string) RookoutError { 581 return newRookoutError( 582 "FileNotFound", 583 fmt.Sprintf("No such file found %s", filename), 584 nil, 585 map[string]interface{}{ 586 "filename": filename, 587 }) 588 } 589 590 func NewLineNotFound(filename string, lineno int) RookoutError { 591 return newRookoutError( 592 "RookLineNotFound", 593 fmt.Sprintf("Can't break on line %d in file %s", lineno, filename), 594 nil, 595 map[string]interface{}{ 596 "filename": filename, 597 "lineno": lineno, 598 }) 599 } 600 601 func NewMultipleFilesFound(filename string) RookoutError { 602 return newRookoutError( 603 "MultipleFilesFound", 604 fmt.Sprintf("Found multiple files matching %s, use more specific file path", filename), 605 nil, 606 map[string]interface{}{ 607 "filename": filename, 608 }) 609 } 610 611 func NewFailedToAddBreakpoint(filename string, lineno int, err error) RookoutError { 612 return newRookoutError( 613 "FailedToAddBreakpoint", 614 "Unable to add a breakpoint at the given address", 615 err, 616 map[string]interface{}{ 617 "filename": filename, 618 "lineno": lineno, 619 }) 620 } 621 622 func NewAllTrampolineAddressesInUse() RookoutError { 623 return newRookoutError( 624 "AllTrampolineAddressesInUse", 625 "Can't add another breakpoint since all trampolines are in use", 626 nil, 627 map[string]interface{}{}) 628 } 629 630 func NewFailedToRemoveBreakpoint(filename string, lineno int, err error) RookoutError { 631 return newRookoutError( 632 "FailedToRemoveBreakpoint", 633 "Unable to remove the breakpoint at the given address", 634 err, 635 map[string]interface{}{ 636 "filename": filename, 637 "lineno": lineno, 638 }) 639 } 640 641 func NewFailedToEraseAllBreakpointInstances() RookoutError { 642 return newRookoutError( 643 "FailedToEraseAllBreakpointInstances", 644 "Could not remove at least one breakpoint instance", 645 nil, 646 map[string]interface{}{}) 647 } 648 649 func NewFailedToGetExecutable(err error) RookoutError { 650 return newRookoutError( 651 "FailedToGetExecutable", 652 "", 653 err, 654 map[string]interface{}{}) 655 } 656 657 func NewFailedToLoadBinaryInfo(err error) RookoutError { 658 return newRookoutError( 659 "FailedToLoadBinaryInfo", 660 "", 661 err, 662 map[string]interface{}{}) 663 } 664 665 func NewFailedToPatchModule(filename string, lineno int, err error) RookoutError { 666 return newRookoutError( 667 "NewFailedToPatchModule", 668 "", 669 err, 670 map[string]interface{}{ 671 "filename": filename, 672 "lineno": lineno, 673 }) 674 } 675 676 func NewFailedToApplyBreakpointState(filename string, lineno int, err error) RookoutError { 677 return newRookoutError( 678 "NewFailedToApplyBreakpointState", 679 "", 680 err, 681 map[string]interface{}{ 682 "filename": filename, 683 "lineno": lineno, 684 }) 685 } 686 func NewFailedToGetVariableLocators(filename string, lineno int, err error) RookoutError { 687 return newRookoutError( 688 "NewFailedToGetVariableLocators", 689 "", 690 err, 691 map[string]interface{}{ 692 "filename": filename, 693 "lineno": lineno, 694 }) 695 } 696 697 func NewFailedToGetUnpatchedAddressMapping(filename string, lineno int, err error) RookoutError { 698 return newRookoutError( 699 "FailedToGetUnpatchedAddressMapping", 700 "", 701 err, 702 map[string]interface{}{ 703 "filename": filename, 704 "lineno": lineno, 705 }) 706 } 707 708 func NewFailedToGetAddressMapping(filename string, lineno int, err error) RookoutError { 709 return newRookoutError( 710 "FailedToGetAddressMapping", 711 "", 712 err, 713 map[string]interface{}{ 714 "filename": filename, 715 "lineno": lineno, 716 }) 717 } 718 719 func NewFailedToStartCopyingFunction(err error) RookoutError { 720 return newRookoutError( 721 "FailedToStartCopyingFunction", 722 "Unable to start copying original function", 723 err, 724 map[string]interface{}{}) 725 } 726 727 func NewCompiledWithoutCGO() RookoutError { 728 return newRookoutError("CompiledWithoutCGO", "Your project was built with CGO_ENABLED disabled", nil, map[string]interface{}{}) 729 } 730 731 func NewFailedToGetDWARFTree(err error) RookoutError { 732 return newRookoutError( 733 "FailedToGetDWARFTree", 734 "Unable to load DWARF tree", 735 err, 736 map[string]interface{}{}) 737 } 738 739 func NewFlushTimedOut() RookoutError { 740 return newRookoutError("FlushTimedOut", "Timed out during flush", nil, map[string]interface{}{}) 741 } 742 743 func NewRookOutputQueueFull() RookoutError { 744 return newRookoutError("RookOutputQueueFull", 745 "Breakpoint triggered but output queue is full. Data collection will be disabled until the queue has emptied.", 746 nil, 747 map[string]interface{}{}) 748 } 749 750 func NewInvalidDwarfRegister(dwarfReg uint64) RookoutError { 751 return newRookoutError("InvalidDwarfRegister", 752 "Tracked invalid dwarf register while locating variable", 753 nil, 754 map[string]interface{}{ 755 "dwarfReg": dwarfReg, 756 }) 757 } 758 759 func NewFailedToLocate(variableName string, externalErr error) RookoutError { 760 return newRookoutError("FailedToLocate", 761 "Failed to locate variable", 762 externalErr, 763 map[string]interface{}{ 764 "variableName": variableName, 765 }) 766 } 767 768 func NewFailedToAlignFunc(funcAddress, pclntableAddress, funcOffset uintptr) RookoutError { 769 return newRookoutError( 770 "FailedToAlignFunc", 771 "Tried to align _func in moduledata pclntable but failed", 772 nil, 773 map[string]interface{}{ 774 "funcAddress": funcAddress, 775 "pclntableAddress": pclntableAddress, 776 "funcOffset": funcOffset, 777 }, 778 ) 779 } 780 781 func NewRookMessageSizeExceeded(messageSize int, maxMessageSize int) RookoutError { 782 return newRookoutError("RookMessageSizeExceeded", 783 fmt.Sprintf("Message size of %d exceeds max size limit of %d. "+ 784 "Change the depth of collection or change the default by setting ROOKOUT_MAX_MESSAGE_SIZE as environment variable or system property", messageSize, maxMessageSize), 785 nil, 786 map[string]interface{}{ 787 "messageSize": messageSize, 788 "maxMessageSize": maxMessageSize, 789 }) 790 } 791 792 func NewUnwrappedFuncNotFound(funcName string) RookoutError { 793 return newRookoutError( 794 "UnwrappedFuncNotFound", 795 "Could not find unwrapped address of go assembly function", 796 nil, 797 map[string]interface{}{ 798 "funcName": funcName, 799 }) 800 } 801 802 func NewUnsupportedPlatform() RookoutError { 803 var desc string 804 if runtime.GOOS == "windows" { 805 desc = "Your project was built for an unsupported platform - Windows" 806 } else if runtime.GOARCH != "amd64" { 807 desc = "Your project was built for an unsupported platform architecture - " + runtime.GOARCH + "-" + runtime.GOOS 808 } else { 809 desc = "You're building without CGO enabled, which is not supported" 810 } 811 return newRookoutError( 812 "UnsupportedPlatform", 813 desc, 814 nil, 815 map[string]interface{}{}) 816 } 817 818 func NewFailedToExecuteBreakpoint(failedCount uint64) RookoutError { 819 return newRookoutError( 820 "FailedToExecuteBreakpoint", 821 fmt.Sprintf("%d breakpoint executions failed because registers backup buffer was full", failedCount), 822 nil, 823 map[string]interface{}{ 824 "failedCount": failedCount, 825 }, 826 ) 827 } 828 829 func NewReadBuildFlagsError() RookoutError { 830 return newRookoutError( 831 "ReadBuildFlagsError", 832 "Couldn't read the build flags. Verify the application was built with go build", 833 nil, 834 map[string]interface{}{}) 835 } 836 837 func NewValidateBuildFlagsError(err error) RookoutError { 838 return newRookoutError( 839 "ValidateBuildFlagsError", 840 "The application wasn't built with -gcflags all=-dwarflocationlists=true or it was built with either -ldflags -s or -w", 841 err, 842 map[string]interface{}{}) 843 } 844 845 func NewMprotectFailed(address uintptr, size int, permissions int, err string) RookoutError { 846 return newRookoutError( 847 "MprotectFailed", 848 "Tried to change permissions of memory area but failed", 849 nil, 850 map[string]interface{}{ 851 "address": address, 852 "size": size, 853 "permissions": permissions, 854 "err": err, 855 }) 856 } 857 858 func NewFailedToGetCurrentMemoryProtection(address uint64, size uint64) RookoutError { 859 return newRookoutError( 860 "FailedToGetCurrentMemoryProtection", 861 "Failed to get current memory protection", 862 nil, 863 map[string]interface{}{ 864 "address": address, 865 "size": size, 866 }) 867 } 868 869 func NewDifferentNPCData(origNPCData uint32, newNPCData uint32) RookoutError { 870 return newRookoutError( 871 "DifferenceNPCData", 872 "New module doesn't have the same number of PCData tables as original module", 873 nil, 874 map[string]interface{}{ 875 "origNPCData": origNPCData, 876 "newNPCData": newNPCData, 877 }) 878 } 879 880 func NewPCDataVerificationFailed(table uint32, origValue int32, origPC uintptr, newValue int32, newPC uintptr) RookoutError { 881 return newRookoutError( 882 "PCDataVerificationFailed", 883 "New module has a different value in pcdata table than the original module", 884 nil, 885 map[string]interface{}{ 886 "table": table, 887 "origValue": origValue, 888 "origPC": origPC, 889 "newValue": newValue, 890 "newPC": newPC, 891 }) 892 } 893 894 func NewPCDataAsyncUnsafePointVerificationFailed(newValue int32, newPC uintptr) RookoutError { 895 return newRookoutError( 896 "PCDataAsyncUnsafePointVerificationFailed", 897 "New module has a different value than the unsafe point for PCs within the patched code", 898 nil, 899 map[string]interface{}{ 900 "newValue": newValue, 901 "newPC": newPC, 902 }) 903 } 904 905 func NewPCSPInPatchedVerificationFailed(origValue int32, origPC uintptr, expectedNewValue, newValue int32, newPC uintptr) RookoutError { 906 return newRookoutError( 907 "PCSPInPatchedVerificationFailed", 908 "New module has a different value in pcsp table than the expected generated values", 909 nil, 910 map[string]interface{}{ 911 "origValue": origValue, 912 "origPC": origPC, 913 "expectedNewValue": expectedNewValue, 914 "newValue": newValue, 915 "newPC": newPC, 916 }) 917 } 918 919 func NewPCSPVerificationFailed(origValue int32, origPC uintptr, newValue int32, newPC uintptr) RookoutError { 920 return newRookoutError( 921 "PCSPVerificationFailed", 922 "New module has a different value in pcsp table than the original module", 923 nil, 924 map[string]interface{}{ 925 "origValue": origValue, 926 "origPC": origPC, 927 "newValue": newValue, 928 "newPC": newPC, 929 }) 930 } 931 932 func NewPCSPVerificationFailedMissingEntry(origValue int32, origPC uintptr, newPC uintptr) RookoutError { 933 return newRookoutError( 934 "PCSPVerificationFailedMissingEntry", 935 "New module has doesn't have a PCSP entry for a PC within the patched code", 936 nil, 937 map[string]interface{}{ 938 "origValue": origValue, 939 "origPC": origPC, 940 "newPC": newPC, 941 }) 942 } 943 944 func NewPCFileVerificationFailed(origFile string, origPC uintptr, newFile string, newPC uintptr) RookoutError { 945 return newRookoutError( 946 "PCFileVerificationFailed", 947 "New module has a different value in pcfile table than the original module", 948 nil, 949 map[string]interface{}{ 950 "origFile": origFile, 951 "origPC": origPC, 952 "newFile": newFile, 953 "newPC": newPC, 954 }) 955 } 956 957 func NewPCLineVerificationFailed(origLine int32, origPC uintptr, newLine int32, newPC uintptr) RookoutError { 958 return newRookoutError( 959 "PCLineVerificationFailed", 960 "New module has a different value in pcline table than the original module", 961 nil, 962 map[string]interface{}{ 963 "origLine": origLine, 964 "origPC": origPC, 965 "newLine": newLine, 966 "newPC": newPC, 967 }) 968 } 969 970 func NewDifferentNFuncData(origNFuncData uint8, newNFuncData uint8) RookoutError { 971 return newRookoutError( 972 "DifferenceNFuncData", 973 "New module doesn't have the same number of funcdata tables as original module", 974 nil, 975 map[string]interface{}{ 976 "origNFuncData": origNFuncData, 977 "newNFuncData": newNFuncData, 978 }) 979 } 980 981 func NewFuncDataVerificationFailed(table int, origValue uintptr, newValue uintptr) RookoutError { 982 return newRookoutError( 983 "FuncDataVerificationFailed", 984 "New module has a different pointer to funcdata than the original module", 985 nil, 986 map[string]interface{}{ 987 "table": table, 988 "origValue": origValue, 989 "newValue": newValue, 990 }) 991 } 992 993 func NewModuleVerificationFailed(recovered interface{}) RookoutError { 994 return newRookoutError( 995 "ModuleVerificationFailed", 996 "Panic occured while trying to verify new moduledata", 997 nil, 998 map[string]interface{}{ 999 "recovered": recovered, 1000 }) 1001 } 1002 1003 func NewIllegalAddressMappings() RookoutError { 1004 return newRookoutError( 1005 "BadAddressMapping", 1006 "Function address mapping must not contain patched code in the last two mappings", 1007 nil, 1008 nil) 1009 } 1010 1011 func NewVariableCreationFailed(recovered interface{}) RookoutError { 1012 return newRookoutError( 1013 "VariableCreationFailed", 1014 "Panic occured while trying to create new variable", 1015 nil, 1016 map[string]interface{}{ 1017 "recovered": recovered, 1018 }) 1019 } 1020 1021 func NewVariableLoadFailed(recovered interface{}) RookoutError { 1022 return newRookoutError( 1023 "VariableLoadFailed", 1024 "Panic occured while trying to load variable", 1025 nil, 1026 map[string]interface{}{ 1027 "recovered": recovered, 1028 }) 1029 } 1030 1031 func NewArgIsNotRel(inst interface{}) RookoutError { 1032 return newRookoutError( 1033 "ArgIsNotRel", 1034 "Unable to calculate absolute dest because first arg is not Rel", 1035 nil, 1036 map[string]interface{}{ 1037 "inst": inst, 1038 }) 1039 } 1040 1041 func NewInvalidJumpDest(jumpDest string) RookoutError { 1042 return newRookoutError( 1043 "InvalidJumpDest", 1044 "Created a jump with a nonexistant dest", 1045 nil, 1046 map[string]interface{}{ 1047 "jumpDest": jumpDest, 1048 }) 1049 } 1050 1051 func NewFailedToAssemble(recovered interface{}) RookoutError { 1052 return newRookoutError( 1053 "FailedToAssemble", 1054 "Failed to assemble instructions", 1055 nil, 1056 map[string]interface{}{ 1057 "recovered": recovered, 1058 }) 1059 } 1060 1061 func NewFailedToDecode(funcAsm []byte, err error) RookoutError { 1062 return newRookoutError( 1063 "FailedToDecode", 1064 "Failed to decode one instruction", 1065 err, 1066 map[string]interface{}{ 1067 "inst": fmt.Sprintf("%x", funcAsm), 1068 }) 1069 } 1070 1071 func NewUnexpectedInstructionOp(inst interface{}) RookoutError { 1072 return newRookoutError( 1073 "UnexpectedInstructionOp", 1074 "Unable to calculate dest PC of instruction that isn't CALL or JMP", 1075 nil, 1076 map[string]interface{}{ 1077 "inst": inst, 1078 }) 1079 } 1080 1081 func NewKeyNotInMap(mapName string, key string) RookoutError { 1082 return newRookoutError( 1083 "KeyNotInMap", 1084 "Given key does not exist in map", 1085 nil, 1086 map[string]interface{}{ 1087 "mapName": mapName, 1088 "key": key, 1089 }) 1090 } 1091 1092 func NewNoSuchMember(structName string, memberName string) RookoutError { 1093 return newRookoutError( 1094 "NoSuchChild", 1095 "Struct doesn't have member with given name", 1096 nil, 1097 map[string]interface{}{ 1098 "structName": structName, 1099 "memberName": memberName, 1100 }) 1101 } 1102 1103 func NewVariableIsNotMap(name string, kind reflect.Kind) RookoutError { 1104 return newRookoutError( 1105 "VariableIsNotMap", 1106 "Tried to get map value of variable that is not of kind map", 1107 nil, 1108 map[string]interface{}{ 1109 "name": name, 1110 "kind": kind, 1111 }) 1112 } 1113 1114 func NewVariableIsNotStruct(name string, kind reflect.Kind) RookoutError { 1115 return newRookoutError( 1116 "VariableIsNotStruct", 1117 "Tried to get struct value of variable that is not of kind struct", 1118 nil, 1119 map[string]interface{}{ 1120 "name": name, 1121 "kind": kind, 1122 }) 1123 } 1124 1125 func NewVariableIsNotArray(name string, kind reflect.Kind) RookoutError { 1126 return newRookoutError( 1127 "VariableIsNotArray", 1128 "Tried to get array item of variable that is not of kind array", 1129 nil, 1130 map[string]interface{}{ 1131 "name": name, 1132 "kind": kind, 1133 }) 1134 } 1135 1136 func NewLabelAlreadyExists(label string) RookoutError { 1137 return newRookoutError( 1138 "LabelAlreadyExists", 1139 "Unable to add label to assembly: the label already exists", 1140 nil, 1141 map[string]interface{}{ 1142 "label": label, 1143 }) 1144 } 1145 1146 func NewInvalidBytes(bytes []byte) RookoutError { 1147 return newRookoutError( 1148 "InvalidBytes", 1149 "Cannot insert bytes: length of bytes is not a multiple of 4", 1150 nil, 1151 map[string]interface{}{ 1152 "bytes": bytes, 1153 }) 1154 } 1155 1156 func NewUnexpectedInstruction(movGToR12 interface{}, ret interface{}) RookoutError { 1157 return newRookoutError( 1158 "UnexpectedInstruction", 1159 "Unexpected instructions in assembled getg", 1160 nil, 1161 map[string]interface{}{ 1162 "movGToR12": movGToR12, 1163 "ret": ret, 1164 }) 1165 }