test_plugin.py 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103
  1. import os.path
  2. import zipfile
  3. from base64 import b64encode
  4. from io import BytesIO
  5. from unittest.mock import patch
  6. from uuid import uuid4
  7. import responses
  8. from django.utils.encoding import force_bytes
  9. from sentry.models import (
  10. ArtifactBundle,
  11. DebugIdArtifactBundle,
  12. File,
  13. Release,
  14. ReleaseFile,
  15. SourceFileType,
  16. )
  17. from sentry.models.releasefile import update_artifact_index
  18. from sentry.testutils import RelayStoreHelper, SnubaTestCase, TransactionTestCase
  19. from sentry.testutils.helpers.datetime import before_now, iso_format
  20. from sentry.utils import json
  21. BASE64_SOURCEMAP = "data:application/json;base64," + (
  22. b64encode(
  23. b'{"version":3,"file":"generated.js","sources":["/test.js"],"names":[],"mappings":"AAAA","sourcesContent":['
  24. b'"console.log(\\"hello, World!\\")"]}'
  25. )
  26. .decode("utf-8")
  27. .replace("\n", "")
  28. )
  29. INVALID_BASE64_SOURCEMAP = "data:application/json;base64,A"
  30. def get_fixture_path(name):
  31. return os.path.join(os.path.dirname(__file__), "fixtures", name)
  32. def load_fixture(name):
  33. with open(get_fixture_path(name), "rb") as fp:
  34. return fp.read()
  35. class JavascriptIntegrationTest(RelayStoreHelper, SnubaTestCase, TransactionTestCase):
  36. def setUp(self):
  37. super().setUp()
  38. self.min_ago = iso_format(before_now(minutes=1))
  39. def test_adds_contexts_without_device(self):
  40. data = {
  41. "timestamp": self.min_ago,
  42. "message": "hello",
  43. "platform": "javascript",
  44. "request": {
  45. "url": "http://example.com",
  46. "headers": [
  47. [
  48. "User-Agent",
  49. "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
  50. "Chrome/28.0.1500.72 Safari/537.36",
  51. ]
  52. ],
  53. },
  54. }
  55. event = self.post_and_retrieve_event(data)
  56. contexts = event.interfaces["contexts"].to_json()
  57. assert contexts.get("os") == {"name": "Windows", "version": "8", "type": "os"}
  58. assert contexts.get("device") is None
  59. def test_adds_contexts_with_device(self):
  60. data = {
  61. "timestamp": self.min_ago,
  62. "message": "hello",
  63. "platform": "javascript",
  64. "request": {
  65. "url": "http://example.com",
  66. "headers": [
  67. [
  68. "User-Agent",
  69. "Mozilla/5.0 (Linux; U; Android 4.3; en-us; SCH-R530U Build/JSS15J) AppleWebKit/534.30 ("
  70. "KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 USCC-R530U",
  71. ]
  72. ],
  73. },
  74. }
  75. event = self.post_and_retrieve_event(data)
  76. contexts = event.interfaces["contexts"].to_json()
  77. assert contexts.get("os") == {"name": "Android", "type": "os", "version": "4.3"}
  78. assert contexts.get("browser") == {"name": "Android", "type": "browser", "version": "4.3"}
  79. assert contexts.get("device") == {
  80. "family": "Samsung SCH-R530U",
  81. "type": "device",
  82. "model": "SCH-R530U",
  83. "brand": "Samsung",
  84. }
  85. def test_adds_contexts_with_ps4_device(self):
  86. data = {
  87. "timestamp": self.min_ago,
  88. "message": "hello",
  89. "platform": "javascript",
  90. "request": {
  91. "url": "http://example.com",
  92. "headers": [
  93. [
  94. "User-Agent",
  95. "Mozilla/5.0 (PlayStation 4 3.55) AppleWebKit/537.78 (KHTML, like Gecko)",
  96. ]
  97. ],
  98. },
  99. }
  100. event = self.post_and_retrieve_event(data)
  101. contexts = event.interfaces["contexts"].to_json()
  102. assert contexts.get("os") is None
  103. assert contexts.get("browser") is None
  104. assert contexts.get("device") == {
  105. "family": "PlayStation 4",
  106. "type": "device",
  107. "model": "PlayStation 4",
  108. "brand": "Sony",
  109. }
  110. @patch("sentry.lang.javascript.processor.Fetcher.fetch_by_url")
  111. def test_source_expansion(self, mock_fetch_by_url):
  112. data = {
  113. "timestamp": self.min_ago,
  114. "message": "hello",
  115. "platform": "javascript",
  116. "exception": {
  117. "values": [
  118. {
  119. "type": "Error",
  120. "stacktrace": {
  121. "frames": [
  122. {
  123. "abs_path": "http://example.com/foo.js",
  124. "filename": "foo.js",
  125. "lineno": 4,
  126. "colno": 0,
  127. },
  128. {
  129. "abs_path": "http://example.com/foo.js",
  130. "filename": "foo.js",
  131. "lineno": 1,
  132. "colno": 0,
  133. },
  134. ]
  135. },
  136. }
  137. ]
  138. },
  139. }
  140. mock_fetch_by_url.return_value.body = force_bytes("\n".join("hello world"))
  141. mock_fetch_by_url.return_value.encoding = None
  142. mock_fetch_by_url.return_value.headers = {}
  143. event = self.post_and_retrieve_event(data)
  144. mock_fetch_by_url.assert_called_once_with("http://example.com/foo.js")
  145. exception = event.interfaces["exception"]
  146. frame_list = exception.values[0].stacktrace.frames
  147. frame = frame_list[0]
  148. assert frame.pre_context == ["h", "e", "l"]
  149. assert frame.context_line == "l"
  150. assert frame.post_context == ["o", " ", "w", "o", "r"]
  151. frame = frame_list[1]
  152. assert not frame.pre_context
  153. assert frame.context_line == "h"
  154. assert frame.post_context == ["e", "l", "l", "o", " "]
  155. # no source map means no raw_stacktrace
  156. assert exception.values[0].raw_stacktrace is None
  157. @patch("sentry.lang.javascript.processor.Fetcher.fetch_by_url")
  158. @patch("sentry.lang.javascript.processor.discover_sourcemap")
  159. def test_inlined_sources(self, mock_discover_sourcemap, mock_fetch_by_url):
  160. data = {
  161. "timestamp": self.min_ago,
  162. "message": "hello",
  163. "platform": "javascript",
  164. "exception": {
  165. "values": [
  166. {
  167. "type": "Error",
  168. "stacktrace": {
  169. "frames": [
  170. {
  171. "abs_path": "http://example.com/test.min.js",
  172. "filename": "test.js",
  173. "lineno": 1,
  174. "colno": 1,
  175. }
  176. ]
  177. },
  178. }
  179. ]
  180. },
  181. }
  182. mock_discover_sourcemap.return_value = BASE64_SOURCEMAP
  183. mock_fetch_by_url.return_value.url = "http://example.com/test.min.js"
  184. mock_fetch_by_url.return_value.body = force_bytes("\n".join("<generated source>"))
  185. mock_fetch_by_url.return_value.encoding = None
  186. event = self.post_and_retrieve_event(data)
  187. mock_fetch_by_url.assert_called_once_with("http://example.com/test.min.js")
  188. exception = event.interfaces["exception"]
  189. frame_list = exception.values[0].stacktrace.frames
  190. frame = frame_list[0]
  191. assert not frame.pre_context
  192. assert frame.context_line == 'console.log("hello, World!")'
  193. assert not frame.post_context
  194. assert frame.data["sourcemap"] == "http://example.com/test.min.js"
  195. @patch("sentry.lang.javascript.processor.Fetcher.fetch_by_url")
  196. @patch("sentry.lang.javascript.processor.discover_sourcemap")
  197. def test_invalid_base64_sourcemap_returns_an_error(
  198. self, mock_discover_sourcemap, mock_fetch_by_url
  199. ):
  200. data = {
  201. "timestamp": self.min_ago,
  202. "message": "hello",
  203. "platform": "javascript",
  204. "exception": {
  205. "values": [
  206. {
  207. "type": "Error",
  208. "stacktrace": {
  209. "frames": [
  210. {
  211. "abs_path": "http://example.com/test.min.js",
  212. "filename": "test.js",
  213. "lineno": 1,
  214. "colno": 1,
  215. },
  216. ]
  217. },
  218. }
  219. ]
  220. },
  221. }
  222. mock_discover_sourcemap.return_value = INVALID_BASE64_SOURCEMAP
  223. mock_fetch_by_url.return_value.url = "http://example.com/test.min.js"
  224. mock_fetch_by_url.return_value.body = force_bytes("\n".join("<generated source>"))
  225. mock_fetch_by_url.return_value.encoding = None
  226. event = self.post_and_retrieve_event(data)
  227. mock_fetch_by_url.assert_called_once_with("http://example.com/test.min.js")
  228. assert len(event.data["errors"]) == 1
  229. assert event.data["errors"][0] == {
  230. "url": "<base64>",
  231. "reason": "Invalid base64-encoded string: "
  232. "number of data characters (1) cannot be 1 more than a multiple of 4",
  233. "type": "js_invalid_source",
  234. }
  235. @patch("sentry.lang.javascript.processor.SmCache.from_bytes")
  236. @patch("sentry.lang.javascript.processor.Fetcher.fetch_by_url")
  237. @patch("sentry.lang.javascript.processor.discover_sourcemap")
  238. def test_sourcemap_cache_is_constructed_only_once_if_an_error_is_raised(
  239. self, mock_discover_sourcemap, mock_fetch_by_url, mock_from_bytes
  240. ):
  241. data = {
  242. "timestamp": self.min_ago,
  243. "message": "hello",
  244. "platform": "javascript",
  245. "exception": {
  246. "values": [
  247. {
  248. "type": "Error",
  249. "stacktrace": {
  250. "frames": [
  251. {
  252. "abs_path": "http://example.com/test.min.js",
  253. "filename": "test.js",
  254. "lineno": 1,
  255. "colno": 1,
  256. },
  257. {
  258. "abs_path": "http://example.com/test.min.js",
  259. "filename": "test.js",
  260. "lineno": 1,
  261. "colno": 1,
  262. },
  263. {
  264. "abs_path": "http://example.com/test.min.js",
  265. "filename": "test.js",
  266. "lineno": 1,
  267. "colno": 1,
  268. },
  269. ]
  270. },
  271. }
  272. ]
  273. },
  274. }
  275. mock_discover_sourcemap.return_value = BASE64_SOURCEMAP
  276. mock_fetch_by_url.return_value.url = "http://example.com/test.min.js"
  277. mock_fetch_by_url.return_value.body = force_bytes("\n".join("<generated source>"))
  278. mock_fetch_by_url.return_value.encoding = None
  279. mock_from_bytes.side_effect = Exception()
  280. self.post_and_retrieve_event(data)
  281. mock_fetch_by_url.assert_called_once_with("http://example.com/test.min.js")
  282. mock_from_bytes.assert_called_once()
  283. @responses.activate
  284. def test_error_message_translations(self):
  285. data = {
  286. "timestamp": self.min_ago,
  287. "message": "hello",
  288. "platform": "javascript",
  289. "logentry": {
  290. "formatted": "ReferenceError: Impossible de d\xe9finir une propri\xe9t\xe9 \xab foo \xbb : objet non "
  291. "extensible"
  292. },
  293. "exception": {
  294. "values": [
  295. {"type": "Error", "value": "P\u0159\xedli\u0161 mnoho soubor\u016f"},
  296. {
  297. "type": "Error",
  298. "value": "foo: wyst\u0105pi\u0142 nieoczekiwany b\u0142\u0105d podczas pr\xf3by uzyskania "
  299. "informacji o metadanych",
  300. },
  301. ]
  302. },
  303. }
  304. event = self.post_and_retrieve_event(data)
  305. message = event.interfaces["logentry"]
  306. assert (
  307. message.formatted
  308. == "ReferenceError: Cannot define property 'foo': object is not extensible"
  309. )
  310. exception = event.interfaces["exception"]
  311. assert exception.values[0].value == "Too many files"
  312. assert (
  313. exception.values[1].value
  314. == "foo: an unexpected failure occurred while trying to obtain metadata information"
  315. )
  316. @responses.activate
  317. def test_sourcemap_source_expansion(self):
  318. responses.add(
  319. responses.GET,
  320. "http://example.com/file.min.js",
  321. body=load_fixture("file.min.js"),
  322. content_type="application/javascript; charset=utf-8",
  323. )
  324. responses.add(
  325. responses.GET,
  326. "http://example.com/file1.js",
  327. body=load_fixture("file1.js"),
  328. content_type="application/javascript; charset=utf-8",
  329. )
  330. responses.add(
  331. responses.GET,
  332. "http://example.com/file2.js",
  333. body=load_fixture("file2.js"),
  334. content_type="application/javascript; charset=utf-8",
  335. )
  336. responses.add(
  337. responses.GET,
  338. "http://example.com/file.sourcemap.js",
  339. body=load_fixture("file.sourcemap.js"),
  340. content_type="application/javascript; charset=utf-8",
  341. )
  342. responses.add(responses.GET, "http://example.com/index.html", body="Not Found", status=404)
  343. data = {
  344. "timestamp": self.min_ago,
  345. "message": "hello",
  346. "platform": "javascript",
  347. "exception": {
  348. "values": [
  349. {
  350. "type": "Error",
  351. "stacktrace": {
  352. "frames": [
  353. {
  354. "abs_path": "http://example.com/file.min.js",
  355. "filename": "file.min.js",
  356. "lineno": 1,
  357. "colno": 39,
  358. },
  359. # NOTE: Intentionally source is not retrieved from this HTML file
  360. {
  361. "function": 'function: "HTMLDocument.<anonymous>"',
  362. "abs_path": "http//example.com/index.html",
  363. "filename": "index.html",
  364. "lineno": 283,
  365. "colno": 17,
  366. "in_app": False,
  367. },
  368. ]
  369. },
  370. }
  371. ]
  372. },
  373. }
  374. event = self.post_and_retrieve_event(data)
  375. assert event.data["errors"] == [
  376. {"type": "js_no_source", "url": "http//example.com/index.html"}
  377. ]
  378. exception = event.interfaces["exception"]
  379. frame_list = exception.values[0].stacktrace.frames
  380. frame = frame_list[0]
  381. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  382. expected = "\treturn a + b; // fôo"
  383. assert frame.context_line == expected
  384. assert frame.post_context == ["}", ""]
  385. raw_frame_list = exception.values[0].raw_stacktrace.frames
  386. raw_frame = raw_frame_list[0]
  387. assert not raw_frame.pre_context
  388. assert (
  389. raw_frame.context_line
  390. == 'function add(a,b){"use strict";return a+b}function multiply(a,b){"use strict";return a*b}function '
  391. 'divide(a,b){"use strict";try{return multip {snip}'
  392. )
  393. assert raw_frame.post_context == ["//@ sourceMappingURL=file.sourcemap.js", ""]
  394. assert raw_frame.lineno == 1
  395. # Since we couldn't expand source for the 2nd frame, both
  396. # its raw and original form should be identical
  397. assert raw_frame_list[1] == frame_list[1]
  398. @responses.activate
  399. def test_sourcemap_embedded_source_expansion(self):
  400. responses.add(
  401. responses.GET,
  402. "http://example.com/embedded.js",
  403. body=load_fixture("embedded.js"),
  404. content_type="application/javascript; charset=utf-8",
  405. )
  406. responses.add(
  407. responses.GET,
  408. "http://example.com/embedded.js.map",
  409. body=load_fixture("embedded.js.map"),
  410. content_type="application/json; charset=utf-8",
  411. )
  412. responses.add(responses.GET, "http://example.com/index.html", body="Not Found", status=404)
  413. data = {
  414. "timestamp": self.min_ago,
  415. "message": "hello",
  416. "platform": "javascript",
  417. "exception": {
  418. "values": [
  419. {
  420. "type": "Error",
  421. "stacktrace": {
  422. "frames": [
  423. {
  424. "abs_path": "http://example.com/embedded.js",
  425. "filename": "file.min.js",
  426. "lineno": 1,
  427. "colno": 39,
  428. },
  429. # NOTE: Intentionally source is not retrieved from this HTML file
  430. {
  431. "function": 'function: "HTMLDocument.<anonymous>"',
  432. "abs_path": "http//example.com/index.html",
  433. "filename": "index.html",
  434. "lineno": 283,
  435. "colno": 17,
  436. "in_app": False,
  437. },
  438. ]
  439. },
  440. }
  441. ]
  442. },
  443. }
  444. event = self.post_and_retrieve_event(data)
  445. assert event.data["errors"] == [
  446. {"type": "js_no_source", "url": "http//example.com/index.html"}
  447. ]
  448. exception = event.interfaces["exception"]
  449. frame_list = exception.values[0].stacktrace.frames
  450. frame = frame_list[0]
  451. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  452. expected = "\treturn a + b; // fôo"
  453. assert frame.context_line == expected
  454. assert frame.post_context == ["}", ""]
  455. @responses.activate
  456. def test_sourcemap_nofiles_source_expansion(self):
  457. project = self.project
  458. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  459. release.add_project(project)
  460. with open(get_fixture_path("nofiles.js"), "rb") as f:
  461. f_minified = File.objects.create(
  462. name="nofiles.js", type="release.file", headers={"Content-Type": "application/json"}
  463. )
  464. f_minified.putfile(f)
  465. ReleaseFile.objects.create(
  466. name=f"~/{f_minified.name}",
  467. release_id=release.id,
  468. organization_id=project.organization_id,
  469. file=f_minified,
  470. )
  471. with open(get_fixture_path("nofiles.js.map"), "rb") as f:
  472. f_sourcemap = File.objects.create(
  473. name="nofiles.js.map",
  474. type="release.file",
  475. headers={"Content-Type": "application/json"},
  476. )
  477. f_sourcemap.putfile(f)
  478. ReleaseFile.objects.create(
  479. name=f"app:///{f_sourcemap.name}",
  480. release_id=release.id,
  481. organization_id=project.organization_id,
  482. file=f_sourcemap,
  483. )
  484. data = {
  485. "timestamp": self.min_ago,
  486. "message": "hello",
  487. "platform": "javascript",
  488. "release": "abc",
  489. "exception": {
  490. "values": [
  491. {
  492. "type": "Error",
  493. "stacktrace": {
  494. "frames": [{"abs_path": "app:///nofiles.js", "lineno": 1, "colno": 39}]
  495. },
  496. }
  497. ]
  498. },
  499. }
  500. event = self.post_and_retrieve_event(data)
  501. assert "errors" not in event.data
  502. exception = event.interfaces["exception"]
  503. frame_list = exception.values[0].stacktrace.frames
  504. assert len(frame_list) == 1
  505. frame = frame_list[0]
  506. assert frame.abs_path == "app:///nofiles.js"
  507. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  508. assert frame.context_line == "\treturn a + b; // fôo"
  509. assert frame.post_context == ["}", ""]
  510. @responses.activate
  511. def test_indexed_sourcemap_source_expansion(self):
  512. responses.add(
  513. responses.GET,
  514. "http://example.com/indexed.min.js",
  515. body=load_fixture("indexed.min.js"),
  516. content_type="application/javascript; charset=utf-8",
  517. )
  518. responses.add(
  519. responses.GET,
  520. "http://example.com/file1.js",
  521. body=load_fixture("file1.js"),
  522. content_type="application/javascript; charset=utf-8",
  523. )
  524. responses.add(
  525. responses.GET,
  526. "http://example.com/file2.js",
  527. body=load_fixture("file2.js"),
  528. content_type="application/javascript; charset=utf-8",
  529. )
  530. responses.add(
  531. responses.GET,
  532. "http://example.com/indexed.sourcemap.js",
  533. body=load_fixture("indexed.sourcemap.js"),
  534. content_type="application/json; charset=utf-8",
  535. )
  536. data = {
  537. "timestamp": self.min_ago,
  538. "message": "hello",
  539. "platform": "javascript",
  540. "exception": {
  541. "values": [
  542. {
  543. "type": "Error",
  544. "stacktrace": {
  545. "frames": [
  546. {
  547. "abs_path": "http://example.com/indexed.min.js",
  548. "filename": "indexed.min.js",
  549. "lineno": 1,
  550. "colno": 39,
  551. },
  552. {
  553. "abs_path": "http://example.com/indexed.min.js",
  554. "filename": "indexed.min.js",
  555. "lineno": 2,
  556. "colno": 44,
  557. },
  558. ]
  559. },
  560. }
  561. ]
  562. },
  563. }
  564. event = self.post_and_retrieve_event(data)
  565. assert "errors" not in event.data
  566. exception = event.interfaces["exception"]
  567. frame_list = exception.values[0].stacktrace.frames
  568. frame = frame_list[0]
  569. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  570. expected = "\treturn a + b; // fôo"
  571. assert frame.context_line == expected
  572. assert frame.post_context == ["}", ""]
  573. raw_frame_list = exception.values[0].raw_stacktrace.frames
  574. raw_frame = raw_frame_list[0]
  575. assert not raw_frame.pre_context
  576. assert raw_frame.context_line == 'function add(a,b){"use strict";return a+b}'
  577. assert raw_frame.post_context == [
  578. 'function multiply(a,b){"use strict";return a*b}function divide(a,b){"use strict";try{return multiply('
  579. "add(a,b),a,b)/c}catch(e){Raven.captureE {snip}",
  580. "//# sourceMappingURL=indexed.sourcemap.js",
  581. "",
  582. ]
  583. assert raw_frame.lineno == 1
  584. frame = frame_list[1]
  585. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  586. assert frame.context_line == "\treturn a * b;"
  587. assert frame.post_context == [
  588. "}",
  589. "function divide(a, b) {",
  590. '\t"use strict";',
  591. "\ttry {",
  592. "\t\treturn multiply(add(a, b), a, b) / c;",
  593. ]
  594. raw_frame = raw_frame_list[1]
  595. assert raw_frame.pre_context == ['function add(a,b){"use strict";return a+b}']
  596. assert (
  597. raw_frame.context_line
  598. == 'function multiply(a,b){"use strict";return a*b}function divide(a,b){"use strict";try{return multiply('
  599. "add(a,b),a,b)/c}catch(e){Raven.captureE {snip}"
  600. )
  601. assert raw_frame.post_context == ["//# sourceMappingURL=indexed.sourcemap.js", ""]
  602. assert raw_frame.lineno == 2
  603. @responses.activate
  604. def test_expansion_via_debug(self):
  605. project = self.project
  606. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  607. release.add_project(project)
  608. # file.min.js
  609. # ------------
  610. with open(get_fixture_path("file.min.js"), "rb") as f:
  611. f_minified = File.objects.create(
  612. name="file.min.js",
  613. type="release.file",
  614. headers={"Content-Type": "application/json"},
  615. )
  616. f_minified.putfile(f)
  617. # Intentionally omit hostname - use alternate artifact path lookup instead
  618. # /file1.js vs http://example.com/file1.js
  619. ReleaseFile.objects.create(
  620. name=f"~/{f_minified.name}?foo=bar",
  621. release_id=release.id,
  622. organization_id=project.organization_id,
  623. file=f_minified,
  624. )
  625. # file1.js
  626. # ---------
  627. with open(get_fixture_path("file1.js"), "rb") as f:
  628. f1 = File.objects.create(
  629. name="file1.js", type="release.file", headers={"Content-Type": "application/json"}
  630. )
  631. f1.putfile(f)
  632. ReleaseFile.objects.create(
  633. name=f"http://example.com/{f1.name}",
  634. release_id=release.id,
  635. organization_id=project.organization_id,
  636. file=f1,
  637. )
  638. # file2.js
  639. # ----------
  640. with open(get_fixture_path("file2.js"), "rb") as f:
  641. f2 = File.objects.create(
  642. name="file2.js", type="release.file", headers={"Content-Type": "application/json"}
  643. )
  644. f2.putfile(f)
  645. ReleaseFile.objects.create(
  646. name=f"http://example.com/{f2.name}",
  647. release_id=release.id,
  648. organization_id=project.organization_id,
  649. file=f2,
  650. )
  651. # To verify that the full url has priority over the relative url,
  652. # we will also add a second ReleaseFile alias for file2.js (f3) w/o
  653. # hostname that points to an empty file. If the processor chooses
  654. # this empty file over the correct file2.js, it will not locate
  655. # context for the 2nd frame.
  656. with open(get_fixture_path("empty.js"), "rb") as f:
  657. f2_empty = File.objects.create(
  658. name="empty.js", type="release.file", headers={"Content-Type": "application/json"}
  659. )
  660. f2_empty.putfile(f)
  661. ReleaseFile.objects.create(
  662. name=f"~/{f2.name}", # intentionally using f2.name ("file2.js")
  663. release_id=release.id,
  664. organization_id=project.organization_id,
  665. file=f2_empty,
  666. )
  667. # sourcemap
  668. # ----------
  669. with open(get_fixture_path("file.sourcemap.js"), "rb") as f:
  670. f_sourcemap = File.objects.create(
  671. name="file.sourcemap.js",
  672. type="release.file",
  673. headers={"Content-Type": "application/json"},
  674. )
  675. f_sourcemap.putfile(f)
  676. ReleaseFile.objects.create(
  677. name=f"http://example.com/{f_sourcemap.name}",
  678. release_id=release.id,
  679. organization_id=project.organization_id,
  680. file=f_sourcemap,
  681. )
  682. data = {
  683. "timestamp": self.min_ago,
  684. "message": "hello",
  685. "platform": "javascript",
  686. "release": "abc",
  687. "exception": {
  688. "values": [
  689. {
  690. "type": "Error",
  691. "stacktrace": {
  692. "frames": [
  693. {
  694. "abs_path": "http://example.com/file.min.js?foo=bar",
  695. "filename": "file.min.js",
  696. "lineno": 1,
  697. "colno": 39,
  698. },
  699. {
  700. "abs_path": "http://example.com/file.min.js?foo=bar",
  701. "filename": "file.min.js",
  702. "lineno": 1,
  703. "colno": 79,
  704. },
  705. ]
  706. },
  707. }
  708. ]
  709. },
  710. }
  711. event = self.post_and_retrieve_event(data)
  712. assert "errors" not in event.data
  713. exception = event.interfaces["exception"]
  714. frame_list = exception.values[0].stacktrace.frames
  715. frame = frame_list[0]
  716. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  717. assert frame.context_line == "\treturn a + b; // fôo"
  718. assert frame.post_context == ["}", ""]
  719. frame = frame_list[1]
  720. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  721. assert frame.context_line == "\treturn a * b;"
  722. assert frame.post_context == [
  723. "}",
  724. "function divide(a, b) {",
  725. '\t"use strict";',
  726. "\ttry {",
  727. "\t\treturn multiply(add(a, b), a, b) / c;",
  728. ]
  729. @responses.activate
  730. def test_expansion_via_distribution_release_artifacts(self):
  731. project = self.project
  732. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  733. release.add_project(project)
  734. dist = release.add_dist("foo")
  735. # file.min.js
  736. # ------------
  737. with open(get_fixture_path("file.min.js"), "rb") as f:
  738. f_minified = File.objects.create(
  739. name="file.min.js",
  740. type="release.file",
  741. headers={"Content-Type": "application/json"},
  742. )
  743. f_minified.putfile(f)
  744. # Intentionally omit hostname - use alternate artifact path lookup instead
  745. # /file1.js vs http://example.com/file1.js
  746. ReleaseFile.objects.create(
  747. name=f"~/{f_minified.name}?foo=bar",
  748. release_id=release.id,
  749. dist_id=dist.id,
  750. organization_id=project.organization_id,
  751. file=f_minified,
  752. )
  753. # file1.js
  754. # ---------
  755. with open(get_fixture_path("file1.js"), "rb") as f:
  756. f1 = File.objects.create(
  757. name="file1.js", type="release.file", headers={"Content-Type": "application/json"}
  758. )
  759. f1.putfile(f)
  760. ReleaseFile.objects.create(
  761. name=f"http://example.com/{f1.name}",
  762. release_id=release.id,
  763. dist_id=dist.id,
  764. organization_id=project.organization_id,
  765. file=f1,
  766. )
  767. # file2.js
  768. # ----------
  769. with open(get_fixture_path("file2.js"), "rb") as f:
  770. f2 = File.objects.create(
  771. name="file2.js", type="release.file", headers={"Content-Type": "application/json"}
  772. )
  773. f2.putfile(f)
  774. ReleaseFile.objects.create(
  775. name=f"http://example.com/{f2.name}",
  776. release_id=release.id,
  777. dist_id=dist.id,
  778. organization_id=project.organization_id,
  779. file=f2,
  780. )
  781. # To verify that the full url has priority over the relative url,
  782. # we will also add a second ReleaseFile alias for file2.js (f3) w/o
  783. # hostname that points to an empty file. If the processor chooses
  784. # this empty file over the correct file2.js, it will not locate
  785. # context for the 2nd frame.
  786. with open(get_fixture_path("empty.js"), "rb") as f:
  787. f2_empty = File.objects.create(
  788. name="empty.js", type="release.file", headers={"Content-Type": "application/json"}
  789. )
  790. f2_empty.putfile(f)
  791. ReleaseFile.objects.create(
  792. name=f"~/{f2.name}", # intentionally using f2.name ("file2.js")
  793. release_id=release.id,
  794. dist_id=dist.id,
  795. organization_id=project.organization_id,
  796. file=f2_empty,
  797. )
  798. # sourcemap
  799. # ----------
  800. with open(get_fixture_path("file.sourcemap.js"), "rb") as f:
  801. f_sourcemap = File.objects.create(
  802. name="file.sourcemap.js",
  803. type="release.file",
  804. headers={"Content-Type": "application/json"},
  805. )
  806. f_sourcemap.putfile(f)
  807. ReleaseFile.objects.create(
  808. name=f"http://example.com/{f_sourcemap.name}",
  809. release_id=release.id,
  810. dist_id=dist.id,
  811. organization_id=project.organization_id,
  812. file=f_sourcemap,
  813. )
  814. data = {
  815. "timestamp": self.min_ago,
  816. "message": "hello",
  817. "platform": "javascript",
  818. "release": "abc",
  819. "dist": "foo",
  820. "exception": {
  821. "values": [
  822. {
  823. "type": "Error",
  824. "stacktrace": {
  825. "frames": [
  826. {
  827. "abs_path": "http://example.com/file.min.js?foo=bar",
  828. "filename": "file.min.js",
  829. "lineno": 1,
  830. "colno": 39,
  831. },
  832. {
  833. "abs_path": "http://example.com/file.min.js?foo=bar",
  834. "filename": "file.min.js",
  835. "lineno": 1,
  836. "colno": 79,
  837. },
  838. ]
  839. },
  840. }
  841. ]
  842. },
  843. }
  844. event = self.post_and_retrieve_event(data)
  845. assert "errors" not in event.data
  846. exception = event.interfaces["exception"]
  847. frame_list = exception.values[0].stacktrace.frames
  848. frame = frame_list[0]
  849. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  850. assert frame.context_line == "\treturn a + b; // fôo"
  851. assert frame.post_context == ["}", ""]
  852. frame = frame_list[1]
  853. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  854. assert frame.context_line == "\treturn a * b;"
  855. assert frame.post_context == [
  856. "}",
  857. "function divide(a, b) {",
  858. '\t"use strict";',
  859. "\ttry {",
  860. "\t\treturn multiply(add(a, b), a, b) / c;",
  861. ]
  862. @responses.activate
  863. def test_sourcemap_expansion_with_missing_source(self):
  864. """
  865. Tests a successful sourcemap expansion that points to source files
  866. that are not found.
  867. """
  868. responses.add(
  869. responses.GET,
  870. "http://example.com/file.min.js",
  871. body=load_fixture("file.min.js"),
  872. content_type="application/javascript; charset=utf-8",
  873. )
  874. responses.add(
  875. responses.GET,
  876. "http://example.com/file.sourcemap.js",
  877. body=load_fixture("file.sourcemap.js"),
  878. content_type="application/json; charset=utf-8",
  879. )
  880. responses.add(responses.GET, "http://example.com/file1.js", body="Not Found", status=404)
  881. data = {
  882. "timestamp": self.min_ago,
  883. "message": "hello",
  884. "platform": "javascript",
  885. "exception": {
  886. "values": [
  887. {
  888. "type": "Error",
  889. "stacktrace": {
  890. # Add two frames. We only want to see the
  891. # error once though.
  892. "frames": [
  893. {
  894. "abs_path": "http://example.com/file.min.js",
  895. "filename": "file.min.js",
  896. "lineno": 1,
  897. "colno": 39,
  898. },
  899. {
  900. "abs_path": "http://example.com/file.min.js",
  901. "filename": "file.min.js",
  902. "lineno": 1,
  903. "colno": 39,
  904. },
  905. ]
  906. },
  907. }
  908. ]
  909. },
  910. }
  911. event = self.post_and_retrieve_event(data)
  912. assert event.data["errors"] == [
  913. {"url": "http://example.com/file1.js", "type": "fetch_invalid_http_code", "value": 404}
  914. ]
  915. exception = event.interfaces["exception"]
  916. frame_list = exception.values[0].stacktrace.frames
  917. frame = frame_list[0]
  918. # no context information ...
  919. assert not frame.pre_context
  920. assert not frame.context_line
  921. assert not frame.post_context
  922. # ... but line, column numbers are still correctly mapped
  923. assert frame.lineno == 3
  924. assert frame.colno == 9
  925. @responses.activate
  926. def test_failed_sourcemap_expansion(self):
  927. """
  928. Tests attempting to parse an indexed source map where each section has a "url"
  929. property - this is unsupported and should fail.
  930. """
  931. responses.add(
  932. responses.GET,
  933. "http://example.com/unsupported.min.js",
  934. body=load_fixture("unsupported.min.js"),
  935. content_type="application/javascript; charset=utf-8",
  936. )
  937. responses.add(
  938. responses.GET,
  939. "http://example.com/unsupported.sourcemap.js",
  940. body=load_fixture("unsupported.sourcemap.js"),
  941. content_type="application/json; charset=utf-8",
  942. )
  943. data = {
  944. "timestamp": self.min_ago,
  945. "message": "hello",
  946. "platform": "javascript",
  947. "exception": {
  948. "values": [
  949. {
  950. "type": "Error",
  951. "stacktrace": {
  952. "frames": [
  953. {
  954. "abs_path": "http://example.com/unsupported.min.js",
  955. "filename": "indexed.min.js",
  956. "lineno": 1,
  957. "colno": 39,
  958. }
  959. ]
  960. },
  961. }
  962. ]
  963. },
  964. }
  965. event = self.post_and_retrieve_event(data)
  966. assert event.data["errors"] == [
  967. {"url": "http://example.com/unsupported.sourcemap.js", "type": "js_invalid_source"}
  968. ]
  969. def test_failed_sourcemap_expansion_data_url(self):
  970. data = {
  971. "timestamp": self.min_ago,
  972. "message": "hello",
  973. "platform": "javascript",
  974. "exception": {
  975. "values": [
  976. {
  977. "type": "Error",
  978. "stacktrace": {
  979. "frames": [
  980. {
  981. "abs_path": "data:application/javascript,base46,asfasf",
  982. "filename": "indexed.min.js",
  983. "lineno": 1,
  984. "colno": 39,
  985. }
  986. ]
  987. },
  988. }
  989. ]
  990. },
  991. }
  992. event = self.post_and_retrieve_event(data)
  993. assert event.data["errors"] == [{"url": "<data url>", "type": "js_no_source"}]
  994. @responses.activate
  995. def test_failed_sourcemap_expansion_missing_location_entirely(self):
  996. responses.add(
  997. responses.GET,
  998. "http://example.com/indexed.min.js",
  999. body="//# sourceMappingURL=indexed.sourcemap.js",
  1000. )
  1001. responses.add(responses.GET, "http://example.com/indexed.sourcemap.js", body="{}")
  1002. data = {
  1003. "timestamp": self.min_ago,
  1004. "message": "hello",
  1005. "platform": "javascript",
  1006. "exception": {
  1007. "values": [
  1008. {
  1009. "type": "Error",
  1010. "stacktrace": {
  1011. "frames": [
  1012. {
  1013. "abs_path": "http://example.com/indexed.min.js",
  1014. "filename": "indexed.min.js",
  1015. "lineno": 1,
  1016. "colno": 1,
  1017. },
  1018. {
  1019. "abs_path": "http://example.com/indexed.min.js",
  1020. "filename": "indexed.min.js",
  1021. },
  1022. ]
  1023. },
  1024. }
  1025. ]
  1026. },
  1027. }
  1028. event = self.post_and_retrieve_event(data)
  1029. assert "errors" not in event.data
  1030. @responses.activate
  1031. def test_html_response_for_js(self):
  1032. responses.add(
  1033. responses.GET,
  1034. "http://example.com/file1.js",
  1035. body=" <!DOCTYPE html><html><head></head><body></body></html>",
  1036. )
  1037. responses.add(
  1038. responses.GET,
  1039. "http://example.com/file2.js",
  1040. body="<!doctype html><html><head></head><body></body></html>",
  1041. )
  1042. responses.add(
  1043. responses.GET,
  1044. "http://example.com/file.html",
  1045. body=(
  1046. "<!doctype html><html><head></head><body><script>/*legit case*/</script></body></html>"
  1047. ),
  1048. )
  1049. data = {
  1050. "timestamp": self.min_ago,
  1051. "message": "hello",
  1052. "platform": "javascript",
  1053. "exception": {
  1054. "values": [
  1055. {
  1056. "type": "Error",
  1057. "stacktrace": {
  1058. "frames": [
  1059. {
  1060. "abs_path": "http://example.com/file1.js",
  1061. "filename": "file.min.js",
  1062. "lineno": 1,
  1063. "colno": 39,
  1064. },
  1065. {
  1066. "abs_path": "http://example.com/file2.js",
  1067. "filename": "file.min.js",
  1068. "lineno": 1,
  1069. "colno": 39,
  1070. },
  1071. {
  1072. "abs_path": "http://example.com/file.html",
  1073. "filename": "file.html",
  1074. "lineno": 1,
  1075. "colno": 1,
  1076. },
  1077. ]
  1078. },
  1079. }
  1080. ]
  1081. },
  1082. }
  1083. event = self.post_and_retrieve_event(data)
  1084. assert event.data["errors"] == [
  1085. {"url": "http://example.com/file1.js", "type": "js_invalid_content"},
  1086. {"url": "http://example.com/file2.js", "type": "js_invalid_content"},
  1087. ]
  1088. def _test_expansion_via_release_archive(self, link_sourcemaps: bool):
  1089. project = self.project
  1090. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  1091. release.add_project(project)
  1092. manifest = {
  1093. "org": self.organization.slug,
  1094. "release": release.version,
  1095. "files": {
  1096. "files/_/_/file.min.js": {
  1097. "url": "http://example.com/file.min.js",
  1098. },
  1099. "files/_/_/file1.js": {
  1100. "url": "http://example.com/file1.js",
  1101. },
  1102. "files/_/_/file2.js": {
  1103. "url": "http://example.com/file2.js",
  1104. },
  1105. "files/_/_/file.sourcemap.js": {
  1106. "url": "http://example.com/file.sourcemap.js",
  1107. },
  1108. },
  1109. }
  1110. file_like = BytesIO()
  1111. with zipfile.ZipFile(file_like, "w") as zip:
  1112. for rel_path, entry in manifest["files"].items():
  1113. name = os.path.basename(rel_path)
  1114. content = load_fixture(name)
  1115. if name == "file.min.js" and not link_sourcemaps:
  1116. # Remove link to source map, add to header instead
  1117. content = content.replace(b"//@ sourceMappingURL=file.sourcemap.js", b"")
  1118. entry["headers"] = {"SourceMap": "/file.sourcemap.js"}
  1119. zip.writestr(rel_path, content)
  1120. zip.writestr("manifest.json", json.dumps(manifest))
  1121. file_like.seek(0)
  1122. file = File.objects.create(name="doesnt_matter", type="release.bundle")
  1123. file.putfile(file_like)
  1124. update_artifact_index(release, None, file)
  1125. data = {
  1126. "timestamp": self.min_ago,
  1127. "message": "hello",
  1128. "platform": "javascript",
  1129. "release": "abc",
  1130. "exception": {
  1131. "values": [
  1132. {
  1133. "type": "Error",
  1134. "stacktrace": {
  1135. "frames": [
  1136. {
  1137. "abs_path": "http://example.com/file.min.js",
  1138. "filename": "file.min.js",
  1139. "lineno": 1,
  1140. "colno": 39,
  1141. },
  1142. {
  1143. "abs_path": "http://example.com/file.min.js",
  1144. "filename": "file.min.js",
  1145. "lineno": 1,
  1146. "colno": 79,
  1147. },
  1148. ]
  1149. },
  1150. }
  1151. ]
  1152. },
  1153. }
  1154. event = self.post_and_retrieve_event(data)
  1155. assert "errors" not in event.data
  1156. exception = event.interfaces["exception"]
  1157. frame_list = exception.values[0].stacktrace.frames
  1158. frame = frame_list[0]
  1159. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  1160. assert frame.context_line == "\treturn a + b; // fôo"
  1161. assert frame.post_context == ["}", ""]
  1162. frame = frame_list[1]
  1163. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  1164. assert frame.context_line == "\treturn a * b;"
  1165. assert frame.post_context == [
  1166. "}",
  1167. "function divide(a, b) {",
  1168. '\t"use strict";',
  1169. "\ttry {",
  1170. "\t\treturn multiply(add(a, b), a, b) / c;",
  1171. ]
  1172. def test_expansion_via_release_archive(self):
  1173. self._test_expansion_via_release_archive(link_sourcemaps=True)
  1174. def test_expansion_via_release_archive_no_sourcemap_link(self):
  1175. self._test_expansion_via_release_archive(link_sourcemaps=False)
  1176. def test_node_processing(self):
  1177. project = self.project
  1178. release = Release.objects.create(
  1179. organization_id=project.organization_id, version="nodeabc123"
  1180. )
  1181. release.add_project(project)
  1182. with open(get_fixture_path("dist.bundle.js"), "rb") as f:
  1183. f_minified = File.objects.create(
  1184. name="dist.bundle.js",
  1185. type="release.file",
  1186. headers={"Content-Type": "application/javascript"},
  1187. )
  1188. f_minified.putfile(f)
  1189. ReleaseFile.objects.create(
  1190. name=f"~/{f_minified.name}",
  1191. release_id=release.id,
  1192. organization_id=project.organization_id,
  1193. file=f_minified,
  1194. )
  1195. with open(get_fixture_path("dist.bundle.js.map"), "rb") as f:
  1196. f_sourcemap = File.objects.create(
  1197. name="dist.bundle.js.map",
  1198. type="release.file",
  1199. headers={"Content-Type": "application/javascript"},
  1200. )
  1201. f_sourcemap.putfile(f)
  1202. ReleaseFile.objects.create(
  1203. name=f"~/{f_sourcemap.name}",
  1204. release_id=release.id,
  1205. organization_id=project.organization_id,
  1206. file=f_sourcemap,
  1207. )
  1208. data = {
  1209. "timestamp": self.min_ago,
  1210. "message": "hello",
  1211. "platform": "node",
  1212. "release": "nodeabc123",
  1213. "exception": {
  1214. "values": [
  1215. {
  1216. "type": "Error",
  1217. "stacktrace": {
  1218. "frames": [
  1219. {
  1220. "filename": "app:///dist.bundle.js",
  1221. "function": "bar",
  1222. "lineno": 9,
  1223. "colno": 2321,
  1224. },
  1225. {
  1226. "filename": "app:///dist.bundle.js",
  1227. "function": "foo",
  1228. "lineno": 3,
  1229. "colno": 2308,
  1230. },
  1231. {
  1232. "filename": "app:///dist.bundle.js",
  1233. "function": "App",
  1234. "lineno": 3,
  1235. "colno": 1011,
  1236. },
  1237. {
  1238. "filename": "app:///dist.bundle.js",
  1239. "function": "Object.<anonymous>",
  1240. "lineno": 1,
  1241. "colno": 1014,
  1242. },
  1243. {
  1244. "filename": "app:///dist.bundle.js",
  1245. "function": "__webpack_require__",
  1246. "lineno": 20,
  1247. "colno": 30,
  1248. },
  1249. {
  1250. "filename": "app:///dist.bundle.js",
  1251. "function": "<unknown>",
  1252. "lineno": 18,
  1253. "colno": 63,
  1254. },
  1255. ]
  1256. },
  1257. }
  1258. ]
  1259. },
  1260. }
  1261. event = self.post_and_retrieve_event(data)
  1262. exception = event.interfaces["exception"]
  1263. frame_list = exception.values[0].stacktrace.frames
  1264. assert len(frame_list) == 6
  1265. assert frame_list[0].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1266. assert frame_list[0].function == "bar"
  1267. assert frame_list[0].lineno == 8
  1268. assert frame_list[1].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1269. assert frame_list[1].function == "foo"
  1270. assert frame_list[1].lineno == 2
  1271. assert frame_list[2].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1272. assert frame_list[2].function == "App"
  1273. assert frame_list[2].lineno == 2
  1274. assert frame_list[3].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1275. assert frame_list[3].function == "Object.<anonymous>"
  1276. assert frame_list[3].lineno == 1
  1277. assert frame_list[4].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1278. assert frame_list[4].function == "__webpack_require__"
  1279. assert frame_list[4].lineno == 19
  1280. assert frame_list[5].abs_path == "webpack:///webpack/bootstrap d9a5a31d9276b73873d3"
  1281. assert frame_list[5].function == "<unknown>"
  1282. assert frame_list[5].lineno == 16
  1283. @responses.activate
  1284. def test_no_fetch_from_http(self):
  1285. responses.add(
  1286. responses.GET,
  1287. "http://example.com/node_app.min.js",
  1288. body=load_fixture("node_app.min.js"),
  1289. content_type="application/javascript; charset=utf-8",
  1290. )
  1291. responses.add(
  1292. responses.GET,
  1293. "http://example.com/node_app.min.js.map",
  1294. body=load_fixture("node_app.min.js.map"),
  1295. content_type="application/javascript; charset=utf-8",
  1296. )
  1297. data = {
  1298. "timestamp": self.min_ago,
  1299. "message": "hello",
  1300. "platform": "node",
  1301. "exception": {
  1302. "values": [
  1303. {
  1304. "type": "Error",
  1305. "stacktrace": {
  1306. "frames": [
  1307. {
  1308. "abs_path": "node_bootstrap.js",
  1309. "filename": "node_bootstrap.js",
  1310. "lineno": 1,
  1311. "colno": 38,
  1312. },
  1313. {
  1314. "abs_path": "timers.js",
  1315. "filename": "timers.js",
  1316. "lineno": 1,
  1317. "colno": 39,
  1318. },
  1319. {
  1320. "abs_path": "webpack:///internal",
  1321. "filename": "internal",
  1322. "lineno": 1,
  1323. "colno": 43,
  1324. },
  1325. {
  1326. "abs_path": "webpack:///~/some_dep/file.js",
  1327. "filename": "file.js",
  1328. "lineno": 1,
  1329. "colno": 41,
  1330. },
  1331. {
  1332. "abs_path": "webpack:///./node_modules/file.js",
  1333. "filename": "file.js",
  1334. "lineno": 1,
  1335. "colno": 42,
  1336. },
  1337. {
  1338. "abs_path": "http://example.com/node_app.min.js",
  1339. "filename": "node_app.min.js",
  1340. "lineno": 1,
  1341. "colno": 40,
  1342. },
  1343. ]
  1344. },
  1345. }
  1346. ]
  1347. },
  1348. }
  1349. event = self.post_and_retrieve_event(data)
  1350. exception = event.interfaces["exception"]
  1351. frame_list = exception.values[0].stacktrace.frames
  1352. # This one should not process, so this one should be none.
  1353. assert exception.values[0].raw_stacktrace is None
  1354. # None of the in app should update
  1355. for x in range(6):
  1356. assert not frame_list[x].in_app
  1357. @responses.activate
  1358. def test_html_file_with_query_param_ending_with_js_extension(self):
  1359. responses.add(
  1360. responses.GET,
  1361. "http://example.com/file.html",
  1362. body=(
  1363. "<!doctype html><html><head></head><body><script>/*legit case*/</script></body></html>"
  1364. ),
  1365. )
  1366. data = {
  1367. "timestamp": self.min_ago,
  1368. "message": "hello",
  1369. "platform": "javascript",
  1370. "exception": {
  1371. "values": [
  1372. {
  1373. "type": "Error",
  1374. "stacktrace": {
  1375. "frames": [
  1376. {
  1377. "abs_path": "http://example.com/file.html?sw=iddqd1337.js",
  1378. "filename": "file.html",
  1379. "lineno": 1,
  1380. "colno": 1,
  1381. },
  1382. ]
  1383. },
  1384. }
  1385. ]
  1386. },
  1387. }
  1388. event = self.post_and_retrieve_event(data)
  1389. assert "errors" not in event.data
  1390. def test_expansion_with_debug_id(self):
  1391. project = self.project
  1392. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  1393. release.add_project(project)
  1394. debug_id = "c941d872-af1f-4f0c-a7ff-ad3d295fe153"
  1395. compressed = BytesIO()
  1396. with zipfile.ZipFile(compressed, mode="w") as zip_file:
  1397. zip_file.writestr("files/_/_/file.min.js", load_fixture("file.min.js"))
  1398. zip_file.writestr("files/_/_/file1.js", load_fixture("file1.js"))
  1399. zip_file.writestr("files/_/_/file2.js", load_fixture("file2.js"))
  1400. zip_file.writestr("files/_/_/empty.js", load_fixture("empty.js"))
  1401. zip_file.writestr(
  1402. "files/_/_/file.wc.sourcemap.js", load_fixture("file.wc.sourcemap.js")
  1403. )
  1404. zip_file.writestr(
  1405. "manifest.json",
  1406. json.dumps(
  1407. {
  1408. "org": self.organization.slug,
  1409. "release": release.version,
  1410. "files": {
  1411. "files/_/_/file.min.js": {
  1412. "url": "~/file.min.js",
  1413. "type": "minified_source",
  1414. "headers": {
  1415. "content-type": "application/json",
  1416. "debug-id": debug_id,
  1417. "sourcemap": "~/file.sourcemap.js",
  1418. },
  1419. },
  1420. "files/_/_/file1.js": {
  1421. "url": "~/file1.js",
  1422. "type": "source",
  1423. "headers": {
  1424. "content-type": "application/json",
  1425. },
  1426. },
  1427. "files/_/_/file2.js": {
  1428. "url": "~/file2.js",
  1429. "type": "source",
  1430. "headers": {
  1431. "content-type": "application/json",
  1432. },
  1433. },
  1434. "files/_/_/empty.js": {
  1435. "url": "~/empty.js",
  1436. "type": "source",
  1437. "headers": {
  1438. "content-type": "application/json",
  1439. },
  1440. },
  1441. "files/_/_/file.wc.sourcemap.js": {
  1442. "url": "~/file.wc.sourcemap.js",
  1443. "type": "source_map",
  1444. "headers": {
  1445. "content-type": "application/json",
  1446. "debug-id": debug_id,
  1447. },
  1448. },
  1449. },
  1450. }
  1451. ),
  1452. )
  1453. compressed.seek(0)
  1454. file = File.objects.create(name="bundle.zip", type="artifact.bundle")
  1455. file.putfile(compressed)
  1456. # We want to also store the release files for this bundle, to check if they work together.
  1457. compressed.seek(0)
  1458. file_for_release = File.objects.create(name="bundle.zip", type="release.bundle")
  1459. file_for_release.putfile(compressed)
  1460. update_artifact_index(release, None, file_for_release)
  1461. artifact_bundle = ArtifactBundle.objects.create(
  1462. organization_id=self.organization.id, bundle_id=uuid4(), file=file, artifact_count=5
  1463. )
  1464. DebugIdArtifactBundle.objects.create(
  1465. organization_id=self.organization.id,
  1466. debug_id=debug_id,
  1467. artifact_bundle=artifact_bundle,
  1468. source_file_type=SourceFileType.MINIFIED_SOURCE.value,
  1469. )
  1470. DebugIdArtifactBundle.objects.create(
  1471. organization_id=self.organization.id,
  1472. debug_id=debug_id,
  1473. artifact_bundle=artifact_bundle,
  1474. source_file_type=SourceFileType.SOURCE_MAP.value,
  1475. )
  1476. data = {
  1477. "timestamp": self.min_ago,
  1478. "message": "hello",
  1479. "platform": "javascript",
  1480. "release": "abc",
  1481. "exception": {
  1482. "values": [
  1483. {
  1484. "type": "Error",
  1485. "stacktrace": {
  1486. "frames": [
  1487. {
  1488. "abs_path": "http://example.com/file.min.js",
  1489. "filename": "file.min.js",
  1490. "lineno": 1,
  1491. "colno": 39,
  1492. },
  1493. {
  1494. "abs_path": "http://example.com/file.min.js",
  1495. "filename": "file.min.js",
  1496. "lineno": 1,
  1497. "colno": 79,
  1498. },
  1499. # We want also to test the source without minification.
  1500. {
  1501. "abs_path": "http://example.com/file1.js",
  1502. "filename": "file1.js",
  1503. "lineno": 3,
  1504. "colno": 12,
  1505. },
  1506. ]
  1507. },
  1508. }
  1509. ]
  1510. },
  1511. "debug_meta": {
  1512. "images": [
  1513. {
  1514. "type": "sourcemap",
  1515. "debug_id": debug_id,
  1516. "code_file": "http://example.com/file.min.js",
  1517. }
  1518. ]
  1519. },
  1520. }
  1521. event = self.post_and_retrieve_event(data)
  1522. assert "errors" not in event.data
  1523. exception = event.interfaces["exception"]
  1524. frame_list = exception.values[0].stacktrace.frames
  1525. frame = frame_list[0]
  1526. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  1527. assert frame.context_line == "\treturn a + b; // fôo"
  1528. assert frame.post_context == ["}", ""]
  1529. frame = frame_list[1]
  1530. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  1531. assert frame.context_line == "\treturn a * b;"
  1532. assert frame.post_context == [
  1533. "}",
  1534. "function divide(a, b) {",
  1535. '\t"use strict";',
  1536. "\ttry {",
  1537. "\t\treturn multiply(add(a, b), a, b) / c;",
  1538. ]
  1539. frame = frame_list[2]
  1540. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  1541. assert frame.context_line == "\treturn a + b; // fôo"
  1542. assert frame.post_context == ["}", ""]
  1543. def test_expansion_with_debug_id_and_sourcemap_without_sources_content(self):
  1544. debug_id = "c941d872-af1f-4f0c-a7ff-ad3d295fe153"
  1545. compressed = BytesIO()
  1546. with zipfile.ZipFile(compressed, mode="w") as zip_file:
  1547. zip_file.writestr("files/_/_/file.min.js", load_fixture("file.min.js"))
  1548. zip_file.writestr("files/_/_/file1.js", load_fixture("file1.js"))
  1549. zip_file.writestr("files/_/_/file2.js", load_fixture("file2.js"))
  1550. zip_file.writestr("files/_/_/empty.js", load_fixture("empty.js"))
  1551. zip_file.writestr("files/_/_/file.sourcemap.js", load_fixture("file.sourcemap.js"))
  1552. zip_file.writestr(
  1553. "manifest.json",
  1554. json.dumps(
  1555. {
  1556. "files": {
  1557. "files/_/_/file.min.js": {
  1558. "url": "~/file.min.js",
  1559. "type": "minified_source",
  1560. "headers": {
  1561. "content-type": "application/json",
  1562. "debug-id": debug_id,
  1563. "sourcemap": "~/file.sourcemap.js",
  1564. },
  1565. },
  1566. "files/_/_/file1.js": {
  1567. "url": "~/file1.js",
  1568. "type": "source",
  1569. "headers": {
  1570. "content-type": "application/json",
  1571. },
  1572. },
  1573. "files/_/_/file2.js": {
  1574. "url": "~/file2.js",
  1575. "type": "source",
  1576. "headers": {
  1577. "content-type": "application/json",
  1578. },
  1579. },
  1580. "files/_/_/empty.js": {
  1581. "url": "~/empty.js",
  1582. "type": "source",
  1583. "headers": {
  1584. "content-type": "application/json",
  1585. },
  1586. },
  1587. "files/_/_/file.sourcemap.js": {
  1588. "url": "~/file.sourcemap.js",
  1589. "type": "source_map",
  1590. "headers": {
  1591. "content-type": "application/json",
  1592. "debug-id": debug_id,
  1593. },
  1594. },
  1595. }
  1596. }
  1597. ),
  1598. )
  1599. compressed.seek(0)
  1600. file = File.objects.create(name="bundle.zip", type="artifact.bundle")
  1601. file.putfile(compressed)
  1602. artifact_bundle = ArtifactBundle.objects.create(
  1603. organization_id=self.organization.id, bundle_id=uuid4(), file=file, artifact_count=5
  1604. )
  1605. DebugIdArtifactBundle.objects.create(
  1606. organization_id=self.organization.id,
  1607. debug_id=debug_id,
  1608. artifact_bundle=artifact_bundle,
  1609. source_file_type=SourceFileType.MINIFIED_SOURCE.value,
  1610. )
  1611. DebugIdArtifactBundle.objects.create(
  1612. organization_id=self.organization.id,
  1613. debug_id=debug_id,
  1614. artifact_bundle=artifact_bundle,
  1615. source_file_type=SourceFileType.SOURCE_MAP.value,
  1616. )
  1617. data = {
  1618. "timestamp": self.min_ago,
  1619. "message": "hello",
  1620. "platform": "javascript",
  1621. "release": "abc",
  1622. "exception": {
  1623. "values": [
  1624. {
  1625. "type": "Error",
  1626. "stacktrace": {
  1627. "frames": [
  1628. {
  1629. "abs_path": "http://example.com/file.min.js",
  1630. "filename": "file.min.js",
  1631. "lineno": 1,
  1632. "colno": 39,
  1633. },
  1634. {
  1635. "abs_path": "http://example.com/file.min.js",
  1636. "filename": "file.min.js",
  1637. "lineno": 1,
  1638. "colno": 79,
  1639. },
  1640. ]
  1641. },
  1642. }
  1643. ]
  1644. },
  1645. "debug_meta": {
  1646. "images": [
  1647. {
  1648. "type": "sourcemap",
  1649. "debug_id": debug_id,
  1650. "code_file": "http://example.com/file.min.js",
  1651. }
  1652. ]
  1653. },
  1654. }
  1655. event = self.post_and_retrieve_event(data)
  1656. assert len(event.data["errors"]) == 3
  1657. assert event.data["errors"][0] == {
  1658. "type": "js_missing_sources_content",
  1659. "source": "http://example.com/file.min.js",
  1660. "sourcemap": f"debug-id:{debug_id}",
  1661. }
  1662. def test_expansion_with_debug_id_and_malformed_sourcemap(self):
  1663. debug_id = "c941d872-af1f-4f0c-a7ff-ad3d295fe153"
  1664. compressed = BytesIO()
  1665. with zipfile.ZipFile(compressed, mode="w") as zip_file:
  1666. zip_file.writestr("files/_/_/file.min.js", load_fixture("file.min.js"))
  1667. zip_file.writestr("files/_/_/file1.js", load_fixture("file1.js"))
  1668. zip_file.writestr("files/_/_/file2.js", load_fixture("file2.js"))
  1669. zip_file.writestr("files/_/_/empty.js", load_fixture("empty.js"))
  1670. zip_file.writestr(
  1671. "files/_/_/file.malformed.sourcemap.js", load_fixture("file.malformed.sourcemap.js")
  1672. )
  1673. zip_file.writestr(
  1674. "manifest.json",
  1675. json.dumps(
  1676. {
  1677. "files": {
  1678. "files/_/_/file.min.js": {
  1679. "url": "~/file.min.js",
  1680. "type": "minified_source",
  1681. "headers": {
  1682. "content-type": "application/json",
  1683. "debug-id": debug_id,
  1684. "sourcemap": "~/file.sourcemap.js",
  1685. },
  1686. },
  1687. "files/_/_/file1.js": {
  1688. "url": "~/file1.js",
  1689. "type": "source",
  1690. "headers": {
  1691. "content-type": "application/json",
  1692. },
  1693. },
  1694. "files/_/_/file2.js": {
  1695. "url": "~/file2.js",
  1696. "type": "source",
  1697. "headers": {
  1698. "content-type": "application/json",
  1699. },
  1700. },
  1701. "files/_/_/empty.js": {
  1702. "url": "~/empty.js",
  1703. "type": "source",
  1704. "headers": {
  1705. "content-type": "application/json",
  1706. },
  1707. },
  1708. "files/_/_/file.malformed.sourcemap.js": {
  1709. "url": "~/file.malformed.sourcemap.js",
  1710. "type": "source_map",
  1711. "headers": {
  1712. "content-type": "application/json",
  1713. "debug-id": debug_id,
  1714. },
  1715. },
  1716. }
  1717. }
  1718. ),
  1719. )
  1720. compressed.seek(0)
  1721. file = File.objects.create(name="bundle.zip", type="artifact.bundle")
  1722. file.putfile(compressed)
  1723. artifact_bundle = ArtifactBundle.objects.create(
  1724. organization_id=self.organization.id, bundle_id=uuid4(), file=file, artifact_count=5
  1725. )
  1726. DebugIdArtifactBundle.objects.create(
  1727. organization_id=self.organization.id,
  1728. debug_id=debug_id,
  1729. artifact_bundle=artifact_bundle,
  1730. source_file_type=SourceFileType.MINIFIED_SOURCE.value,
  1731. )
  1732. DebugIdArtifactBundle.objects.create(
  1733. organization_id=self.organization.id,
  1734. debug_id=debug_id,
  1735. artifact_bundle=artifact_bundle,
  1736. source_file_type=SourceFileType.SOURCE_MAP.value,
  1737. )
  1738. data = {
  1739. "timestamp": self.min_ago,
  1740. "message": "hello",
  1741. "platform": "javascript",
  1742. "release": "abc",
  1743. "exception": {
  1744. "values": [
  1745. {
  1746. "type": "Error",
  1747. "stacktrace": {
  1748. "frames": [
  1749. {
  1750. "abs_path": "http://example.com/file.min.js",
  1751. "filename": "file.min.js",
  1752. "lineno": 1,
  1753. "colno": 39,
  1754. },
  1755. {
  1756. "abs_path": "http://example.com/file.min.js",
  1757. "filename": "file.min.js",
  1758. "lineno": 1,
  1759. "colno": 79,
  1760. },
  1761. ]
  1762. },
  1763. }
  1764. ]
  1765. },
  1766. "debug_meta": {
  1767. "images": [
  1768. {
  1769. "type": "sourcemap",
  1770. "debug_id": debug_id,
  1771. "code_file": "http://example.com/file.min.js",
  1772. }
  1773. ]
  1774. },
  1775. }
  1776. event = self.post_and_retrieve_event(data)
  1777. assert len(event.data["errors"]) == 1
  1778. assert event.data["errors"][0] == {
  1779. "type": "js_invalid_source",
  1780. "debug_id": f"debug-id:{debug_id}",
  1781. }
  1782. def test_expansion_with_debug_id_not_found(self):
  1783. project = self.project
  1784. release = Release.objects.create(organization_id=project.organization_id, version="abc")
  1785. release.add_project(project)
  1786. manifest = {
  1787. "org": self.organization.slug,
  1788. "release": release.version,
  1789. "files": {
  1790. "files/_/_/file.min.js": {
  1791. "url": "http://example.com/file.min.js",
  1792. },
  1793. "files/_/_/file1.js": {
  1794. "url": "http://example.com/file1.js",
  1795. },
  1796. "files/_/_/file2.js": {
  1797. "url": "http://example.com/file2.js",
  1798. },
  1799. "files/_/_/file.sourcemap.js": {
  1800. "url": "http://example.com/file.sourcemap.js",
  1801. },
  1802. },
  1803. }
  1804. file_like = BytesIO()
  1805. with zipfile.ZipFile(file_like, "w") as zip:
  1806. for rel_path, entry in manifest["files"].items():
  1807. name = os.path.basename(rel_path)
  1808. content = load_fixture(name)
  1809. if name == "file.min.js":
  1810. # Remove link to source map, add to header instead
  1811. content = content.replace(b"//@ sourceMappingURL=file.sourcemap.js", b"")
  1812. entry["headers"] = {"SourceMap": "/file.sourcemap.js"}
  1813. zip.writestr(rel_path, content)
  1814. zip.writestr("manifest.json", json.dumps(manifest))
  1815. file_like.seek(0)
  1816. file = File.objects.create(name="release_bundle.zip", type="release.bundle")
  1817. file.putfile(file_like)
  1818. update_artifact_index(release, None, file)
  1819. debug_id = "c941d872-af1f-4f0c-a7ff-ad3d295fe153"
  1820. data = {
  1821. "timestamp": self.min_ago,
  1822. "message": "hello",
  1823. "platform": "javascript",
  1824. "release": "abc",
  1825. "exception": {
  1826. "values": [
  1827. {
  1828. "type": "Error",
  1829. "stacktrace": {
  1830. "frames": [
  1831. {
  1832. "abs_path": "http://example.com/file.min.js",
  1833. "filename": "file.min.js",
  1834. "lineno": 1,
  1835. "colno": 39,
  1836. },
  1837. {
  1838. "abs_path": "http://example.com/file.min.js",
  1839. "filename": "file.min.js",
  1840. "lineno": 1,
  1841. "colno": 79,
  1842. },
  1843. # We want also to test the source without minification.
  1844. {
  1845. "abs_path": "http://example.com/file1.js",
  1846. "filename": "file1.js",
  1847. "lineno": 3,
  1848. "colno": 12,
  1849. },
  1850. ]
  1851. },
  1852. }
  1853. ]
  1854. },
  1855. "debug_meta": {
  1856. "images": [
  1857. {
  1858. "type": "sourcemap",
  1859. "debug_id": debug_id,
  1860. "code_file": "http://example.com/file.min.js",
  1861. }
  1862. ]
  1863. },
  1864. }
  1865. event = self.post_and_retrieve_event(data)
  1866. assert "errors" not in event.data
  1867. exception = event.interfaces["exception"]
  1868. frame_list = exception.values[0].stacktrace.frames
  1869. frame = frame_list[0]
  1870. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  1871. assert frame.context_line == "\treturn a + b; // fôo"
  1872. assert frame.post_context == ["}", ""]
  1873. frame = frame_list[1]
  1874. assert frame.pre_context == ["function multiply(a, b) {", '\t"use strict";']
  1875. assert frame.context_line == "\treturn a * b;"
  1876. assert frame.post_context == [
  1877. "}",
  1878. "function divide(a, b) {",
  1879. '\t"use strict";',
  1880. "\ttry {",
  1881. "\t\treturn multiply(add(a, b), a, b) / c;",
  1882. ]
  1883. frame = frame_list[2]
  1884. assert frame.pre_context == ["function add(a, b) {", '\t"use strict";']
  1885. assert frame.context_line == "\treturn a + b; // fôo"
  1886. assert frame.post_context == ["}", ""]