release-depot / git_wrapper

A python based wrapper around GitPython
MIT License
4 stars 8 forks source link

Describe specific exceptions. #26

Open fuzzball81 opened 6 years ago

fuzzball81 commented 6 years ago

Add git describe specific exceptions, extracting details for the failure from GitPython

Description

If there is a failure during a git describe operation a return code of 128 is always used and all the details are included in failure text. Instead of using a general exception, add a more specific describe exception and extract the failure text for GitPython and add it to the exception.

It may be a good idea to have several types of exceptions based on the common failure modes for more granular error handling but that can be another enhancement in the future.

jpichon commented 6 years ago

The specific failure message should already be available in the generic describe exception added with PR23 (sorry for the confusion!).

An issue with simply using the failure text to determine a specific exception is that the message comes from git and can be localised. For example, calling with a bad hash:

$ git describe kfoejoe
fatal: Not a valid object name kfoejoe
$ git describe ifihe
fatal: ifihe n'est pas un nom d'objet valide

So we may have to figure out what caused the most common errors by other means.