Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

except ParseError: --> except ParseError as e: #1177

Merged
merged 1 commit into from
Nov 24, 2017

Conversation

cclauss
Copy link

@cclauss cclauss commented Nov 23, 2017

Make the same fix in four different files where we are catching a ParseError and then re-raising it. In the except statement, we need to capture the exception into the variable in e so that we can re-raise it in the lines immediately following. Without this change, we would raise a NameError instead of the intended exception.

Discovered via flake8 testing of https://github.com/hyperledger/sawtooth-core on Python 3.6.3

$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

./cli/sawtooth_cli/identity.py:567:76: F821 undefined name 'e'
            raise CliException('Unable to read key in file: {}'.format(str(e)))
                                                                           ^

./cli/sawtooth_cli/sawset.py:290:76: F821 undefined name 'e'
            raise CliException('Unable to read key in file: {}'.format(str(e)))
                                                                           ^

./consensus/poet/cli/sawtooth_poet_cli/registration.py:258:76: F821 undefined name 'e'
            raise CliException('Unable to read key in file: {}'.format(str(e)))
                                                                           ^

./validator/sawtooth_validator/server/keys.py:62:67: F821 undefined name 'e'
                "Invalid key in file {}: {}".format(key_path, str(e)))
                                                                  ^

4     F821 undefined name 'e'

Signed-off-by: cclauss cclauss@bluewin.ch

Signed-off-by: cclauss <cclauss@bluewin.ch>
@nick-drozd
Copy link
Contributor

This is a known pylint bug: pylint-dev/pylint#626

@cclauss
Copy link
Author

cclauss commented Nov 24, 2017

This is not a bug in the linting tools...

  1. I did not use pylint.
  2. pylint doesn't understand the scope of except clause variables pylint-dev/pylint#626 is correct. Things changed in Python 3.4 and the code will raise an UnboundLocalError in Python 3.4+

@nick-drozd
Copy link
Contributor

@cclauss That was an incomplete thought on my part. What I meant was: These errors should have been caught by pylint (which runs as part of the build process), but, because of that bug, were not.

@peterschwarz peterschwarz merged commit b1b6b08 into hyperledger-archives:master Nov 24, 2017
@cclauss cclauss deleted the patch-2 branch November 24, 2017 22:30
asing177 pushed a commit to asing177/sawtooth-core that referenced this pull request Jan 15, 2019
except ParseError: --> except ParseError as e:
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants