Giter Site home page Giter Site logo

pycats's People

Contributors

kykosic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lehmaning

pycats's Issues

Make `Err.unwrap` traceback better for debugging

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.