summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosip Sokcevic <sokcevic@chromium.org>2024-03-14 23:50:33 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-03-15 19:26:10 +0000
commita3a73726129f7aa9cc12bbdc1f01700189936284 (patch)
treea1fe5d9c56397232a4be4df876e446906310254d
parentfff1d2d74c2078b62cc9c2561330e41a842dc197 (diff)
downloadgit-repo-a3a73726129f7aa9cc12bbdc1f01700189936284.tar.gz
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>
-rwxr-xr-xmain.py2
-rw-r--r--project.py4
2 files changed, 3 insertions, 3 deletions
diff --git a/main.py b/main.py
index 2e1058d4..b00aadbd 100755
--- a/main.py
+++ b/main.py
@@ -425,7 +425,7 @@ class _Repo:
425 error_info = json.dumps( 425 error_info = json.dumps(
426 { 426 {
427 "ErrorType": type(error).__name__, 427 "ErrorType": type(error).__name__,
428 "Project": project, 428 "Project": str(project),
429 "Message": str(error), 429 "Message": str(error),
430 } 430 }
431 ) 431 )
diff --git a/project.py b/project.py
index 2ba2b766..7d6b6cea 100644
--- a/project.py
+++ b/project.py
@@ -1813,11 +1813,11 @@ class Project:
1813 ) 1813 )
1814 else: 1814 else:
1815 msg = ( 1815 msg = (
1816 "error: %s: Cannot remove project: uncommitted" 1816 "error: %s: Cannot remove project: uncommitted "
1817 "changes are present.\n" % self.RelPath(local=False) 1817 "changes are present.\n" % self.RelPath(local=False)
1818 ) 1818 )
1819 logger.error(msg) 1819 logger.error(msg)
1820 raise DeleteDirtyWorktreeError(msg, project=self) 1820 raise DeleteDirtyWorktreeError(msg, project=self.name)
1821 1821
1822 if verbose: 1822 if verbose:
1823 print(f"{self.RelPath(local=False)}: Deleting obsolete checkout.") 1823 print(f"{self.RelPath(local=False)}: Deleting obsolete checkout.")