We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Issue on calling action-alias match in CLI
calling 
`st2 action-alias match "st2 pack install" `
Gives the error
```
2016-11-30 04:02:38,984 140340458909360 INFO hooks [-] 25e7cbee-ec68-4040-9adc-f3f82f11774c -  POST /v1/actionalias/match with filters={} (remote_addr='127.0.0.1',method='POST',filters={},request_id='25e7cbee-ec68-4040-9adc-f3f82f11774c',path='/v1/actionalias/match')
2016-11-30 04:02:38,985 140340458909360 AUDIT auth [-] Token provided in headers
2016-11-30 04:02:38,986 140340458909360 AUDIT auth [-] Token with id "583e4f54c4da5f27da3c32ea" is validated.
2016-11-30 04:02:38,990 140340458909360 WARNING base [-] Type definition for 'action_alias_match_api' argument of 'match' is missing.
2016-11-30 04:02:38,990 140340458909360 INFO resource [-] GET all /v1/actionalias/match with filters={'order_by': ['pack', 'name']} (offset=0,limit='None',filters={'order_by': ['pack', 'name']},sort=[])
2016-11-30 04:02:38,996 140340458909360 ERROR hooks [-] API call failed: 'representation'
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py", line 631, in __call__
    self.invoke_controller(controller, args, kwargs, state)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py", line 531, in invoke_controller
    result = controller(*args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/rbac/decorators.py", line 61, in func_wrapper
    return func(*args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/models/api/base.py", line 284, in callfunction
    raise e
KeyError: 'representation' (_exception_data={},_exception_class='KeyError',_exception_message="'representation'")
2016-11-30 04:02:38,997 140340458909360 ERROR hooks [-] Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py", line 631, in __call__
    self.invoke_controller(controller, args, kwargs, state)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py", line 531, in invoke_controller
    result = controller(*args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/rbac/decorators.py", line 61, in func_wrapper
    return func(*args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/models/api/base.py", line 284, in callfunction
    raise e
KeyError: 'representation'
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py", line 631, in __call__
    self.invoke_controller(controller, args, kwargs, state)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py", line 531, in invoke_controller
    result = controller(*args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/rbac/decorators.py", line 61, in func_wrapper
    return func(*args, **kwargs)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/models/api/base.py", line 284, in callfunction
    raise e
KeyError: 'representation'
2016-11-30 04:02:38,997 140340458909360 INFO hooks [-] 25e7cbee-ec68-4040-9adc-f3f82f11774c - POST /v1/actionalias/match result={
    "faultstring": "Internal Server Error"
} (result='{\n    "faultstring": "Internal Server Error"\n}',request_id='25e7cbee-ec68-4040-9adc-f3f82f11774c',status_code='500 Internal Server Error',remote_addr='127.0.0.1',path='/v1/actionalias/match',method='POST')
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `st2common/st2common/util/actionalias_matching.py`
Content:
```
1 # Licensed to the StackStorm, Inc ('StackStorm') under one or more
2 # contributor license agreements.  See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License.  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 import six
17 
18 from st2common.exceptions.content import ParseException
19 from st2common.models.utils.action_alias_utils import extract_parameters
20 
21 __all__ = [
22     'list_format_strings_from_aliases',
23     'normalise_alias_format_string',
24     'match_command_to_alias'
25 ]
26 
27 
28 def list_format_strings_from_aliases(aliases):
29     '''
30     List patterns from a collection of alias objects
31 
32     :param aliases: The list of aliases
33     :type  aliases: ``list`` of :class:`st2common.models.api.action.ActionAliasAPI`
34 
35     :return: A description of potential execution patterns in a list of aliases.
36     :rtype: ``list`` of ``list``
37     '''
38     patterns = []
39     for alias in aliases:
40         for format_ in alias.formats:
41             display, representations = normalise_alias_format_string(format_)
42             patterns.extend([(display, representation) for representation in representations])
43     return patterns
44 
45 
46 def normalise_alias_format_string(alias_format):
47     '''
48     StackStorm action aliases can have two types;
49         1. A simple string holding the format
50         2. A dictionary which hold numerous alias format "representation(s)"
51            With a single "display" for help about the action alias.
52     This function processes both forms and returns a standardized form.
53 
54     :param alias_format: The alias format
55     :type  alias_format: ``str`` or ``dict``
56 
57     :return: The representation of the alias
58     :rtype: ``tuple`` of (``str``, ``str``)
59     '''
60     display = None
61     representation = []
62 
63     if isinstance(alias_format, six.string_types):
64         display = alias_format
65         representation.append(alias_format)
66     elif isinstance(alias_format, dict):
67         display = alias_format['display']
68         representation = alias_format['representation']
69     else:
70         raise TypeError("alias_format '%s' is neither a dictionary or string type."
71                         % repr(alias_format))
72     return (display, representation)
73 
74 
75 def match_command_to_alias(command, aliases):
76     """
77     Match the text against an action and return the action reference.
78     """
79     results = []
80 
81     for alias in aliases:
82         format_strings = list_format_strings_from_aliases([alias])
83         for format_string in format_strings:
84             try:
85                 extract_parameters(format_str=format_string[1],
86                                    param_stream=command)
87             except ParseException:
88                 continue
89 
90             results.append((alias, format_string[0], format_string[1]))
91     return results
92
```
--- 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/st2common/st2common/util/actionalias_matching.py b/st2common/st2common/util/actionalias_matching.py
--- a/st2common/st2common/util/actionalias_matching.py
+++ b/st2common/st2common/util/actionalias_matching.py
@@ -39,16 +39,20 @@
     for alias in aliases:
         for format_ in alias.formats:
             display, representations = normalise_alias_format_string(format_)
-            patterns.extend([(display, representation) for representation in representations])
+            if display and len(representations) == 0:
+                patterns.extend([(display, [])])
+            else:
+                patterns.extend([(display, representation) for representation in representations])
     return patterns
 
 
 def normalise_alias_format_string(alias_format):
     '''
-    StackStorm action aliases can have two types;
-        1. A simple string holding the format
-        2. A dictionary which hold numerous alias format "representation(s)"
-           With a single "display" for help about the action alias.
+    StackStorm action aliases come in two forms;
+        1. A string holding the format, which is also used as the help string.
+        2. A dictionary containing "display" and/or "representation" keys.
+           "representation": a list of numerous alias format "representation(s)"
+           "display": a help string to be displayed.
     This function processes both forms and returns a standardized form.
 
     :param alias_format: The alias format
@@ -64,8 +68,10 @@
         display = alias_format
         representation.append(alias_format)
     elif isinstance(alias_format, dict):
-        display = alias_format['display']
-        representation = alias_format['representation']
+        display = alias_format.get('display')
+        representation = alias_format.get('representation') or []
+        if isinstance(representation, six.string_types):
+            representation = [representation]
     else:
         raise TypeError("alias_format '%s' is neither a dictionary or string type."
                         % repr(alias_format))

{"golden_diff": "diff --git a/st2common/st2common/util/actionalias_matching.py b/st2common/st2common/util/actionalias_matching.py\n--- a/st2common/st2common/util/actionalias_matching.py\n+++ b/st2common/st2common/util/actionalias_matching.py\n@@ -39,16 +39,20 @@\n     for alias in aliases:\n         for format_ in alias.formats:\n             display, representations = normalise_alias_format_string(format_)\n-            patterns.extend([(display, representation) for representation in representations])\n+            if display and len(representations) == 0:\n+                patterns.extend([(display, [])])\n+            else:\n+                patterns.extend([(display, representation) for representation in representations])\n     return patterns\n \n \n def normalise_alias_format_string(alias_format):\n     '''\n-    StackStorm action aliases can have two types;\n-        1. A simple string holding the format\n-        2. A dictionary which hold numerous alias format \"representation(s)\"\n-           With a single \"display\" for help about the action alias.\n+    StackStorm action aliases come in two forms;\n+        1. A string holding the format, which is also used as the help string.\n+        2. A dictionary containing \"display\" and/or \"representation\" keys.\n+           \"representation\": a list of numerous alias format \"representation(s)\"\n+           \"display\": a help string to be displayed.\n     This function processes both forms and returns a standardized form.\n \n     :param alias_format: The alias format\n@@ -64,8 +68,10 @@\n         display = alias_format\n         representation.append(alias_format)\n     elif isinstance(alias_format, dict):\n-        display = alias_format['display']\n-        representation = alias_format['representation']\n+        display = alias_format.get('display')\n+        representation = alias_format.get('representation') or []\n+        if isinstance(representation, six.string_types):\n+            representation = [representation]\n     else:\n         raise TypeError(\"alias_format '%s' is neither a dictionary or string type.\"\n                         % repr(alias_format))\n", "issue": "Issue on calling action-alias match in CLI\ncalling \r\n`st2 action-alias match \"st2 pack install\" `\r\nGives the error\r\n```\r\n2016-11-30 04:02:38,984 140340458909360 INFO hooks [-] 25e7cbee-ec68-4040-9adc-f3f82f11774c -  POST /v1/actionalias/match with filters={} (remote_addr='127.0.0.1',method='POST',filters={},request_id='25e7cbee-ec68-4040-9adc-f3f82f11774c',path='/v1/actionalias/match')\r\n2016-11-30 04:02:38,985 140340458909360 AUDIT auth [-] Token provided in headers\r\n2016-11-30 04:02:38,986 140340458909360 AUDIT auth [-] Token with id \"583e4f54c4da5f27da3c32ea\" is validated.\r\n2016-11-30 04:02:38,990 140340458909360 WARNING base [-] Type definition for 'action_alias_match_api' argument of 'match' is missing.\r\n2016-11-30 04:02:38,990 140340458909360 INFO resource [-] GET all /v1/actionalias/match with filters={'order_by': ['pack', 'name']} (offset=0,limit='None',filters={'order_by': ['pack', 'name']},sort=[])\r\n2016-11-30 04:02:38,996 140340458909360 ERROR hooks [-] API call failed: 'representation'\r\nTraceback (most recent call last):\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py\", line 631, in __call__\r\n    self.invoke_controller(controller, args, kwargs, state)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py\", line 531, in invoke_controller\r\n    result = controller(*args, **kwargs)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/rbac/decorators.py\", line 61, in func_wrapper\r\n    return func(*args, **kwargs)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/models/api/base.py\", line 284, in callfunction\r\n    raise e\r\nKeyError: 'representation' (_exception_data={},_exception_class='KeyError',_exception_message=\"'representation'\")\r\n2016-11-30 04:02:38,997 140340458909360 ERROR hooks [-] Traceback (most recent call last):\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py\", line 631, in __call__\r\n    self.invoke_controller(controller, args, kwargs, state)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py\", line 531, in invoke_controller\r\n    result = controller(*args, **kwargs)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/rbac/decorators.py\", line 61, in func_wrapper\r\n    return func(*args, **kwargs)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/models/api/base.py\", line 284, in callfunction\r\n    raise e\r\nKeyError: 'representation'\r\nTraceback (most recent call last):\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py\", line 631, in __call__\r\n    self.invoke_controller(controller, args, kwargs, state)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/pecan/core.py\", line 531, in invoke_controller\r\n    result = controller(*args, **kwargs)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/rbac/decorators.py\", line 61, in func_wrapper\r\n    return func(*args, **kwargs)\r\n  File \"/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/models/api/base.py\", line 284, in callfunction\r\n    raise e\r\nKeyError: 'representation'\r\n2016-11-30 04:02:38,997 140340458909360 INFO hooks [-] 25e7cbee-ec68-4040-9adc-f3f82f11774c - POST /v1/actionalias/match result={\r\n    \"faultstring\": \"Internal Server Error\"\r\n} (result='{\\n    \"faultstring\": \"Internal Server Error\"\\n}',request_id='25e7cbee-ec68-4040-9adc-f3f82f11774c',status_code='500 Internal Server Error',remote_addr='127.0.0.1',path='/v1/actionalias/match',method='POST')\r\n```\n", "before_files": [{"content": "# Licensed to the StackStorm, Inc ('StackStorm') under one or more\n# contributor license agreements.  See the NOTICE file distributed with\n# this work for additional information regarding copyright ownership.\n# The ASF licenses this file to You under the Apache License, Version 2.0\n# (the \"License\"); you may not use this file except in compliance with\n# the License.  You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport six\n\nfrom st2common.exceptions.content import ParseException\nfrom st2common.models.utils.action_alias_utils import extract_parameters\n\n__all__ = [\n    'list_format_strings_from_aliases',\n    'normalise_alias_format_string',\n    'match_command_to_alias'\n]\n\n\ndef list_format_strings_from_aliases(aliases):\n    '''\n    List patterns from a collection of alias objects\n\n    :param aliases: The list of aliases\n    :type  aliases: ``list`` of :class:`st2common.models.api.action.ActionAliasAPI`\n\n    :return: A description of potential execution patterns in a list of aliases.\n    :rtype: ``list`` of ``list``\n    '''\n    patterns = []\n    for alias in aliases:\n        for format_ in alias.formats:\n            display, representations = normalise_alias_format_string(format_)\n            patterns.extend([(display, representation) for representation in representations])\n    return patterns\n\n\ndef normalise_alias_format_string(alias_format):\n    '''\n    StackStorm action aliases can have two types;\n        1. A simple string holding the format\n        2. A dictionary which hold numerous alias format \"representation(s)\"\n           With a single \"display\" for help about the action alias.\n    This function processes both forms and returns a standardized form.\n\n    :param alias_format: The alias format\n    :type  alias_format: ``str`` or ``dict``\n\n    :return: The representation of the alias\n    :rtype: ``tuple`` of (``str``, ``str``)\n    '''\n    display = None\n    representation = []\n\n    if isinstance(alias_format, six.string_types):\n        display = alias_format\n        representation.append(alias_format)\n    elif isinstance(alias_format, dict):\n        display = alias_format['display']\n        representation = alias_format['representation']\n    else:\n        raise TypeError(\"alias_format '%s' is neither a dictionary or string type.\"\n                        % repr(alias_format))\n    return (display, representation)\n\n\ndef match_command_to_alias(command, aliases):\n    \"\"\"\n    Match the text against an action and return the action reference.\n    \"\"\"\n    results = []\n\n    for alias in aliases:\n        format_strings = list_format_strings_from_aliases([alias])\n        for format_string in format_strings:\n            try:\n                extract_parameters(format_str=format_string[1],\n                                   param_stream=command)\n            except ParseException:\n                continue\n\n            results.append((alias, format_string[0], format_string[1]))\n    return results\n", "path": "st2common/st2common/util/actionalias_matching.py"}], "after_files": [{"content": "# Licensed to the StackStorm, Inc ('StackStorm') under one or more\n# contributor license agreements.  See the NOTICE file distributed with\n# this work for additional information regarding copyright ownership.\n# The ASF licenses this file to You under the Apache License, Version 2.0\n# (the \"License\"); you may not use this file except in compliance with\n# the License.  You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport six\n\nfrom st2common.exceptions.content import ParseException\nfrom st2common.models.utils.action_alias_utils import extract_parameters\n\n__all__ = [\n    'list_format_strings_from_aliases',\n    'normalise_alias_format_string',\n    'match_command_to_alias'\n]\n\n\ndef list_format_strings_from_aliases(aliases):\n    '''\n    List patterns from a collection of alias objects\n\n    :param aliases: The list of aliases\n    :type  aliases: ``list`` of :class:`st2common.models.api.action.ActionAliasAPI`\n\n    :return: A description of potential execution patterns in a list of aliases.\n    :rtype: ``list`` of ``list``\n    '''\n    patterns = []\n    for alias in aliases:\n        for format_ in alias.formats:\n            display, representations = normalise_alias_format_string(format_)\n            if display and len(representations) == 0:\n                patterns.extend([(display, [])])\n            else:\n                patterns.extend([(display, representation) for representation in representations])\n    return patterns\n\n\ndef normalise_alias_format_string(alias_format):\n    '''\n    StackStorm action aliases come in two forms;\n        1. A string holding the format, which is also used as the help string.\n        2. A dictionary containing \"display\" and/or \"representation\" keys.\n           \"representation\": a list of numerous alias format \"representation(s)\"\n           \"display\": a help string to be displayed.\n    This function processes both forms and returns a standardized form.\n\n    :param alias_format: The alias format\n    :type  alias_format: ``str`` or ``dict``\n\n    :return: The representation of the alias\n    :rtype: ``tuple`` of (``str``, ``str``)\n    '''\n    display = None\n    representation = []\n\n    if isinstance(alias_format, six.string_types):\n        display = alias_format\n        representation.append(alias_format)\n    elif isinstance(alias_format, dict):\n        display = alias_format.get('display')\n        representation = alias_format.get('representation') or []\n        if isinstance(representation, six.string_types):\n            representation = [representation]\n    else:\n        raise TypeError(\"alias_format '%s' is neither a dictionary or string type.\"\n                        % repr(alias_format))\n    return (display, representation)\n\n\ndef match_command_to_alias(command, aliases):\n    \"\"\"\n    Match the text against an action and return the action reference.\n    \"\"\"\n    results = []\n\n    for alias in aliases:\n        format_strings = list_format_strings_from_aliases([alias])\n        for format_string in format_strings:\n            try:\n                extract_parameters(format_str=format_string[1],\n                                   param_stream=command)\n            except ParseException:\n                continue\n\n            results.append((alias, format_string[0], format_string[1]))\n    return results\n", "path": "st2common/st2common/util/actionalias_matching.py"}]}