We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Annotations: handling exceptions
When writing custom annotation, user should be able to access exceptions, that it's raising, to debug his function. Currently all that he gets is the information that something went wrong, e. g.

```
[WARNING][14:09:44] The bear ClangComplexityBear cannot be executed. Unable to convert parameter 'max_complexity' into type <function func at 0x7fa1b4d12d90>
```

This can be pretty easy fixed, by specifying exception [here](https://github.com/coala-analyzer/coala/blob/master/coalib/settings/FunctionMetadata.py#L105) and specifying in the docs what exception should annotations be allowed to raise.

This is related to https://github.com/coala-analyzer/coala/issues/1219 discussion. I think, maybe we need to figure out a better way to use exceptions so that there will be no need in catching broad ones, because they can hide bugs or other useful information.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `coalib/settings/FunctionMetadata.py`
Content:
```
1 from collections import OrderedDict
2 from copy import copy
3 from inspect import getfullargspec, ismethod
4 
5 from coalib.settings.DocumentationComment import DocumentationComment
6 
7 
8 class FunctionMetadata:
9     str_nodesc = "No description given."
10     str_optional = "Optional, defaults to '{}'."
11 
12     def __init__(self,
13                  name,
14                  desc="",
15                  retval_desc="",
16                  non_optional_params=None,
17                  optional_params=None,
18                  omit=frozenset()):
19         """
20         Creates the FunctionMetadata object.
21 
22         :param name:                The name of the function.
23         :param desc:                The description of the function.
24         :param retval_desc:         The retval description of the function.
25         :param non_optional_params: A dict containing the name of non optional
26                                     parameters as the key and a tuple of a
27                                     description and the python annotation. To
28                                     preserve the order, use OrderedDict.
29         :param optional_params:     A dict containing the name of optional
30                                     parameters as the key and a tuple
31                                     of a description, the python annotation and
32                                     the default value. To preserve the order,
33                                     use OrderedDict.
34         :param omit:                A set of parameters to omit.
35         """
36         if non_optional_params is None:
37             non_optional_params = OrderedDict()
38         if optional_params is None:
39             optional_params = OrderedDict()
40 
41         self.name = name
42         self.desc = desc
43         self.retval_desc = retval_desc
44         self._non_optional_params = non_optional_params
45         self._optional_params = optional_params
46         self.omit = set(omit)
47 
48     def _filter_out_omitted(self, params):
49         """
50         Filters out parameters that are to omit. This is a helper method for
51         the param related properties.
52 
53         :param params: The parameter dictionary to filter.
54         :return:       The filtered dictionary.
55         """
56         return OrderedDict(filter(lambda p: p[0] not in self.omit,
57                                   tuple(params.items())))
58 
59     @property
60     def non_optional_params(self):
61         """
62         Retrieves a dict containing the name of non optional parameters as the
63         key and a tuple of a description and the python annotation. Values that
64         are present in self.omit will be omitted.
65         """
66         return self._filter_out_omitted(self._non_optional_params)
67 
68     @property
69     def optional_params(self):
70         """
71         Retrieves a dict containing the name of optional parameters as the key
72         and a tuple of a description, the python annotation and the default
73         value. Values that are present in self.omit will be omitted.
74         """
75         return self._filter_out_omitted(self._optional_params)
76 
77     def create_params_from_section(self, section):
78         """
79         Create a params dictionary for this function that holds all values the
80         function needs plus optional ones that are available.
81 
82         :param section:    The section to retrieve the values from.
83         :return:           The params dictionary.
84         """
85         params = {}
86 
87         for param in self.non_optional_params:
88             _, annotation = self.non_optional_params[param]
89             params[param] = self._get_param(param, section, annotation)
90 
91         for param in self.optional_params:
92             if param in section:
93                 _, annotation, _ = self.optional_params[param]
94                 params[param] = self._get_param(param, section, annotation)
95 
96         return params
97 
98     @staticmethod
99     def _get_param(param, section, annotation):
100         if annotation is None:
101             annotation = lambda x: x
102 
103         try:
104             return annotation(section[param])
105         except:
106             raise ValueError("Unable to convert parameter {} into type "
107                              "{}.".format(repr(param), annotation))
108 
109     @classmethod
110     def from_function(cls, func, omit=frozenset()):
111         """
112         Creates a FunctionMetadata object from a function. Please note that any
113         variable argument lists are not supported. If you do not want the
114         first (usual named 'self') argument to appear please pass the method of
115         an actual INSTANCE of a class; passing the method of the class isn't
116         enough. Alternatively you can add "self" to the omit set.
117 
118         :param func: The function. If __metadata__ of the unbound function is
119                      present it will be copied and used, otherwise it will be
120                      generated.
121         :param omit: A set of parameter names that are to be ignored.
122         :return:     The FunctionMetadata object corresponding to the given
123                      function.
124         """
125         if hasattr(func, "__metadata__"):
126             metadata = copy(func.__metadata__)
127             metadata.omit = omit
128             return metadata
129 
130         doc = func.__doc__ or ""
131         doc_comment = DocumentationComment.from_docstring(doc)
132 
133         non_optional_params = OrderedDict()
134         optional_params = OrderedDict()
135 
136         argspec = getfullargspec(func)
137         args = argspec.args or ()
138         defaults = argspec.defaults or ()
139         num_non_defaults = len(args) - len(defaults)
140         for i, arg in enumerate(args):
141             # Implicit self argument or omitted explicitly
142             if i < 1 and ismethod(func):
143                 continue
144 
145             if i < num_non_defaults:
146                 non_optional_params[arg] = (
147                     doc_comment.param_dict.get(arg, cls.str_nodesc),
148                     argspec.annotations.get(arg, None))
149             else:
150                 optional_params[arg] = (
151                     doc_comment.param_dict.get(arg, cls.str_nodesc) + " (" +
152                     cls.str_optional.format(str(defaults[i-num_non_defaults]))
153                     + ")",
154                     argspec.annotations.get(arg, None),
155                     defaults[i-num_non_defaults])
156 
157         return cls(name=func.__name__,
158                    desc=doc_comment.desc,
159                    retval_desc=doc_comment.retval_desc,
160                    non_optional_params=non_optional_params,
161                    optional_params=optional_params,
162                    omit=omit)
163
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/coalib/settings/FunctionMetadata.py b/coalib/settings/FunctionMetadata.py
--- a/coalib/settings/FunctionMetadata.py
+++ b/coalib/settings/FunctionMetadata.py
@@ -102,7 +102,7 @@
 
         try:
             return annotation(section[param])
-        except:
+        except (TypeError, ValueError):
             raise ValueError("Unable to convert parameter {} into type "
                              "{}.".format(repr(param), annotation))

{"golden_diff": "diff --git a/coalib/settings/FunctionMetadata.py b/coalib/settings/FunctionMetadata.py\n--- a/coalib/settings/FunctionMetadata.py\n+++ b/coalib/settings/FunctionMetadata.py\n@@ -102,7 +102,7 @@\n \n         try:\n             return annotation(section[param])\n-        except:\n+        except (TypeError, ValueError):\n             raise ValueError(\"Unable to convert parameter {} into type \"\n                              \"{}.\".format(repr(param), annotation))\n", "issue": "Annotations: handling exceptions\nWhen writing custom annotation, user should be able to access exceptions, that it's raising, to debug his function. Currently all that he gets is the information that something went wrong, e. g.\n\n```\n[WARNING][14:09:44] The bear ClangComplexityBear cannot be executed. Unable to convert parameter 'max_complexity' into type <function func at 0x7fa1b4d12d90>\n```\n\nThis can be pretty easy fixed, by specifying exception [here](https://github.com/coala-analyzer/coala/blob/master/coalib/settings/FunctionMetadata.py#L105) and specifying in the docs what exception should annotations be allowed to raise.\n\nThis is related to https://github.com/coala-analyzer/coala/issues/1219 discussion. I think, maybe we need to figure out a better way to use exceptions so that there will be no need in catching broad ones, because they can hide bugs or other useful information.\n\n", "before_files": [{"content": "from collections import OrderedDict\nfrom copy import copy\nfrom inspect import getfullargspec, ismethod\n\nfrom coalib.settings.DocumentationComment import DocumentationComment\n\n\nclass FunctionMetadata:\n    str_nodesc = \"No description given.\"\n    str_optional = \"Optional, defaults to '{}'.\"\n\n    def __init__(self,\n                 name,\n                 desc=\"\",\n                 retval_desc=\"\",\n                 non_optional_params=None,\n                 optional_params=None,\n                 omit=frozenset()):\n        \"\"\"\n        Creates the FunctionMetadata object.\n\n        :param name:                The name of the function.\n        :param desc:                The description of the function.\n        :param retval_desc:         The retval description of the function.\n        :param non_optional_params: A dict containing the name of non optional\n                                    parameters as the key and a tuple of a\n                                    description and the python annotation. To\n                                    preserve the order, use OrderedDict.\n        :param optional_params:     A dict containing the name of optional\n                                    parameters as the key and a tuple\n                                    of a description, the python annotation and\n                                    the default value. To preserve the order,\n                                    use OrderedDict.\n        :param omit:                A set of parameters to omit.\n        \"\"\"\n        if non_optional_params is None:\n            non_optional_params = OrderedDict()\n        if optional_params is None:\n            optional_params = OrderedDict()\n\n        self.name = name\n        self.desc = desc\n        self.retval_desc = retval_desc\n        self._non_optional_params = non_optional_params\n        self._optional_params = optional_params\n        self.omit = set(omit)\n\n    def _filter_out_omitted(self, params):\n        \"\"\"\n        Filters out parameters that are to omit. This is a helper method for\n        the param related properties.\n\n        :param params: The parameter dictionary to filter.\n        :return:       The filtered dictionary.\n        \"\"\"\n        return OrderedDict(filter(lambda p: p[0] not in self.omit,\n                                  tuple(params.items())))\n\n    @property\n    def non_optional_params(self):\n        \"\"\"\n        Retrieves a dict containing the name of non optional parameters as the\n        key and a tuple of a description and the python annotation. Values that\n        are present in self.omit will be omitted.\n        \"\"\"\n        return self._filter_out_omitted(self._non_optional_params)\n\n    @property\n    def optional_params(self):\n        \"\"\"\n        Retrieves a dict containing the name of optional parameters as the key\n        and a tuple of a description, the python annotation and the default\n        value. Values that are present in self.omit will be omitted.\n        \"\"\"\n        return self._filter_out_omitted(self._optional_params)\n\n    def create_params_from_section(self, section):\n        \"\"\"\n        Create a params dictionary for this function that holds all values the\n        function needs plus optional ones that are available.\n\n        :param section:    The section to retrieve the values from.\n        :return:           The params dictionary.\n        \"\"\"\n        params = {}\n\n        for param in self.non_optional_params:\n            _, annotation = self.non_optional_params[param]\n            params[param] = self._get_param(param, section, annotation)\n\n        for param in self.optional_params:\n            if param in section:\n                _, annotation, _ = self.optional_params[param]\n                params[param] = self._get_param(param, section, annotation)\n\n        return params\n\n    @staticmethod\n    def _get_param(param, section, annotation):\n        if annotation is None:\n            annotation = lambda x: x\n\n        try:\n            return annotation(section[param])\n        except:\n            raise ValueError(\"Unable to convert parameter {} into type \"\n                             \"{}.\".format(repr(param), annotation))\n\n    @classmethod\n    def from_function(cls, func, omit=frozenset()):\n        \"\"\"\n        Creates a FunctionMetadata object from a function. Please note that any\n        variable argument lists are not supported. If you do not want the\n        first (usual named 'self') argument to appear please pass the method of\n        an actual INSTANCE of a class; passing the method of the class isn't\n        enough. Alternatively you can add \"self\" to the omit set.\n\n        :param func: The function. If __metadata__ of the unbound function is\n                     present it will be copied and used, otherwise it will be\n                     generated.\n        :param omit: A set of parameter names that are to be ignored.\n        :return:     The FunctionMetadata object corresponding to the given\n                     function.\n        \"\"\"\n        if hasattr(func, \"__metadata__\"):\n            metadata = copy(func.__metadata__)\n            metadata.omit = omit\n            return metadata\n\n        doc = func.__doc__ or \"\"\n        doc_comment = DocumentationComment.from_docstring(doc)\n\n        non_optional_params = OrderedDict()\n        optional_params = OrderedDict()\n\n        argspec = getfullargspec(func)\n        args = argspec.args or ()\n        defaults = argspec.defaults or ()\n        num_non_defaults = len(args) - len(defaults)\n        for i, arg in enumerate(args):\n            # Implicit self argument or omitted explicitly\n            if i < 1 and ismethod(func):\n                continue\n\n            if i < num_non_defaults:\n                non_optional_params[arg] = (\n                    doc_comment.param_dict.get(arg, cls.str_nodesc),\n                    argspec.annotations.get(arg, None))\n            else:\n                optional_params[arg] = (\n                    doc_comment.param_dict.get(arg, cls.str_nodesc) + \" (\" +\n                    cls.str_optional.format(str(defaults[i-num_non_defaults]))\n                    + \")\",\n                    argspec.annotations.get(arg, None),\n                    defaults[i-num_non_defaults])\n\n        return cls(name=func.__name__,\n                   desc=doc_comment.desc,\n                   retval_desc=doc_comment.retval_desc,\n                   non_optional_params=non_optional_params,\n                   optional_params=optional_params,\n                   omit=omit)\n", "path": "coalib/settings/FunctionMetadata.py"}], "after_files": [{"content": "from collections import OrderedDict\nfrom copy import copy\nfrom inspect import getfullargspec, ismethod\n\nfrom coalib.settings.DocumentationComment import DocumentationComment\n\n\nclass FunctionMetadata:\n    str_nodesc = \"No description given.\"\n    str_optional = \"Optional, defaults to '{}'.\"\n\n    def __init__(self,\n                 name,\n                 desc=\"\",\n                 retval_desc=\"\",\n                 non_optional_params=None,\n                 optional_params=None,\n                 omit=frozenset()):\n        \"\"\"\n        Creates the FunctionMetadata object.\n\n        :param name:                The name of the function.\n        :param desc:                The description of the function.\n        :param retval_desc:         The retval description of the function.\n        :param non_optional_params: A dict containing the name of non optional\n                                    parameters as the key and a tuple of a\n                                    description and the python annotation. To\n                                    preserve the order, use OrderedDict.\n        :param optional_params:     A dict containing the name of optional\n                                    parameters as the key and a tuple\n                                    of a description, the python annotation and\n                                    the default value. To preserve the order,\n                                    use OrderedDict.\n        :param omit:                A set of parameters to omit.\n        \"\"\"\n        if non_optional_params is None:\n            non_optional_params = OrderedDict()\n        if optional_params is None:\n            optional_params = OrderedDict()\n\n        self.name = name\n        self.desc = desc\n        self.retval_desc = retval_desc\n        self._non_optional_params = non_optional_params\n        self._optional_params = optional_params\n        self.omit = set(omit)\n\n    def _filter_out_omitted(self, params):\n        \"\"\"\n        Filters out parameters that are to omit. This is a helper method for\n        the param related properties.\n\n        :param params: The parameter dictionary to filter.\n        :return:       The filtered dictionary.\n        \"\"\"\n        return OrderedDict(filter(lambda p: p[0] not in self.omit,\n                                  tuple(params.items())))\n\n    @property\n    def non_optional_params(self):\n        \"\"\"\n        Retrieves a dict containing the name of non optional parameters as the\n        key and a tuple of a description and the python annotation. Values that\n        are present in self.omit will be omitted.\n        \"\"\"\n        return self._filter_out_omitted(self._non_optional_params)\n\n    @property\n    def optional_params(self):\n        \"\"\"\n        Retrieves a dict containing the name of optional parameters as the key\n        and a tuple of a description, the python annotation and the default\n        value. Values that are present in self.omit will be omitted.\n        \"\"\"\n        return self._filter_out_omitted(self._optional_params)\n\n    def create_params_from_section(self, section):\n        \"\"\"\n        Create a params dictionary for this function that holds all values the\n        function needs plus optional ones that are available.\n\n        :param section:    The section to retrieve the values from.\n        :return:           The params dictionary.\n        \"\"\"\n        params = {}\n\n        for param in self.non_optional_params:\n            _, annotation = self.non_optional_params[param]\n            params[param] = self._get_param(param, section, annotation)\n\n        for param in self.optional_params:\n            if param in section:\n                _, annotation, _ = self.optional_params[param]\n                params[param] = self._get_param(param, section, annotation)\n\n        return params\n\n    @staticmethod\n    def _get_param(param, section, annotation):\n        if annotation is None:\n            annotation = lambda x: x\n\n        try:\n            return annotation(section[param])\n        except (TypeError, ValueError):\n            raise ValueError(\"Unable to convert parameter {} into type \"\n                             \"{}.\".format(repr(param), annotation))\n\n    @classmethod\n    def from_function(cls, func, omit=frozenset()):\n        \"\"\"\n        Creates a FunctionMetadata object from a function. Please note that any\n        variable argument lists are not supported. If you do not want the\n        first (usual named 'self') argument to appear please pass the method of\n        an actual INSTANCE of a class; passing the method of the class isn't\n        enough. Alternatively you can add \"self\" to the omit set.\n\n        :param func: The function. If __metadata__ of the unbound function is\n                     present it will be copied and used, otherwise it will be\n                     generated.\n        :param omit: A set of parameter names that are to be ignored.\n        :return:     The FunctionMetadata object corresponding to the given\n                     function.\n        \"\"\"\n        if hasattr(func, \"__metadata__\"):\n            metadata = copy(func.__metadata__)\n            metadata.omit = omit\n            return metadata\n\n        doc = func.__doc__ or \"\"\n        doc_comment = DocumentationComment.from_docstring(doc)\n\n        non_optional_params = OrderedDict()\n        optional_params = OrderedDict()\n\n        argspec = getfullargspec(func)\n        args = argspec.args or ()\n        defaults = argspec.defaults or ()\n        num_non_defaults = len(args) - len(defaults)\n        for i, arg in enumerate(args):\n            # Implicit self argument or omitted explicitly\n            if i < 1 and ismethod(func):\n                continue\n\n            if i < num_non_defaults:\n                non_optional_params[arg] = (\n                    doc_comment.param_dict.get(arg, cls.str_nodesc),\n                    argspec.annotations.get(arg, None))\n            else:\n                optional_params[arg] = (\n                    doc_comment.param_dict.get(arg, cls.str_nodesc) + \" (\" +\n                    cls.str_optional.format(str(defaults[i-num_non_defaults]))\n                    + \")\",\n                    argspec.annotations.get(arg, None),\n                    defaults[i-num_non_defaults])\n\n        return cls(name=func.__name__,\n                   desc=doc_comment.desc,\n                   retval_desc=doc_comment.retval_desc,\n                   non_optional_params=non_optional_params,\n                   optional_params=optional_params,\n                   omit=omit)\n", "path": "coalib/settings/FunctionMetadata.py"}]}