Skip to content

Commit

Permalink
Handle invalid source encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Jan 8, 2016
1 parent baffe03 commit 3124ce5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sentry/lang/javascript/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ def fetch_file(url, project=None, release=None, allow_scraping=True):
}
raise CannotFetchSource(error)

# Make sure the file we're getting back is unicode, if it's not,
# it's either some encoding that we don't understand, or it's binary
# data which we can't process.
if not isinstance(result[1], unicode):
try:
result[1] = result[1].decode('utf8')
except UnicodeDecodeError:
error = {
'type': EventError.JS_INVALID_SOURCE_ENCODING,
'value': 'utf8',
'url': url,
}
raise CannotFetchSource(error)

return UrlResult(url, result[0], result[1])


Expand Down
2 changes: 2 additions & 0 deletions src/sentry/models/eventerror.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class EventError(object):
JS_MISSING_SOURCE = 'js_no_source'
JS_INVALID_SOURCEMAP = 'js_invalid_source'
JS_TOO_MANY_REMOTE_SOURCES = 'js_too_many_sources'
JS_INVALID_SOURCE_ENCODING = 'js_invalid_source_encoding'

_messages = {
INVALID_DATA: 'Discarded invalid value for parameter \'{name}\'',
Expand All @@ -29,6 +30,7 @@ class EventError(object):
JS_MISSING_SOURCE: 'Source code was not found for {url}',
JS_INVALID_SOURCEMAP: 'Sourcemap was invalid or not parseable: {url}',
JS_TOO_MANY_REMOTE_SOURCES: 'The maximum number of remote source requests was made',
JS_INVALID_SOURCE_ENCODING: 'Source file was not \'{value}\' encoding: {url}'
}

@classmethod
Expand Down

0 comments on commit 3124ce5

Please sign in to comment.