Hi,
I'm having trouble understanding the recommended way to handle errors from Git when using the Porcelain API. I'm reading the documentation at [1] for reference.
During clone, push, and other operations how is the caller supposed to handle errors in the Git layer? For an example, consider the following code for pushing to a remote.
try:
porcelain.push(
repo=repo_path,
remote_location="fork",
refspecs=bytes(f"HEAD:refs/heads/{branch}", "utf-8"),
)
logger.info("github push done")
except Exception as e:
logger.error("error while pushing changes to remote", err=e)
return False
else:
return True
Now this wouldn't do the trick since porcelain.push() doesn't throw an error if for example, push fails in Git because of an auth issue.
I played around with the `errstream` argument, however other than acting as the stderr, it doesn't provide any definitive method to detect if the push operation failed. I could attach a file handler to `errstream` and afterwards detect if the words "Push of * failed" is in that file, however I feel that approach could be really brittle.
Have I gone down the wrong path here and is there a better way to handle errors in this scenario?
I'm guessing if we raise an Error at [2] like we do at [3], this could be solved. Is there a reason for not raising an error at [2]?
Also, another way to tackle this would be to return a list of errors from push() method, so that the caller can decide how to act.
Thanks!