git_deploy: improve refresh error handling
Save repo state if an exception is raised during a refresh attempt. Add additional repo warnings with for better descriptions regarding repo issues. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
aadff0d54e
commit
119f579a44
|
@ -48,22 +48,27 @@ class GitDeploy(AppDeploy):
|
|||
async def initialize(self) -> Dict[str, Any]:
|
||||
storage = await super().initialize()
|
||||
await self.repo.restore_state(storage)
|
||||
self._is_valid = self.repo.is_valid()
|
||||
self._is_valid = storage["is_valid"]
|
||||
if not self.needs_refresh():
|
||||
self.repo.log_repo_info()
|
||||
return storage
|
||||
|
||||
async def refresh(self) -> None:
|
||||
try:
|
||||
await self._update_repo_state()
|
||||
except Exception:
|
||||
logging.exception("Error Refreshing git state")
|
||||
await self._update_repo_state(raise_exc=False)
|
||||
|
||||
async def _update_repo_state(self, need_fetch: bool = True) -> None:
|
||||
async def _update_repo_state(
|
||||
self, need_fetch: bool = True, raise_exc: bool = True
|
||||
) -> None:
|
||||
self._is_valid = False
|
||||
try:
|
||||
await self.repo.refresh_repo_state(need_fetch=need_fetch)
|
||||
self.log_info(f"Channel: {self.channel}")
|
||||
except Exception as e:
|
||||
if raise_exc or isinstance(e, asyncio.CancelledError):
|
||||
raise
|
||||
else:
|
||||
self._is_valid = self.repo.is_valid()
|
||||
finally:
|
||||
self.log_info(f"Channel: {self.channel}")
|
||||
if not self._is_valid:
|
||||
self.log_info("Repo validation check failed, updates disabled")
|
||||
else:
|
||||
|
@ -371,6 +376,7 @@ class GitRepo:
|
|||
self._check_warnings()
|
||||
except Exception:
|
||||
logging.exception(f"Git Repo {self.alias}: Initialization failure")
|
||||
self._check_warnings()
|
||||
raise
|
||||
else:
|
||||
self.initialized = True
|
||||
|
@ -671,6 +677,12 @@ class GitRepo:
|
|||
self.repo_anomalies.clear()
|
||||
if self.repo_corrupt:
|
||||
self.repo_warnings.append("Repo is corrupt")
|
||||
if self.git_branch == "?":
|
||||
self.repo_warnings.append("Failed to detect git branch")
|
||||
elif self.git_remote == "?":
|
||||
self.repo_warnings.append(
|
||||
f"Failed to detect tracking remote for branch {self.git_branch}"
|
||||
)
|
||||
if self.upstream_url == "?":
|
||||
self.repo_warnings.append("Failed to detect repo url")
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue