mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
Fix browser error reporting to find webpack source map files.
When we switched to using webpack, source map files weren't being logged in the expected place.
This commit is contained in:
committed by
Tim Abbott
parent
7778a66171
commit
5932896ebb
@@ -5,15 +5,15 @@ import os.path
|
||||
import sourcemap
|
||||
from six.moves import map
|
||||
|
||||
from typing import Dict, Text
|
||||
from typing import Dict, List, Text
|
||||
|
||||
|
||||
class SourceMap(object):
|
||||
'''Map (line, column) pairs from generated to source file.'''
|
||||
|
||||
def __init__(self, sourcemap_dir):
|
||||
# type: (Text) -> None
|
||||
self._dir = sourcemap_dir
|
||||
def __init__(self, sourcemap_dirs):
|
||||
# type: (List[Text]) -> None
|
||||
self._dirs = sourcemap_dirs
|
||||
self._indices = {} # type: Dict[Text, sourcemap.SourceMapDecoder]
|
||||
|
||||
def _index_for(self, minified_src):
|
||||
@@ -21,8 +21,12 @@ class SourceMap(object):
|
||||
'''Return the source map index for minified_src, loading it if not
|
||||
already loaded.'''
|
||||
if minified_src not in self._indices:
|
||||
with open(os.path.join(self._dir, minified_src + '.map')) as fp:
|
||||
self._indices[minified_src] = sourcemap.load(fp)
|
||||
for source_dir in self._dirs:
|
||||
filename = os.path.join(source_dir, minified_src + '.map')
|
||||
if os.path.isfile(filename):
|
||||
with open(filename) as fp:
|
||||
self._indices[minified_src] = sourcemap.load(fp)
|
||||
break
|
||||
|
||||
return self._indices[minified_src]
|
||||
|
||||
@@ -31,7 +35,7 @@ class SourceMap(object):
|
||||
out = '' # type: Text
|
||||
for ln in stacktrace.splitlines():
|
||||
out += ln + '\n'
|
||||
match = re.search(r'/static/min/(.+)(\.[0-9a-f]+)\.js:(\d+):(\d+)', ln)
|
||||
match = re.search(r'/static/(?:webpack-bundles|min)/(.+)(\.[\.0-9a-f]+)\.js:(\d+):(\d+)', ln)
|
||||
if match:
|
||||
# Get the appropriate source map for the minified file.
|
||||
minified_src = match.groups()[0] + '.js'
|
||||
|
||||
Reference in New Issue
Block a user