Testing only for the error message string is unreliable, these patches introduce checking if the rpkgError wraps an exception carrying an errno that is ENOENT.
rpkgError
errno
ENOENT
What does it mean by #1 and #2 above?
Why Exception here instead of OSError?
Exception
OSError
To make it compatible with both Python 2 and 3:
In [1]: issubclass(IOError, OSError) Out[1]: False
It's just to be able to distinguish the the tests in the output, every doc string longer than here will be cut off.
Test #1 is for the the case where the exception converted to a string matches, #2 will check if the rpkgError wraps an exception with .errno == ENOENT. I don't know how to phrase this so it fits...
.errno == ENOENT
I see. Why not isinstance(e.args[0], (IOError, OSError))? In Python 3, is mbs-manager does not exist, FileNotFoundError is raised, which is subclass of OSError. Is my understand correct?
isinstance(e.args[0], (IOError, OSError))
mbs-manager
FileNotFoundError
I'm thinking isinstance(e.args[0], Exception) is too general to tell the problem it tries to solve, unless it's commented out that is for Python 2 and 3 compatibility and why it can solve that.
isinstance(e.args[0], Exception)
I see.
Why not isinstance(e.args[0], (IOError, OSError))?
Because we're really not interested in the exact type of the wrapped Python exception, this is 'duck-typing', as in "if it walks like a duck and quacks like a duck it must be a duck", i.e. if it has an .errno member and it's set to ENOENT then the file doesn't exist. There's no advantage in checking for the more specific IOError and OSError here.
.errno
IOError
Context is important, it's really three tests:
I don't think this needs further commentary, errno == ENOENT is a well known error condition on a Linux operating system that shouldn't need further explanation.
errno == ENOENT
Looks good to me.
You know what, even though an explanation shouldn't be strictly necessary here it certainly can't hurt to have one. I'll add it and rebase my PR onto current master.
rebased onto 36dc58bf3501990d9ffa12f2bccfdd83b889c140
4 new commits added
explain mbs-manager exception handling
test for missing mbs-manager with errno set
add missing method docstring
catch errno == ENOENT if mbs-manager is missing
Thank you very much. Merging.
Pull-Request has been merged by cqi
Testing only for the error message string is unreliable, these patches introduce checking if the
rpkgErrorwraps an exception carrying anerrnothat isENOENT.