test_culprit.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. from sentry.event_manager import EventManager
  2. from sentry.event_manager import get_culprit as get_culprit_impl
  3. def get_culprit(data):
  4. mgr = EventManager(data)
  5. mgr.normalize()
  6. return get_culprit_impl(mgr.get_data())
  7. def test_cocoa_culprit():
  8. culprit = get_culprit(
  9. {
  10. "platform": "cocoa",
  11. "exception": {
  12. "type": "Crash",
  13. "stacktrace": {
  14. "frames": [
  15. {
  16. "filename": "foo/baz.c",
  17. "package": "/foo/bar/baz.dylib",
  18. "lineno": 1,
  19. "in_app": True,
  20. "function": "-[CRLCrashAsyncSafeThread crash]",
  21. }
  22. ]
  23. },
  24. },
  25. }
  26. )
  27. assert culprit == "-[CRLCrashAsyncSafeThread crash]"
  28. def test_emoji_culprit():
  29. culprit = get_culprit(
  30. {
  31. "platform": "native",
  32. "exception": {
  33. "type": "Crash",
  34. "stacktrace": {
  35. "frames": [
  36. {
  37. "filename": "foo/baz.c",
  38. "package": "/foo/bar/baz.dylib",
  39. "module": "\U0001f62d",
  40. "lineno": 1,
  41. "in_app": True,
  42. "function": "\U0001f60d",
  43. }
  44. ]
  45. },
  46. },
  47. }
  48. )
  49. assert culprit == "\U0001f60d"
  50. def test_cocoa_strict_stacktrace():
  51. culprit = get_culprit(
  52. {
  53. "platform": "native",
  54. "exception": {
  55. "type": "Crash",
  56. "stacktrace": {
  57. "frames": [
  58. {
  59. "filename": "foo/baz.c",
  60. "package": "/foo/bar/libswiftCore.dylib",
  61. "lineno": 1,
  62. "in_app": False,
  63. "function": "fooBar",
  64. },
  65. {"package": "/foo/bar/MyApp", "in_app": True, "function": "fooBar2"},
  66. {
  67. "filename": "Mycontroller.swift",
  68. "package": "/foo/bar/MyApp",
  69. "in_app": True,
  70. "function": "-[CRLCrashAsyncSafeThread crash]",
  71. },
  72. ]
  73. },
  74. },
  75. }
  76. )
  77. assert culprit == "-[CRLCrashAsyncSafeThread crash]"
  78. def test_culprit_for_synthetic_event():
  79. # Synthetic events do not generate a culprit
  80. culprit = get_culprit(
  81. {
  82. "platform": "javascript",
  83. "exception": {
  84. "type": "Error",
  85. "value": "I threw up stringly",
  86. "mechanism": {"type": "string-error", "synthetic": True},
  87. "stacktrace": {
  88. "frames": [
  89. {
  90. "filename": "foo/baz.js",
  91. "package": "node_modules/blah/foo/bar.js",
  92. "lineno": 42,
  93. "in_app": True,
  94. "function": "fooBar",
  95. }
  96. ]
  97. },
  98. },
  99. }
  100. )
  101. assert culprit == ""
  102. def test_culprit_for_javascript_event():
  103. culprit = get_culprit(
  104. {
  105. "platform": "javascript",
  106. "exception": {
  107. "type": "Error",
  108. "value": "I fail hard",
  109. "stacktrace": {
  110. "frames": [
  111. {
  112. "filename": "foo/baz.js",
  113. "package": "node_modules/blah/foo/bar.js",
  114. "lineno": 42,
  115. "in_app": True,
  116. "function": "fooBar",
  117. }
  118. ]
  119. },
  120. },
  121. }
  122. )
  123. assert culprit == "fooBar(foo/baz.js)"
  124. def test_culprit_for_python_event():
  125. culprit = get_culprit(
  126. {
  127. "platform": "python",
  128. "exception": {
  129. "type": "ZeroDivisionError",
  130. "value": "integer division or modulo by zero",
  131. "stacktrace": {
  132. "frames": [
  133. {
  134. "filename": "foo/baz.py",
  135. "module": "foo.baz",
  136. "package": "foo/baz.py",
  137. "lineno": 23,
  138. "in_app": True,
  139. "function": "it_failed",
  140. }
  141. ]
  142. },
  143. },
  144. }
  145. )
  146. assert culprit == "foo.baz in it_failed"