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

Fix run_cmd error handling #4067

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Flamefire
Copy link
Contributor

@Flamefire Flamefire commented Aug 23, 2022

Don't raise an error when log_ok=False is passed, i.e. the caller wants to handle the error.

The naming is confusing and the dependency on the strictness level is likely wrong. E.g. the caller may not expect a failing command to return from this function but to raise an error instead. However the user might have set the strictness to IGNORE which defeats the purpose of log_ok.

This change now allows to use log_all=True, log_ok=False to log the command and output and handle potential errors at the call site.

This is very likely the intended behavior, see e.g.

# set log_ok to False so we can catch the error instead of run_cmd
(output, ec) = run_cmd(cmd, log_ok=False, simple=False, regexp=False, inp=stdin)

# - Never raise an error (e.g. caller handles that)
# - Independently of the exit code log command and output
# - Assure the command completed with no error (i.e. even for strictness=IGNORE)
if check_ec and log_ok:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the current behavior of run_cmd is bloody confusing, and the meaning of the different parameters is unclear at best, but I'm not sure changes like this are a good idea. It's very difficult to assess the impact of this, I think.

I think we need a new run* function that properly supports the different use cases, like:

  • just run a shell command, raise an error if it fails (based on exit code) -- default
  • run a shell command, return output (stderr+stdout combined, or optionally split) and/or exit code

Logging behavior should probably always be the same (always log the output + exit code, no matter the use case?).

We can start slow, by implementing a new run* function that only supports the most common use case (or whichever one you have a need for), and gradually extend it's capabilities. Once we have a fully fleshed out new shiny run* implementation, we can deprecate run_cmd (and run_cmd_qa command) and make sure we use the new run* everywhere, both in framework itself and in easyblocks (that's perhaps a change to only make in EasyBuild v5.0, to avoid surprises).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that a rewrite is overdue, but this is IMO a bugfix. See the description: In some places we expect that with log_ok set to False this will NOT raise an Exception.

The lengthy comment serves as a guidance for the future run-function

@boegel boegel added the change label Aug 23, 2022
@boegel boegel added this to the 4.x milestone Aug 23, 2022
@Flamefire Flamefire force-pushed the fix-run_cmd branch 3 times, most recently from 250af4c to a444e34 Compare May 12, 2023 07:21
Don't raise an error when `log_ok=False` is passed, i.e. the caller
wants to handle the error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants