Skip to content

Keep underlying exception traceback on Err.unwrap if available #3

Description

@katunilya

When we invoke Err.unwrap we can accidentally lose information about underlying error. If Err internal value is of type Exception / BaseException (somewhere in inheritance hiearachy) then when we raise ErrUnwrapError we should also include underlying exception.

How it works now?

def div(a, b) -> Result[float, Exception]:
  try:
    return Ok(a / b)
  except Exception as exc:
    return Err(exc)

div(1, 0).unwrap()  # raises ErrUnwrapError, but looses ZeroDivisionError

How it should work?

def div(a, b) -> Result[float, Exception]:
  try:
    return Ok(a / b)
  except Exception as exc:
    return Err(exc)

div(1, 0).unwrap()  # raises ErrUnwrapError, but also includes information about ZeroDivisionError in traceback

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions