Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Err.unwrap traceback better for debugging #1

Open
kykosic opened this issue Feb 8, 2020 · 0 comments
Open

Make Err.unwrap traceback better for debugging #1

kykosic opened this issue Feb 8, 2020 · 0 comments

Comments

@kykosic
Copy link
Owner

kykosic commented Feb 8, 2020

Example:

from pycats import Result


@Result.wrap
def divide(a, b):
    return a / b


d = divide(2, 0)

d.unwrap()

Will give a traceback like:

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-1-e472ddea34ee> in <module>
      9 d = divide(2, 0)
     10 
---> 11 d.unwrap()

pycats/pycats/data/result.py in unwrap(self)
    163     def unwrap(self):
    164         if isinstance(self.value, Exception):
--> 165             raise self.value
    166         return self.value

pycats/pycats/data/result.py in wrapped_func(*args, **kwargs)
    110         def wrapped_func(*args, **kwargs):
    111             try:
--> 112                 return Ok(func(*args, **kwargs))
    113             except Exception as e:
    114                 return Err(e)

<ipython-input-1-e472ddea34ee> in divide(a, b)
      4 @Result.wrap
      5 def divide(a, b):
----> 6     return a / b
      7 
      8 

ZeroDivisionError: division by zero

It would be helpful if the traceback included the line which actually called the wrapped function:

d = divide(2, 0)

instead of skipping from the .unwrap() call straight to inside the wrapped function. In a long chain of operations, it could be difficult to debug which operation was causing the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant