main: Stringify project name in error_info

If a project can't be removed from checkout due to uncommitted changes
present, error.project is type of Project and not a string (as it is in
some cases). Project is not JSON serializable, resulting in exception
within exception handler:

TypeError: Object of type Project is not JSON serializable

This change casts project to string as a defensive mechanism. It also
passes project name instead of project object.

Change-Id: Ie7b782d73dc3647975755d5a3774d16ea6cd5348
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/413877
Tested-by: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
Josip Sokcevic 2024-03-14 23:50:33 +00:00 committed by LUCI
parent fff1d2d74c
commit a3a7372612
2 changed files with 3 additions and 3 deletions

View File

@ -425,7 +425,7 @@ class _Repo:
error_info = json.dumps(
{
"ErrorType": type(error).__name__,
"Project": project,
"Project": str(project),
"Message": str(error),
}
)

View File

@ -1813,11 +1813,11 @@ class Project:
)
else:
msg = (
"error: %s: Cannot remove project: uncommitted"
"error: %s: Cannot remove project: uncommitted "
"changes are present.\n" % self.RelPath(local=False)
)
logger.error(msg)
raise DeleteDirtyWorktreeError(msg, project=self)
raise DeleteDirtyWorktreeError(msg, project=self.name)
if verbose:
print(f"{self.RelPath(local=False)}: Deleting obsolete checkout.")