-
-
Notifications
You must be signed in to change notification settings - Fork 760
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
review "assert" usage #8649
Comments
@ThomasWaldmann I found places where assert should be replaced eg : 1,2.....and many such places which need assert to be replaced.So I would first like to do a quick workaround for 1.4-maint branch. Is this file the entry point(where the workaround needs to be added) for borg??Or are there multiple entry points ?? After this, I would like to fix some problematic asserts.(but in some places I could not understand whether they are problematic or not, please help me in this :) ) |
The 2 places you found are to catch programming errors and are executed rather frequently. Thus, such a programming error likely would be catched before a release is made. Guess |
@ThomasWaldmann I am working on replacing assert ..will soon open a PR.Do you also suggest that I make the quick fix into 1.4 in another PR right now or wait? |
Yeah, you could do the quick fix for 1.4 first, then work on master, fixing the asserts. |
@ThomasWaldmann After doing quick fix, when I ran ![]() ![]() |
You need to run pytest with -vv to see the full diff. |
Hmm, that does not look like it is related to the quick fix.
|
|
OK, so:
|
I have checked all the specific error codes that borg provides but I found they are not suitable for this use case, so I think 2 is the best one. Also --show-rc does not log rc in this case as it exits before borg initialises.(so I guess can only manually find out rc using echo $?) |
See there for the problem description:
https://community.sonarsource.com/t/feature-python-assert-should-be-consider-harmful/38501
TL;DR: for now, do not run borg via
python3 -O
or withPYTHONOPTIMIZE
set.In the code,
assert
should be only used for:if <condition>: raise SomeException
So, the task for borg master branch is to do a systematic review and fix all problematic asserts.
In case we find a lot of places to fix, a quick workaround for 1.4-maint branch could be to disallow running borg with assertions switched off, something like:
Note: 2 is the classic error code for a fatal error, but borg 1.4.x also supports modern exit codes, so an appropriate one (2 or more specific) needs to be returned for that.
The text was updated successfully, but these errors were encountered: