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
run_command(error='status') ignored by python scripting lib #333
Conversation
I can confirm the problem, but I wonder if this PR is masking another bug, maybe introduced with cc6dbeb? |
@landam @wenzeslaus Looking at the code again, it seems that cc6dbeb has introduced a bug. I don't understand why run_command() is not always returning the returncode. run_command() actually returns handle_errors(). Maybe run_command() should call handle_errors() and return the returncode? |
See also related https://github.com/OSGeo/grass/blob/master/lib/python/script/core.py#L466 BTW, master has been decided to be 8.0 to my understanding @wenzeslaus Can you elaborate? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me, but I think they are incomplete with regard to fixing cc6dbeb. It seems that the case for errors == 'exit' must also be moved up, because according to the new documentation errors == 'exit' is independent of the returncode.
Bug history investigation: As for
|
There was a thorough discussion about the desired behavior of run_command() between 7.0 and 7.2 which is recorded in the Trac Ticket 2326. However, a return value is unexpected to Python programmers as exceptions are the usual error reporting mechanism in Python and thus dangerous because you could easily write code which was not checking anything and the error would appear only later. With interactive use, it is also awkward as you get 0 for every successfully executed line which is strange to Python users (not necessary even aware of process returncodes where Glynn addressed the different use cases (Python-like, immediate fail okay, error expected, more handling needed) by implementing the universal The case above, when None of the compatibility concerns should be relevant now as we are switching the major version and the proper on-error behavior was already in place since 7.2 (backported to 7.0), so if script used the defaults and was tested for errors in any way the exception would be generated (which is what happened on couple places in GRASS GIS, if I remember correctly, even after trying to address it beforehand, so it seems that the approach worked). Consequently, The same applies also to And yes, cc6dbeb assumes master is or will be 8.0, i.e., no other release from master before 8.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the change. Besides fixing the issue, I think it is actually implementing the originally intended behavior.
With errors="raise"
, returning 0 on success and raising exception on error does not make much sense as the 0 is not useful for anything (it was useful to keep old code running). With errors="status"
, returning returncode on error and returning result, which is None
in case of run_command()
, on success does not make sense either as it makes processing of the return value potentially awkward (although doable since bool(None) == bool(0)
). So, it makes sense that errors="status"
behaves little differently in the way that return value is always returncode, i.e., result parameter is ignored with errors="status"
.
I'm just asking for additional sentence or two in the documentation of handle_errors()
to describe the above and perhaps an extra comment in the code to describe the new structure which is less obvious than the previous one (change from "okay state if - error state ifs" to "any state if - okay state if - error state ifs").
I can see three related todos which are out of scope of this PR, but worth mentioning here: cc6dbeb for write_command()
, dedicated documentation for each function which is using handle_errors()
to cover specific cases and use cases (possibly disallowing some values of the error parameter), and tests.
Removing the 7.0.0 backwards compatibility from run_command() which was raising exception on error but returning 0 on success. Adding option to use the standard fatal() error handling which might be good for use within GRASS GIS code itself. Adding extensive documentation for the available options and linking all relevant functions. Also passing module name explicitelly to CalledModuleError as a parameter.
Agreed, it was not decided than master is automatically '8.x'. There will be probably more 7.x releases, eg. 7.10. Let's create for 8.x a new development branch, like |
@wenzeslaus Please suggest the fix in a new PR. The master should be synced with relbr78 behaviour, see #547 |
Replaced by #1839 |
It seems that
is not working as expected. Discovered (https://github.com/OSGeo/grass/blob/master/scripts/r.import/r.import.py#L183) by running
r.import
which forces reprojection even input data CRS and location matches.This PR should fix the issue. Only master seems to be affected.