# Buggy code
def __init__(self, hs):
    """
    Args:
        hs (synapse.server.HomeServer): homeserver
    """
    Resource.__init__(self)

    self.hs = hs
    self.store = hs.get_datastore()
    self.registration_handler = hs.get_handlers().registration_handler

    # this is required by the request_handler wrapper
    self.clock = hs.get_clock()

    self._default_consent_version = hs.config.user_consent_version
    if self._default_consent_version is None:
        raise ConfigError(
            "Consent resource is enabled but user_consent section is "
            "missing in config file.",
        )

    # daemonize changes the cwd to /, so make the path absolute now.
    consent_template_directory = path.abspath(
        hs.config.user_consent_template_dir,
    )
    if not path.isdir(consent_template_directory):
        raise ConfigError(
            "Could not find template directory '%s'" % (consent_template_directory,),
        )

    loader = jinja2.FileSystemLoader(consent_template_directory)
    self._jinja_env = jinja2.Environment(
        loader=loader,
        autoescape=jinja2.select_autoescape(["html", "htm", "xml"]),
    )

    if hs.config.form_secret is None:
        raise ConfigError(
            "Consent resource is enabled but form_secret is not set in "
            "config file. It should be set to an arbitrary secret string.",
        )

    self._hmac_secret = hs.config.form_secret.encode("utf-8")


# Traceback (ConfigError)
2019-01-28 21:17:00,100 - twisted - 242 - ERROR -  - Traceback (most recent call last):
2019-01-28 21:17:00,101 - twisted - 242 - ERROR -  -   File "/home/matrix/.synapse/lib/python2.7/site-packages/synapse/app/homeserver.py", line 394, in start
2019-01-28 21:17:00,101 - twisted - 242 - ERROR -  -     hs.start_listening()
2019-01-28 21:17:00,101 - twisted - 242 - ERROR -  -   File "/home/matrix/.synapse/lib/python2.7/site-packages/synapse/app/homeserver.py", line 245, in start_listening
2019-01-28 21:17:00,101 - twisted - 242 - ERROR -  -     self._listener_http(config, listener)
2019-01-28 21:17:00,102 - twisted - 242 - ERROR -  -   File "/home/matrix/.synapse/lib/python2.7/site-packages/synapse/app/homeserver.py", line 101, in _listener_http
2019-01-28 21:17:00,102 - twisted - 242 - ERROR -  -     name, res.get("compress", False),
2019-01-28 21:17:00,102 - twisted - 242 - ERROR -  -   File "/home/matrix/.synapse/lib/python2.7/site-packages/synapse/app/homeserver.py", line 183, in _configure_named_resource
2019-01-28 21:17:00,102 - twisted - 242 - ERROR -  -     consent_resource = ConsentResource(self)
2019-01-28 21:17:00,102 - twisted - 242 - ERROR -  -   File "/home/matrix/.synapse/local/lib/python2.7/site-packages/synapse/rest/consent/consent_resource.py", line 111, in __init__
2019-01-28 21:17:00,103 - twisted - 242 - ERROR -  -     consent_template_directory,
2019-01-28 21:17:00,103 - twisted - 242 - ERROR -  - ConfigError: Could not find template directory '/res/templates/privacy'
2019-01-28 21:17:00,104 - synapse.handlers.deactivate_account - 144 - INFO - user_parter_loop-0 - User parter finished: stopping
2019-01-28 21:17:00,111 - synapse.metrics - 374 - INFO -  - Collecting gc 0
2019-01-28 21:17:00,144 - twisted - 242 - CRITICAL -  - Unhandled error in Deferred:
2019-01-28 21:17:00,145 - twisted - 242 - CRITICAL -  -
Traceback (most recent call last):
File "/home/matrix/.synapse/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "/home/matrix/.synapse/lib/python2.7/site-packages/synapse/app/homeserver.py", line 407, in start
sys.exit(1)
SystemExit: 1

# Fixed code
def __init__(self, hs):
    """
    Args:
        hs (synapse.server.HomeServer): homeserver
    """
    Resource.__init__(self)

    self.hs = hs
    self.store = hs.get_datastore()
    self.registration_handler = hs.get_handlers().registration_handler

    # this is required by the request_handler wrapper
    self.clock = hs.get_clock()

    self._default_consent_version = hs.config.user_consent_version
    if self._default_consent_version is None:
        raise ConfigError(
            "Consent resource is enabled but user_consent section is "
            "missing in config file.",
        )

    consent_template_directory = hs.config.user_consent_template_dir

    loader = jinja2.FileSystemLoader(consent_template_directory)
    self._jinja_env = jinja2.Environment(
        loader=loader,
        autoescape=jinja2.select_autoescape(["html", "htm", "xml"]),
    )

    if hs.config.form_secret is None:
        raise ConfigError(
            "Consent resource is enabled but form_secret is not set in "
            "config file. It should be set to an arbitrary secret string.",
        )

    self._hmac_secret = hs.config.form_secret.encode("utf-8")