summary refs log tree commit diff
path: root/synapse/config/key.py
diff options
context:
space:
mode:
authorRichard van der Hoff <github@rvanderhoff.org.uk>2017-10-17 14:46:17 +0100
committerGitHub <noreply@github.com>2017-10-17 14:46:17 +0100
commit7216c76654bbb57bc0ebc27498de7eda247f8ffb (patch)
treed8eab4dc12de21a062b67c9bbd5fa54fc6de223c /synapse/config/key.py
parentMerge pull request #2546 from matrix-org/rav/remove_dead_event_injector (diff)
downloadsynapse-7216c76654bbb57bc0ebc27498de7eda247f8ffb.tar.xz
Improve error handling for missing files (#2551)
`os.path.exists` doesn't allow us to distinguish between permissions errors and
the path actually not existing, which repeatedly confuses people. It also means
that we try to overwrite existing key files, which is super-confusing. (cf
issues #2455, #2379). Use os.stat instead.

Also, don't recomemnd the the use of --generate-config, which screws everything
up if you're using debian (cf #2455).

Diffstat (limited to 'synapse/config/key.py')
-rw-r--r--synapse/config/key.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/synapse/config/key.py b/synapse/config/key.py
index 6ee643793e..4b8fc063d0 100644
--- a/synapse/config/key.py
+++ b/synapse/config/key.py
@@ -118,10 +118,9 @@ class KeyConfig(Config):
         signing_keys = self.read_file(signing_key_path, "signing_key")
         try:
             return read_signing_keys(signing_keys.splitlines(True))
-        except Exception:
+        except Exception as e:
             raise ConfigError(
-                "Error reading signing_key."
-                " Try running again with --generate-config"
+                "Error reading signing_key: %s" % (str(e))
             )
 
     def read_old_signing_keys(self, old_signing_keys):
@@ -141,7 +140,8 @@ class KeyConfig(Config):
 
     def generate_files(self, config):
         signing_key_path = config["signing_key_path"]
-        if not os.path.exists(signing_key_path):
+
+        if not self.path_exists(signing_key_path):
             with open(signing_key_path, "w") as signing_key_file:
                 key_id = "a_" + random_string(4)
                 write_signing_keys(