# Buggy code
def register_user(self, localpart, displayname=None, emails=[]):
    """Registers a new user with given localpart and optional displayname, emails.

    Args:
        localpart (str): The localpart of the new user.
        displayname (str|None): The displayname of the new user.
        emails (List[str]): Emails to bind to the new user.

    Raises:
        SynapseError if there is an error performing the registration. Check the
            'errcode' property for more information on the reason for failure

    Returns:
        Deferred[str]: user_id
    """
    return defer.ensureDeferred(
        self._hs.get_registration_handler().register_user(
            localpart=localpart,
            default_display_name=displayname,
            bind_emails=emails,
        )
    )


# Traceback (TypeError)
2020-06-11 21:42:52,523 - synapse.http.server - 113 - ERROR -  - Failed handle request via 'LoginRestServlet': <XForwardedForRequest at 0x7f89689119e8 method='POST' uri='/_matrix/client/r0/login' clientproto='HTTP/1.1' site=8008>
Traceback (most recent call last):
File "/app/code/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/app/code/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/app/code/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/app/code/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/app/code/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
StopIteration: @girish:cloudron.fun

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/app/code/env/lib/python3.6/site-packages/synapse/http/server.py", line 81, in wrapped_request_handler
await h(self, request)
File "/app/code/env/lib/python3.6/site-packages/synapse/http/server.py", line 350, in _async_render
callback_return = await callback_return
File "/app/code/env/lib/python3.6/site-packages/synapse/rest/client/v1/login.py", line 149, in on_POST
result = await self._do_other_login(login_submission)
File "/app/code/env/lib/python3.6/site-packages/synapse/rest/client/v1/login.py", line 264, in _do_other_login
identifier["user"], login_submission
File "/app/code/env/lib/python3.6/site-packages/synapse/handlers/auth.py", line 722, in validate_login
is_valid = await provider.check_password(qualified_user_id, password)
File "/app/code/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "/app/code/env/lib/python3.6/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "/app/code/env/lib/python3.6/site-packages/ldap_auth_provider.py", line 180, in check_password
user_id = yield self.register_user(localpart, givenName, mail)
File "/app/code/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "/app/code/env/lib/python3.6/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "/app/code/env/lib/python3.6/site-packages/ldap_auth_provider.py", line 291, in register_user
localpart=localpart, displayname=name, emails=emails,
File "/app/code/env/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
result = g.send(result)
File "/app/code/env/lib/python3.6/site-packages/synapse/module_api/__init__.py", line 113, in register
_, access_token = yield self.register_device(user_id)
TypeError: 'coroutine' object is not iterable

# Fixed code
def register_user(self, localpart, displayname=None, emails=[]):
    """Registers a new user with given localpart and optional displayname, emails.

    Args:
        localpart (str): The localpart of the new user.
        displayname (str|None): The displayname of the new user.
        emails (List[str]): Emails to bind to the new user.

    Raises:
        SynapseError if there is an error performing the registration. Check the
            'errcode' property for more information on the reason for failure

    Returns:
        defer.Deferred[str]: user_id
    """
    return defer.ensureDeferred(
        self._hs.get_registration_handler().register_user(
            localpart=localpart,
            default_display_name=displayname,
            bind_emails=emails,
        )
    )