summary refs log tree commit diff
path: root/synapse/config/_base.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-09-02 10:48:05 +0100
committerMark Haines <mark.haines@matrix.org>2014-09-02 10:49:11 +0100
commitd45f89c95b0f61c6b850f73807e9b264796e08a2 (patch)
tree8e30d4bdac4c9c8b4627087a807af8def37f6841 /synapse/config/_base.py
parentYet more bullet points on various sections. (diff)
downloadsynapse-d45f89c95b0f61c6b850f73807e9b264796e08a2.tar.xz
More helpful error messages for missing config
Diffstat (limited to '')
-rw-r--r--synapse/config/_base.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/synapse/config/_base.py b/synapse/config/_base.py
index 08de6ee5ec..91c0229d81 100644
--- a/synapse/config/_base.py
+++ b/synapse/config/_base.py
@@ -21,6 +21,10 @@ import os
 import yaml
 
 
+class ConfigError(Exception):
+    pass
+
+
 class Config(object):
     def __init__(self, args):
         pass
@@ -29,8 +33,25 @@ class Config(object):
     def abspath(file_path):
         return os.path.abspath(file_path) if file_path else file_path
 
-    @staticmethod
-    def read_file(file_path):
+    @classmethod
+    def check_file(cls, file_path, config_name):
+        if file_path is None:
+            raise ConfigError(
+                "Missing config for %s."
+                " Try running again with --generate-config"
+                % (config_name,)
+            )
+        if not os.path.exists(file_path):
+            raise ConfigError(
+                "File % config for %s doesn't exist."
+                " Try running again with --generate-config"
+                % (config_name,)
+            )
+        return cls.abspath(file_path)
+
+    @classmethod
+    def read_file(cls, file_path, config_name):
+        cls.check_file(file_path, config_name)
         with open(file_path) as file_stream:
             return file_stream.read()