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

six.reraise fails #375

Open
northbear opened this issue Aug 23, 2023 · 0 comments
Open

six.reraise fails #375

northbear opened this issue Aug 23, 2023 · 0 comments

Comments

@northbear
Copy link

northbear commented Aug 23, 2023

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.

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