#372 Fix displaying error message if mbs-manager is missing/not installed
Merged by cqi. Opened by nphilipp.
nphilipp/rpkg master--mbs-manager-missing  into  master

Download 372.patch

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.

What does it mean by #1 and #2 above?

Why Exception here instead of 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...

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?

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.

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.

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.

Context is important, it's really three tests:

  • does it wrap an exception?
  • does the wrapped exception have an .errno member and…
  • …is it ENOENT?

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.

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

Metadata