Exemplo n.º 1
0
 def test_get_composite_hash_uses_exception_value_if_no_type_or_stack(self):
     interface = Stacktrace(frames=[])
     interface_exc = Exception.to_python(dict(value='bar'))
     result = interface.get_composite_hash({
         'sentry.interfaces.Exception': interface_exc,
     })
     self.assertEquals(result[-1], 'bar')
Exemplo n.º 2
0
    def to_python(cls, data, slim_frames=True, rust_renormalized=RUST_RENORMALIZED_DEFAULT):
        if not rust_renormalized:
            is_valid, errors = validate_and_default_interface(data, cls.path)
            if not is_valid:
                raise InterfaceValidationError("Invalid exception")

            if not (data.get('type') or data.get('value')):
                raise InterfaceValidationError("No 'type' or 'value' present")

        if get_path(data, 'stacktrace', 'frames', filter=True):
            stacktrace = Stacktrace.to_python(
                data['stacktrace'],
                slim_frames=slim_frames,
                rust_renormalized=rust_renormalized
            )
        else:
            stacktrace = None

        if get_path(data, 'raw_stacktrace', 'frames', filter=True):
            raw_stacktrace = Stacktrace.to_python(
                data['raw_stacktrace'], slim_frames=slim_frames, raw=True,
                rust_renormalized=rust_renormalized
            )
        else:
            raw_stacktrace = None

        type = data.get('type')
        value = data.get('value')

        if not rust_renormalized:
            if isinstance(value, six.string_types):
                if type is None:
                    m = _type_value_re.match(value)
                    if m:
                        type = m.group(1)
                        value = m.group(2).strip()
            elif value is not None:
                value = json.dumps(value)

            value = trim(value, 4096)

        if data.get('mechanism'):
            mechanism = Mechanism.to_python(data['mechanism'],
                                            rust_renormalized=rust_renormalized)
        else:
            mechanism = None

        kwargs = {
            'type': trim(type, 128),
            'value': value,
            'module': trim(data.get('module'), 128),
            'mechanism': mechanism,
            'stacktrace': stacktrace,
            'thread_id': trim(data.get('thread_id'), 40),
            'raw_stacktrace': raw_stacktrace,
        }

        return cls(**kwargs)
Exemplo n.º 3
0
    def to_python(cls, data, has_system_frames=None, slim_frames=True):
        if not (data.get('type') or data.get('value')):
            raise InterfaceValidationError("No 'type' or 'value' present")

        if data.get('stacktrace') and data['stacktrace'].get('frames'):
            stacktrace = Stacktrace.to_python(
                data['stacktrace'],
                has_system_frames=has_system_frames,
                slim_frames=slim_frames,
            )
        else:
            stacktrace = None

        if data.get('raw_stacktrace') and data['raw_stacktrace'].get('frames'):
            raw_stacktrace = Stacktrace.to_python(
                data['raw_stacktrace'],
                has_system_frames=has_system_frames,
                slim_frames=slim_frames,
                raw=True
            )
        else:
            raw_stacktrace = None

        type = data.get('type')
        value = data.get('value')
        if not type and ':' in value.split(' ', 1)[0]:
            type, value = value.split(':', 1)
            # in case of TypeError: foo (no space)
            value = value.strip()

        if value is not None and not isinstance(value, six.string_types):
            value = json.dumps(value)
        value = trim(value, 4096)

        mechanism = data.get('mechanism')
        if mechanism is not None:
            if not isinstance(mechanism, dict):
                raise InterfaceValidationError('Bad value for mechanism')
            mechanism = trim(data.get('mechanism'), 4096)
            mechanism.setdefault('type', 'generic')

        kwargs = {
            'type': trim(type, 128),
            'value': value,
            'module': trim(data.get('module'), 128),
            'mechanism': mechanism,
            'stacktrace': stacktrace,
            'thread_id': trim(data.get('thread_id'), 40),
            'raw_stacktrace': raw_stacktrace,
        }

        return cls(**kwargs)
Exemplo n.º 4
0
 def test_get_stacktrace_with_module(self):
     event = mock.Mock(spec=Event())
     interface = Stacktrace.to_python(dict(frames=[{'module': 'foo'}, {'module': 'bar'}]))
     result = interface.get_stacktrace(event)
     self.assertEquals(
         result, 'Stacktrace (most recent call last):\n\n  Module "foo"\n  Module "bar"'
     )
Exemplo n.º 5
0
 def test_get_stacktrace_with_filename_function_lineno_and_context(self):
     event = mock.Mock(spec=Event())
     interface = Stacktrace.to_python(
         dict(
             frames=[
                 {
                     'filename': 'foo',
                     'function': 'biz',
                     'lineno': 3,
                     'context_line': '  def foo(r):'
                 },
                 {
                     'filename': 'bar',
                     'function': 'baz',
                     'lineno': 5,
                     'context_line': '    return None'
                 },
             ]
         )
     )
     result = interface.get_stacktrace(event)
     self.assertEquals(
         result,
         'Stacktrace (most recent call last):\n\n  File "foo", line 3, in biz\n    def foo(r):\n  File "bar", line 5, in baz\n    return None'
     )
Exemplo n.º 6
0
 def test_get_stacktrace_with_filename_and_function(self):
     event = mock.Mock(spec=Event())
     interface = Stacktrace.to_python(
         dict(frames=[{"filename": "foo", "function": "biz"}, {"filename": "bar", "function": "baz"}])
     )
     result = interface.get_stacktrace(event)
     self.assertEquals(result, 'Stacktrace (most recent call last):\n\n  File "foo", in biz\n  File "bar", in baz')
Exemplo n.º 7
0
 def test_serialize_returns_frames(self):
     interface = Stacktrace.to_python(dict(frames=[{
         'lineno': 1,
         'filename': 'foo.py',
     }]))
     result = interface.to_json()
     assert 'frames' in result
Exemplo n.º 8
0
    def get_stacktrace(self, data):
        try:
            stacktrace = Stacktrace.to_python(data['stacktrace'])
        except KeyError:
            stacktrace = None

        return stacktrace
Exemplo n.º 9
0
 def test_legacy_interface(self):
     # Simple test to ensure legacy data works correctly with the ``Frame``
     # objects
     event = self.event
     interface = Stacktrace.to_python(event.data['sentry.interfaces.Stacktrace'])
     assert len(interface.frames) == 1
     assert interface == event.interfaces['sentry.interfaces.Stacktrace']
Exemplo n.º 10
0
    def test_over_max(self):
        values = []
        for n in xrange(5):
            values.append({
                'filename': 'frame %d' % n,
                'vars': {'foo': 'bar'},
                'context_line': 'b',
                'pre_context': ['a'],
                'post_context': ['c'],
            })
        interface = Stacktrace.to_python({'frames': values})
        slim_frame_data(interface, 4)

        assert len(interface.frames) == 5

        for value, num in zip(interface.frames[:2], xrange(2)):
            assert value.filename == 'frame %d' % num
            assert value.vars is not None
            assert value.pre_context is not None
            assert value.post_context is not None

        for value, num in zip(interface.frames[3:], xrange(3, 5)):
            assert value.filename == 'frame %d' % num
            assert value.vars is not None
            assert value.pre_context is not None
            assert value.post_context is not None

        value = interface.frames[2]
        assert value.filename == 'frame 2'
        assert not value.vars
        assert not value.pre_context
        assert not value.post_context
Exemplo n.º 11
0
 def test_does_not_overwrite_filename(self):
     interface = Stacktrace.to_python(
         dict(frames=[{"lineno": 1, "filename": "foo.js", "abs_path": "http://foo.com/foo.js"}])
     )
     frame = interface.frames[0]
     assert frame.filename == "foo.js"
     assert frame.abs_path == "http://foo.com/foo.js"
Exemplo n.º 12
0
    def to_python(cls, data, has_system_frames=None):
        if not (data.get('type') or data.get('value')):
            raise InterfaceValidationError("No 'type' or 'value' present")

        if data.get('stacktrace') and data['stacktrace'].get('frames'):
            stacktrace = Stacktrace.to_python(
                data['stacktrace'],
                has_system_frames=has_system_frames,
            )
        else:
            stacktrace = None

        type = data.get('type')
        value = data.get('value')
        if not type and ':' in value.split(' ', 1)[0]:
            type, value = value.split(':', 1)
            # in case of TypeError: foo (no space)
            value = value.strip()

        if value is not None and not isinstance(value, basestring):
            value = json.dumps(value)
        value = trim(value, 4096)

        kwargs = {
            'type': trim(type, 128),
            'value': value,
            'module': trim(data.get('module'), 128),
            'stacktrace': stacktrace,
        }

        return cls(**kwargs)
Exemplo n.º 13
0
def generate_culprit(data, platform=None):
    culprit = ''

    try:
        stacktraces = [
            e['stacktrace'] for e in data['sentry.interfaces.Exception']['values']
            if e.get('stacktrace')
        ]
    except KeyError:
        stacktrace = data.get('sentry.interfaces.Stacktrace')
        if stacktrace:
            stacktraces = [stacktrace]
        else:
            stacktraces = None

    if not stacktraces:
        if 'sentry.interfaces.Http' in data:
            culprit = data['sentry.interfaces.Http'].get('url', '')
    else:
        from sentry.interfaces.stacktrace import Stacktrace
        culprit = Stacktrace.to_python(stacktraces[-1]).get_culprit_string(
            platform=platform,
        )

    return truncatechars(culprit, MAX_CULPRIT_LENGTH)
Exemplo n.º 14
0
    def to_python(cls, data, has_system_frames=None, slim_frames=True):
        if not (data.get("type") or data.get("value")):
            raise InterfaceValidationError("No 'type' or 'value' present")

        if data.get("stacktrace") and data["stacktrace"].get("frames"):
            stacktrace = Stacktrace.to_python(
                data["stacktrace"], has_system_frames=has_system_frames, slim_frames=slim_frames
            )
        else:
            stacktrace = None

        if data.get("raw_stacktrace") and data["raw_stacktrace"].get("frames"):
            raw_stacktrace = Stacktrace.to_python(
                data["raw_stacktrace"], has_system_frames=has_system_frames, slim_frames=slim_frames
            )
        else:
            raw_stacktrace = None

        type = data.get("type")
        value = data.get("value")
        if not type and ":" in value.split(" ", 1)[0]:
            type, value = value.split(":", 1)
            # in case of TypeError: foo (no space)
            value = value.strip()

        if value is not None and not isinstance(value, six.string_types):
            value = json.dumps(value)
        value = trim(value, 4096)

        mechanism = data.get("mechanism")
        if mechanism is not None:
            if not isinstance(mechanism, dict):
                raise InterfaceValidationError("Bad value for mechanism")
            mechanism = trim(data.get("mechanism"), 4096)
            mechanism.setdefault("type", "generic")

        kwargs = {
            "type": trim(type, 128),
            "value": value,
            "module": trim(data.get("module"), 128),
            "mechanism": mechanism,
            "stacktrace": stacktrace,
            "thread_id": trim(data.get("thread_id"), 40),
            "raw_stacktrace": raw_stacktrace,
        }

        return cls(**kwargs)
Exemplo n.º 15
0
 def test_get_traceback_response(self, get_stacktrace):
     event = mock.Mock(spec=Event())
     event.message = "foo"
     get_stacktrace.return_value = "bar"
     interface = Stacktrace.to_python(dict(frames=[{"lineno": 1, "filename": "foo.py"}]))
     result = interface.get_traceback(event)
     get_stacktrace.assert_called_once_with(event, newest_first=None)
     self.assertEquals(result, "foo\n\nbar")
Exemplo n.º 16
0
    def get_stacktraces(self, data):
        exceptions = get_path(data, 'exception', 'values', filter=True, default=())
        stacktraces = [e['stacktrace'] for e in exceptions if e.get('stacktrace')]

        if 'stacktrace' in data:
            stacktraces.append(data['stacktrace'])

        return [(s, Stacktrace.to_python(s)) for s in stacktraces]
Exemplo n.º 17
0
 def test_allows_abs_path_without_filename(self):
     interface = Stacktrace.to_python(dict(frames=[{
         'lineno': 1,
         'abs_path': 'foo/bar/baz.py',
     }]))
     frame = interface.frames[0]
     assert frame.filename == 'foo/bar/baz.py'
     assert frame.abs_path == frame.filename
Exemplo n.º 18
0
 def test_ignores_results_with_empty_path(self):
     interface = Stacktrace.to_python(dict(frames=[{
         'lineno': 1,
         'filename': 'http://foo.com',
     }]))
     frame = interface.frames[0]
     assert frame.filename == 'http://foo.com'
     assert frame.abs_path == frame.filename
Exemplo n.º 19
0
 def test_coerces_url_filenames(self):
     interface = Stacktrace.to_python(dict(frames=[{
         'lineno': 1,
         'filename': 'http://foo.com/foo.js',
     }]))
     frame = interface.frames[0]
     assert frame.filename == '/foo.js'
     assert frame.abs_path == 'http://foo.com/foo.js'
Exemplo n.º 20
0
 def test_to_html_response(self, get_traceback):
     event = mock.Mock(spec=Event())
     event.message = 'foo'
     get_traceback.return_value = 'bar'
     interface = Stacktrace.to_python(dict(frames=[{'lineno': 1, 'filename': 'foo.py'}]))
     result = interface.to_html(event)
     get_traceback.assert_called_once_with(event, newest_first=False)
     self.assertTrue('<div class="module">' in result)
Exemplo n.º 21
0
 def test_get_traceback_response(self, get_stacktrace):
     event = mock.Mock(spec=Event())
     event.message = 'foo'
     get_stacktrace.return_value = 'bar'
     interface = Stacktrace.to_python(dict(frames=[{'lineno': 1, 'filename': 'foo.py'}]))
     result = interface.get_traceback(event)
     get_stacktrace.assert_called_once_with(event, newest_first=None)
     self.assertEquals(result, 'foo\n\nbar')
Exemplo n.º 22
0
 def test_does_not_overwrite_filename(self):
     interface = Stacktrace.to_python(dict(frames=[{
         'lineno': 1,
         'filename': 'foo.js',
         'abs_path': 'http://foo.com/foo.js',
     }]))
     frame = interface.frames[0]
     assert frame.filename == 'foo.js'
     assert frame.abs_path == 'http://foo.com/foo.js'
Exemplo n.º 23
0
 def test_cocoa_culprit(self):
     stacktrace = Stacktrace.to_python(dict(frames=[
         {
             'filename': 'foo/baz.c',
             'package': '/foo/bar/baz.dylib',
             'lineno': 1,
             'in_app': True,
             'function': 'fooBar',
         }
     ]))
     assert stacktrace.get_culprit_string(platform='cocoa') == 'fooBar (baz)'
Exemplo n.º 24
0
 def test_compute_hashes(self):
     interface = Stacktrace.to_python(
         dict(
             frames=[
                 {"lineno": 1, "filename": "foo.py", "in_app": True},
                 {"lineno": 1, "filename": "bar.py", "in_app": None},
             ]
         )
     )
     result = interface.compute_hashes("python")
     assert result == [["foo.py", 1, "bar.py", 1], ["foo.py", 1]]
Exemplo n.º 25
0
 def test_get_hash_does_not_group_different_js_errors(self):
     interface = Stacktrace.to_python({
         'frames': [{
             'context_line': '{snip}',
             'lineno': 20,
             'filename': 'https://foo.com/index.js',
             'function': '?',
         }],
     })
     result = interface.get_hash()
     assert result == []
Exemplo n.º 26
0
 def test_exclude_libswiftCore_from_in_app(self):
     stacktrace = Stacktrace.to_python(dict(frames=[
         {
             'filename': 'foo/baz.c',
             'package': '/foo/bar/libswiftCore.dylib',
             'lineno': 1,
             'in_app': True,
             'function': 'fooBar',
         }
     ]))
     assert stacktrace.frames[0].in_app is False
Exemplo n.º 27
0
    def get_stacktraces(self, data):
        try:
            stacktraces = [
                Stacktrace.to_python(e['stacktrace'])
                for e in data['sentry.interfaces.Exception']['values']
                if e.get('stacktrace')
            ]
        except KeyError:
            stacktraces = None

        return stacktraces
Exemplo n.º 28
0
 def interface(self):
     return Stacktrace.to_python(dict(frames=[
         {
             'filename': 'foo/bar.py'
         },
         {
             'filename': 'foo/baz.py',
             'lineno': 1,
             'in_app': True,
         }
     ]))
Exemplo n.º 29
0
 def test_get_hash_does_not_discard_non_urls(self):
     interface = Stacktrace.to_python({
         'frames': [{
             'context_line': '<HTML>',
             'lineno': 1,
             'abs_path': 'foo',
             'filename': 'foo',
             'function': '?',
         }],
     })
     result = interface.get_hash()
     assert result != []
Exemplo n.º 30
0
 def test_get_hash_discards_seemingly_useless_stack(self):
     interface = Stacktrace.to_python({
         'frames': [{
             'context_line': '<HTML>',
             'lineno': 1,
             'abs_path': 'http://example.com/foo',
             'filename': 'foo',
             'function': '?',
         }],
     })
     result = interface.get_hash()
     assert result == []
Exemplo n.º 31
0
 def test_get_hash_with_minimal_app_frames(self):
     frames = [{
         'lineno': 1,
         'filename': 'foo.py',
         'in_app': True,
     }] + [{
         'lineno': 1,
         'filename': 'bar.py',
         'in_app': False,
     } for _ in range(11)]
     interface = Stacktrace.to_python(dict(frames=frames))
     result = interface.get_hash(system_frames=False)
     assert not result
Exemplo n.º 32
0
 def test_compute_hashes(self):
     interface = Stacktrace.to_python(
         dict(frames=[{
             'lineno': 1,
             'filename': 'a/foo.py',
             'in_app': True,
         }, {
             'lineno': 1,
             'filename': 'a/bar.py',
             'in_app': None,
         }]))
     result = interface.compute_hashes('python')
     assert result == [['a/foo.py', 1, 'a/bar.py', 1], ['a/foo.py', 1]]
Exemplo n.º 33
0
 def test_compute_hashes_cocoa(self):
     interface = Stacktrace.to_python(
         dict(frames=[{
             'lineno': 1,
             'filename': '/foo/bar/bar.m',
             'in_app': True,
         }, {
             'lineno': 1,
             'filename': '/foo/bar/baz.m',
             'in_app': None,
         }]))
     result = interface.compute_hashes('cocoa')
     assert result == [['bar.m', 1, 'baz.m', 1], ['bar.m', 1]]
Exemplo n.º 34
0
 def test_get_stacktrace_with_module(self):
     event = mock.Mock(spec=Event())
     interface = Stacktrace.to_python(
         dict(frames=[{
             'module': 'foo'
         }, {
             'module': 'bar'
         }]))
     result = interface.get_stacktrace(event)
     self.assertEquals(
         result,
         'Stacktrace (most recent call last):\n\n  Module "foo"\n  Module "bar"'
     )
Exemplo n.º 35
0
    def get_stacktraces(self, data):
        try:
            stacktraces = [
                e['stacktrace'] for e in data['sentry.interfaces.Exception']['values']
                if e.get('stacktrace')
            ]
        except KeyError:
            stacktraces = []

        if 'sentry.interfaces.Stacktrace' in data:
            stacktraces.append(data['sentry.interfaces.Stacktrace'])

        return [(s, Stacktrace.to_python(s)) for s in stacktraces]
Exemplo n.º 36
0
 def test_does_not_overwrite_filename(self):
     interface = Stacktrace.to_python(
         dict(
             frames=[{
                 'lineno': 1,
                 'filename': 'foo.js',
                 'abs_path': 'http://foo.com/foo.js',
             }]
         )
     )
     frame = interface.frames[0]
     assert frame.filename == 'foo.js'
     assert frame.abs_path == 'http://foo.com/foo.js'
Exemplo n.º 37
0
 def test_compute_hashes_with_minimal_app_frames(self):
     frames = [{
         'lineno': 1,
         'filename': 'foo.py',
         'in_app': True,
     }] + [{
         'lineno': 1,
         'filename': 'bar.py',
         'in_app': False,
     } for _ in range(11)]
     interface = Stacktrace.to_python(dict(frames=frames))
     result = interface.compute_hashes()
     assert result == [['foo.py', 1, 'bar.py', 1]]
Exemplo n.º 38
0
 def interface(self):
     return Stacktrace.to_python(
         dict(
             frames=[
                 {
                     'filename': 'foo/bar.py'
                 }, {
                     'filename': 'foo/baz.py',
                     'lineno': 1,
                     'in_app': True,
                 }
             ]
         )
     )
Exemplo n.º 39
0
    def get_stacktraces(self, data):
        exceptions = get_path(data,
                              "exception",
                              "values",
                              filter=True,
                              default=())
        stacktraces = [
            e["stacktrace"] for e in exceptions if e.get("stacktrace")
        ]

        if "stacktrace" in data:
            stacktraces.append(data["stacktrace"])

        return [(s, Stacktrace.to_python(s)) for s in stacktraces]
Exemplo n.º 40
0
    def get_stacktraces(self, data):
        exceptions = get_path(data,
                              'exception',
                              'values',
                              filter=True,
                              default=())
        stacktraces = [
            e['stacktrace'] for e in exceptions if e.get('stacktrace')
        ]

        if 'stacktrace' in data:
            stacktraces.append(data['stacktrace'])

        return [(s, Stacktrace.to_python(s)) for s in stacktraces]
Exemplo n.º 41
0
    def to_python(cls, data, slim_frames=True):
        if get_path(data, 'stacktrace', 'frames', filter=True):
            stacktrace = Stacktrace.to_python(
                data['stacktrace'],
                slim_frames=slim_frames,
            )
        else:
            stacktrace = None

        if get_path(data, 'raw_stacktrace', 'frames', filter=True):
            raw_stacktrace = Stacktrace.to_python(
                data['raw_stacktrace'],
                slim_frames=slim_frames,
                raw=True,
            )
        else:
            raw_stacktrace = None

        type = data.get('type')
        value = data.get('value')

        if data.get('mechanism'):
            mechanism = Mechanism.to_python(data['mechanism'])
        else:
            mechanism = None

        kwargs = {
            'type': type,
            'value': value,
            'module': data.get('module'),
            'mechanism': mechanism,
            'stacktrace': stacktrace,
            'thread_id': data.get('thread_id'),
            'raw_stacktrace': raw_stacktrace,
        }

        return cls(**kwargs)
Exemplo n.º 42
0
    def test_requires_frames(self):
        with self.assertRaises(InterfaceValidationError):
            Stacktrace.to_python({})

        with self.assertRaises(InterfaceValidationError):
            Stacktrace.to_python(dict(frames=[]))

        with self.assertRaises(InterfaceValidationError):
            Stacktrace.to_python(dict(frames=1))
Exemplo n.º 43
0
 def test_get_stacktrace_with_filename_and_function(self):
     event = mock.Mock(spec=Event())
     interface = Stacktrace.to_python(
         dict(frames=[{
             'filename': 'foo',
             'function': 'biz'
         }, {
             'filename': 'bar',
             'function': 'baz'
         }]))
     result = interface.get_stacktrace(event)
     self.assertEquals(
         result,
         'Stacktrace (most recent call last):\n\n  File "foo", in biz\n  File "bar", in baz'
     )
Exemplo n.º 44
0
    def test_hash_without_system_frames(self):
        interface = Stacktrace.to_python(dict(frames=[{
            'lineno': 1,
            'filename': 'foo.py',
            'in_app': True,
        }, {
            'lineno': 1,
            'filename': 'bar.py',
            'in_app': None,
        }]))
        result = interface.get_hash(system_frames=False)
        assert result == ['foo.py', 1]

        result = interface.get_hash(system_frames=True)
        assert result == ['foo.py', 1, 'bar.py', 1]
Exemplo n.º 45
0
 def test_cocoa_culprit(self):
     stacktrace = Stacktrace.to_python(
         dict(
             frames=[
                 {
                     'filename': 'foo/baz.c',
                     'package': '/foo/bar/baz.dylib',
                     'lineno': 1,
                     'in_app': True,
                     'function': '-[CRLCrashAsyncSafeThread crash]',
                 }
             ]
         )
     )
     assert stacktrace.get_culprit_string(platform='cocoa') == '-[CRLCrashAsyncSafeThread crash]'
Exemplo n.º 46
0
 def test_get_hash_does_not_group_different_js_errors(self):
     interface = Stacktrace.to_python(
         {
             'frames': [
                 {
                     'context_line': '{snip}',
                     'lineno': 20,
                     'filename': 'https://foo.com/index.js',
                     'function': '?',
                 }
             ],
         }
     )
     result = interface.get_hash()
     assert result == []
Exemplo n.º 47
0
 def test_get_composite_hash_uses_exception_if_present(self):
     interface = Stacktrace.to_python(
         dict(frames=[{
             'context_line': 'foo bar',
             'lineno': 1,
             'filename': 'foo.py',
             'function': 'bar'
         }]))
     interface_exc = Exception.to_python(dict(type='exception',
                                              value='bar'))
     result = interface.get_composite_hash({
         'sentry.interfaces.Exception':
         interface_exc,
     })
     self.assertEquals(result[-1], 'exception')
Exemplo n.º 48
0
    def to_python(cls, data):
        assert data.get('type') or data.get('value')

        if data.get('stacktrace'):
            stacktrace = Stacktrace.to_python(data['stacktrace'])
        else:
            stacktrace = None

        kwargs = {
            'type': trim(data.get('type'), 128),
            'value': trim(data.get('value'), 4096),
            'module': trim(data.get('module'), 128),
            'stacktrace': stacktrace,
        }

        return cls(**kwargs)
Exemplo n.º 49
0
    def to_python(cls, data):
        threads = []

        for thread in data.get('values') or ():
            stacktrace = thread.get('stacktrace')
            if stacktrace is not None:
                stacktrace = Stacktrace.to_python(stacktrace, slim_frames=True)
            threads.append({
                'stacktrace': stacktrace,
                'id': trim(thread.get('id'), 40),
                'crashed': bool(thread.get('crashed')),
                'current': bool(thread.get('current')),
                'name': trim(thread.get('name'), 200),
            })

        return cls(values=threads)
Exemplo n.º 50
0
 def test_emoji_culprit(self):
     stacktrace = Stacktrace.to_python(
         dict(
             frames=[
                 {
                     'filename': 'foo/baz.c',
                     'package': '/foo/bar/baz.dylib',
                     'module': u'\U0001f62d',
                     'lineno': 1,
                     'in_app': True,
                     'function': u'\U0001f60d',
                 }
             ]
         )
     )
     assert stacktrace.get_culprit_string(platform='javascript') == u'\U0001f60d(\U0001f62d)'
Exemplo n.º 51
0
 def test_get_hash_does_not_discard_non_urls(self):
     interface = Stacktrace.to_python(
         {
             'frames': [
                 {
                     'context_line': '<HTML>',
                     'lineno': 1,
                     'abs_path': 'foo',
                     'filename': 'foo',
                     'function': '?',
                 }
             ],
         }
     )
     result = interface.get_hash()
     assert result != []
Exemplo n.º 52
0
 def test_get_hash_discards_seemingly_useless_stack(self):
     interface = Stacktrace.to_python(
         {
             'frames': [
                 {
                     'context_line': '<HTML>',
                     'lineno': 1,
                     'abs_path': 'http://example.com/foo',
                     'filename': 'foo',
                     'function': '?',
                 }
             ],
         }
     )
     result = interface.get_hash()
     assert result == []
Exemplo n.º 53
0
    def test_requires_filename(self):
        with self.assertRaises(AssertionError):
            Stacktrace.to_python(dict(frames=[{}]))

        Stacktrace.to_python(dict(frames=[{
            'filename': 'foo.py',
        }]))
        Stacktrace.to_python(dict(frames=[{
            'lineno': 1,
            'filename': 'foo.py',
        }]))
Exemplo n.º 54
0
    def test_frame_hard_limit(self):
        hard_limit = settings.SENTRY_STACKTRACE_FRAMES_HARD_LIMIT
        interface = Stacktrace.to_python({
            'frames': [
                {
                    'filename': 'Application.java',
                    'function': 'main',
                    'lineno': i,  # linenos from 1 to the hard limit + 1
                } for i in range(1, hard_limit + 2)
            ]
        })

        assert len(interface.frames) == hard_limit
        assert interface.frames[0].lineno == 1
        assert interface.frames[-1].lineno == hard_limit + 1
        # second to last frame (lineno:250) should be removed
        assert interface.frames[-2].lineno == hard_limit - 1
Exemplo n.º 55
0
 def test_to_html_render_call(self, get_frame_context, render_to_string, get_traceback):
     event = mock.Mock(spec=Event())
     get_traceback.return_value = 'bar'
     interface = Stacktrace.to_python(dict(frames=[{'lineno': 1, 'filename': 'foo.py'}]))
     result = interface.to_html(event)
     get_traceback.assert_called_once_with(event, newest_first=False)
     get_frame_context.assert_called_once_with(event=event, is_public=False)
     render_to_string.assert_called_once_with('sentry/partial/interfaces/stacktrace.html', {
         'event': event,
         'frames': [get_frame_context.return_value],
         'stacktrace': 'bar',
         'stack_id': 'stacktrace_1',
         'system_frames': 0,
         'newest_first': False,
         'is_public': False,
         'first_frame_omitted': None,
         'last_frame_omitted': None,
     })
     self.assertEquals(result, render_to_string.return_value)
Exemplo n.º 56
0
 def test_cocoa_strict_stacktrace(self):
     stacktrace = Stacktrace.to_python(
         dict(frames=[{
             'filename': 'foo/baz.c',
             'package': '/foo/bar/libswiftCore.dylib',
             'lineno': 1,
             'in_app': False,
             'function': 'fooBar',
         }, {
             'package': '/foo/bar/MyApp',
             'in_app': True,
             'function': 'fooBar2',
         }, {
             'filename': 'Mycontroller.swift',
             'package': '/foo/bar/MyApp',
             'in_app': True,
             'function': '-[CRLCrashAsyncSafeThread crash]',
         }]))
     assert stacktrace.get_culprit_string(
         platform='cocoa') == '-[CRLCrashAsyncSafeThread crash]'
Exemplo n.º 57
0
    def test_compute_hashes_excludes_single_frame_urls(self):
        """
        Browser JS will often throw errors (from inlined code in an HTML page)
        which contain only a single frame, no function name, and have the HTML
        document as the filename.

        In this case the hash is often not usable as the context cannot be
        trusted and the URL is dynamic.
        """
        interface = Stacktrace.to_python({
            'frames': [{
                'context_line': 'hello world',
                'abs_path': 'http://foo.com/bar/',
                'lineno': 107,
                'filename': '/bar/',
                'module': '<unknown module>',
            }],
        })
        result = interface.compute_hashes()
        assert result == []
Exemplo n.º 58
0
    def to_python(cls, data, has_system_frames=None):
        if not (data.get('type') or data.get('value')):
            raise InterfaceValidationError("No 'type' or 'value' present")

        if data.get('stacktrace') and data['stacktrace'].get('frames'):
            stacktrace = Stacktrace.to_python(
                data['stacktrace'],
                has_system_frames=has_system_frames,
            )
        else:
            stacktrace = None

        kwargs = {
            'type': trim(data.get('type'), 128),
            'value': trim(data.get('value'), 4096),
            'module': trim(data.get('module'), 128),
            'stacktrace': stacktrace,
        }

        return cls(**kwargs)
Exemplo n.º 59
0
    def test_get_hash_ignores_singular_anonymous_frame(self):
        interface = Stacktrace.to_python({
            'frames': [
                {"abs_path": "<anonymous>", "filename": "<anonymous>", "in_app": False},
                {"function": "c",
                 "abs_path": "file:///C:/Users/redacted/AppData/Local/redacted/resources/app.asar/dojo/dojo.js",
                 "in_app": False,
                 "lineno": 1188,
                 "colno": 125,
                 "filename": "/C:/Users/redacted/AppData/Local/redacted/app-2.4.1/resources/app.asar/dojo/dojo.js"},
                {"function": "Object._createDocumentViewModel",
                 "abs_path": "file:///C:/Users/redacted/AppData/Local/redacted/app-2.4.1/resources/app.asar/dojo/dojo.js",
                 "in_app": False,
                 "lineno": 1184,
                 "colno": 92,
                 "filename": "/C:/Users/redacted/AppData/Local/redacted/app-2.4.1/resources/app.asar/dojo/dojo.js"}
            ]
        })
        result = interface.get_hash(platform='javascript')

        assert result == []
Exemplo n.º 60
0
 def test_get_stacktrace_with_filename_function_lineno_and_context(self):
     event = mock.Mock(spec=Event())
     interface = Stacktrace.to_python(
         dict(frames=[
             {
                 'filename': 'foo',
                 'function': 'biz',
                 'lineno': 3,
                 'context_line': '  def foo(r):'
             },
             {
                 'filename': 'bar',
                 'function': 'baz',
                 'lineno': 5,
                 'context_line': '    return None'
             },
         ]))
     result = interface.get_stacktrace(event)
     self.assertEquals(
         result,
         'Stacktrace (most recent call last):\n\n  File "foo", line 3, in biz\n    def foo(r):\n  File "bar", line 5, in baz\n    return None'
     )