Skip to content

six.reraise fails  #375

Description

@northbear

HI,
We are using modernize for upgrading a code. And we get fails after replacing raise with six.reraise in a function below:

def reformat_raise_error(header='', footer=''):
    if DEBUG or (not header and not footer):
        raise
    raise sys.exc_info()[0], '%s %s %s' % (header, sys.exc_info()[1], footer), sys.exc_info()[2]

It get translated in this way:

def reformat_raise_error(header='', footer=''):
    if DEBUG or (not header and not footer):
        raise
    six.reraise(sys.exc_info()[0], '%s %s %s' % (header, sys.exc_info()[1], footer), sys.exc_info()[2])

it falls with an error: type 'str' has no attribute __trackback__.

I tried to refactor the raise call.

def reformat_raise_error(header='', footer=''):
    if DEBUG or (not header and not footer):
        raise
    t, v, tb = sys.exc_info()
    six.reraise(t, t(' '.join([header, str(v), footer])), tb)

But I got even more frustrated error when running it with python2.7:

    six.reraise(t, t(' '.join([header, str(v), footer])), tb)
TypeError: function takes exactly 5 arguments (1 given)

I'd appreciate any advice.

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