Skip to content

Commit

Permalink
Merge 574a6b5 into a29c267
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Apr 11, 2017
2 parents a29c267 + 574a6b5 commit 2a99efb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
12 changes: 8 additions & 4 deletions promise/promise.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from collections import namedtuple
from functools import partial, wraps
from sys import version_info
from sys import version_info, exc_info
from threading import Event, RLock

from six import reraise as raise_
from typing import (List, Any, Callable, Dict, Iterator, Optional, # flake8: noqa
Union)

Expand Down Expand Up @@ -58,14 +59,16 @@ def make_self_resolution_error():

_error_obj = {
'e': None
} # type: Dict[str, Union[None, Exception]]
} # type: Dict[str, Union[None, Exception]]


def try_catch(handler, *args, **kwargs):
try:
return handler(*args, **kwargs)
except Exception as e:
# import traceback
tb = exc_info()[2]
if tb is not None and not hasattr(e, '__traceback__'):
e.__traceback__ = tb
_error_obj['e'] = e
# print traceback.format_exc()
return _error_obj
Expand Down Expand Up @@ -190,7 +193,8 @@ def _settled_value(self, _raise=False):
return self._rejection_handler0
elif self._state == STATE_REJECTED:
if _raise:
raise self._fulfillment_handler0
raise_val = self._fulfillment_handler0
raise_(type(raise_val), raise_val, getattr(raise_val, '__traceback__', None))
return self._fulfillment_handler0

def _fulfill(self, value):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
'test': tests_require,
},
install_requires=[
'typing',
'typing', 'six'
],
tests_require=tests_require, )
9 changes: 9 additions & 0 deletions tests/test_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def throws(v):
p2.get()


def test_thrown_exceptions_have_stacktrace():
def throws(v):
assert False
p3 = Promise.resolve('a').then(throws)
with raises(AssertionError) as assert_exc:
p3.get()
assert assert_exc.traceback[-1].path.strpath == __file__


def test_fake_promise():
p = Promise()
p.do_resolve(FakeThenPromise())
Expand Down

0 comments on commit 2a99efb

Please sign in to comment.