From ba5f34a02e05880d3bc317fdb7e7276d2560a25a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 29 Oct 2019 18:22:32 +0000 Subject: [PATCH 1/2] Handle FileNotFound error in version checking using git --- synapse/util/versionstring.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/synapse/util/versionstring.py b/synapse/util/versionstring.py index fa404b9d7563..ab7d03af3a87 100644 --- a/synapse/util/versionstring.py +++ b/synapse/util/versionstring.py @@ -42,6 +42,7 @@ def get_version_string(module): try: null = open(os.devnull, "w") cwd = os.path.dirname(os.path.abspath(module.__file__)) + try: git_branch = ( subprocess.check_output( @@ -51,7 +52,8 @@ def get_version_string(module): .decode("ascii") ) git_branch = "b=" + git_branch - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, FileNotFoundError): + # FileNotFoundError can arise when git is not installed git_branch = "" try: @@ -63,7 +65,7 @@ def get_version_string(module): .decode("ascii") ) git_tag = "t=" + git_tag - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, FileNotFoundError): git_tag = "" try: @@ -74,7 +76,7 @@ def get_version_string(module): .strip() .decode("ascii") ) - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, FileNotFoundError): git_commit = "" try: @@ -89,7 +91,7 @@ def get_version_string(module): ) git_dirty = "dirty" if is_dirty else "" - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, FileNotFoundError): git_dirty = "" if git_branch or git_tag or git_commit or git_dirty: From 5af7de2d8377f8c684268dfaa8385bbaf7aa55c7 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 29 Oct 2019 18:27:38 +0000 Subject: [PATCH 2/2] Add changelog --- changelog.d/6284.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6284.bugfix diff --git a/changelog.d/6284.bugfix b/changelog.d/6284.bugfix new file mode 100644 index 000000000000..cf15053d2d61 --- /dev/null +++ b/changelog.d/6284.bugfix @@ -0,0 +1 @@ +Prevent errors from appearing on Synapse startup if `git` is not installed. \ No newline at end of file