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

feat: inherit CommandError (also) from subprocess.CalledProcessError #50

Closed
wants to merge 1 commit into from

Conversation

mih
Copy link
Member

@mih mih commented Oct 1, 2024

In the DataLad world CommandError was traditionally a RuntimeError. Whether or not that makes sense in the general case, one can have different opinions about.

The rest of the world is using subprocess.CalledProcessError. This exception type is very similar to CommandError in the properties that it can capture. It is only missing the CWD info, and the context message that comes with RuntimeError (see class docs).

This change connects the two worlds, by inheriting from both RuntimeError and CalledProcessError, and using the properties of both, where possible.

The behavior of CommandError remains unchanged, but it will now also work with code that expects a subprocess exception.

In the DataLad world `CommandError` was traditionally a `RuntimeError`.
Whether or not that makes sense in the general case, one can have
different opinions about.

The rest of the world is using `subprocess.CalledProcessError`. This
exception type is very similar to `CommandError` in the properties
that it can capture. It is only missing the CWD info, and the
context message that comes with `RuntimeError` (see class docs).

This change connects the two worlds, by inheriting from both
`RuntimeError` and `CalledProcessError`, and using the properties
of both, where possible.

The behavior of `CommandError` remains unchanged, but it will now also
work with code that expects a `subprocess` exception.
Copy link

codeclimate bot commented Oct 1, 2024

Code Climate has analyzed commit f167ef7 and detected 0 issues on this pull request.

View more on Code Climate.

@mih
Copy link
Member Author

mih commented Oct 1, 2024

I am closing this again, because it cannot be done cleanly.

The reason is that CommandError accepts a returncode=None, whereas CalledProcessError wants an int (for good reasons).

We could select a magic int value and make it be "undetermined/unknown", but without a good reason, I think it is best to just not do it at all.

@mih mih closed this Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant