Skip to content

Revise the disabling of broad-except pylint warning (W0703) #1332

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

Closed
sechkova opened this issue Apr 6, 2021 · 3 comments · Fixed by #1559
Closed

Revise the disabling of broad-except pylint warning (W0703) #1332

sechkova opened this issue Apr 6, 2021 · 3 comments · Fixed by #1559
Assignees
Labels
backlog Issues to address with priority for current development goals low-prio
Milestone

Comments

@sechkova
Copy link
Contributor

sechkova commented Apr 6, 2021

Description of issue or feature request:
An (anti)pattern starts to appear in the newer code (where stricter pylint checks are applied), a tendency to disable broad-except warnings.

Even though each case has its arguments, we should as a minimum make sure we log the exception and not silently bury it.

Current behavior:
# pylint: disable=broad-except throughout the code

Expected behavior:
At least log the exception before ignoring it:

try:
    do_something()
except Exception as e:
    logger.exception("An exception occurred")

Sync with #1178

@sechkova sechkova changed the title Revise the disabling of broad-except pylint warnings Revise the disabling of broad-except pylint warning (W0703) Apr 6, 2021
@sechkova
Copy link
Contributor Author

sechkova commented Apr 6, 2021

This issue is directly related to the newer parts of code (api/*) where the new api/pylintrc config applies:

tuf/api/serialization/json.py:        except Exception as e:  # pylint: disable=broad-except
tuf/api/serialization/json.py:        except Exception as e:  # pylint: disable=broad-except
tuf/api/serialization/json.py:        except Exception as e:  # pylint: disable=broad-except

In the top-level pylintrc used by the rest of the code the broad-except warning is disabled globally.

@jku
Copy link
Member

jku commented May 26, 2021

It's possible that the deserialization cases are actually appropriate (I'm not sure if we can figure out all the ways that deserialization can fail, and the callers certainly won't care too much) but you are right we should review this.

@jku jku added the backlog Issues to address with priority for current development goals label May 26, 2021
@sechkova sechkova added this to the weeks22-23 milestone May 26, 2021
@jku jku modified the milestones: weeks22-23, Client Refactor May 26, 2021
@joshuagl joshuagl removed this from the weeks22-23 milestone Jun 9, 2021
@sechkova
Copy link
Contributor Author

sechkova commented Sep 1, 2021

I tested this with the intention to close the issue since the disable is well justified in serialisation/json.py and another exception is re-raised from the broad one ... but surprisingly pylint agrees with us!
Pylint does not emit the error anymore and the disabling is not needed ... it was needed when python 2.x was supported and six was used (see bd94f6d).

Assigning this to myself to fix it (remove the disabling of the warning).

@sechkova sechkova self-assigned this Sep 1, 2021
@sechkova sechkova added this to the Sprint 7 milestone Sep 1, 2021
@jku jku closed this as completed in #1559 Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Issues to address with priority for current development goals low-prio
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants