# Buggy code
def show_instance(name=None, instance_id=None, call=None, kwargs=None):
    """
    Show the details from EC2 concerning an AMI.

    Can be called as an action (which requires a name):

    .. code-block:: bash

        salt-cloud -a show_instance myinstance

    ...or as a function (which requires either a name or instance_id):

    .. code-block:: bash

        salt-cloud -f show_instance my-ec2 name=myinstance
        salt-cloud -f show_instance my-ec2 instance_id=i-d34db33f
    """
    if not name and call == "action":
        raise SaltCloudSystemExit("The show_instance action requires a name.")

    if call == "function":
        name = kwargs.get("name", None)
        instance_id = kwargs.get("instance_id", None)

    if not name and not instance_id:
        raise SaltCloudSystemExit(
            "The show_instance function requires either a name or an instance_id"
        )

    node = _get_node(name=name, instance_id=instance_id)
    salt.utils.cloud.cache_node(node, __active_provider_name__, __opts__)
    return node


# Traceback (KeyError)
# salt-call --local cloud.has_instance jmoney-git-ec2-amazon-6
[INFO    ] Starting new HTTPS connection (1): api.digitalocean.com
[INFO    ] Starting new HTTPS connection (1): ec2.us-east-1.amazonaws.com
[INFO    ] Starting new HTTPS connection (1): identity.api.rackspacecloud.com
[INFO    ] Starting new HTTPS connection (1): ec2.us-east-1.amazonaws.com
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
KeyError: 'name'
Traceback (most recent call last):
File "/usr/local/bin/salt-call", line 6, in <module>
exec(compile(open(__file__).read(), __file__, 'exec'))
File "/root/salt/scripts/salt-call", line 11, in <module>
salt_call()
File "/root/salt/salt/scripts.py", line 341, in salt_call
client.run()
File "/root/salt/salt/cli/call.py", line 53, in run
caller.run()
File "/root/salt/salt/cli/caller.py", line 133, in run
ret = self.call()
File "/root/salt/salt/cli/caller.py", line 196, in call
ret['return'] = func(*args, **kwargs)
File "/root/salt/salt/modules/cloud.py", line 149, in has_instance
data = get_instance(name, provider)
File "/root/salt/salt/modules/cloud.py", line 175, in get_instance
data = action(fun='show_instance', names=[name], provider=provider)
File "/root/salt/salt/modules/cloud.py", line 234, in action
info = client.action(fun, cloudmap, names, provider, instance, kwargs)
File "/root/salt/salt/cloud/__init__.py", line 482, in action
return mapper.do_action(names, kwargs)
File "/root/salt/salt/cloud/__init__.py", line 1511, in do_action
vm_name, call='action'
File "/root/salt/salt/cloud/clouds/ec2.py", line 3171, in show_instance
salt.utils.cloud.cache_node(node, __active_provider_name__, __opts__)
File "/root/salt/salt/utils/cloud.py", line 2821, in cache_node
path = os.path.join(prov_dir, '{0}.p'.format(node['name']))
KeyError: 'name'

# Fixed code
def show_instance(name=None, instance_id=None, call=None, kwargs=None):
    """
    Show the details from EC2 concerning an AMI.

    Can be called as an action (which requires a name):

    .. code-block:: bash

        salt-cloud -a show_instance myinstance

    ...or as a function (which requires either a name or instance_id):

    .. code-block:: bash

        salt-cloud -f show_instance my-ec2 name=myinstance
        salt-cloud -f show_instance my-ec2 instance_id=i-d34db33f
    """
    if not name and call == "action":
        raise SaltCloudSystemExit("The show_instance action requires a name.")

    if call == "function":
        name = kwargs.get("name", None)
        instance_id = kwargs.get("instance_id", None)

    if not name and not instance_id:
        raise SaltCloudSystemExit(
            "The show_instance function requires either a name or an instance_id"
        )

    node = _get_node(name=name, instance_id=instance_id)
    for name in node:
        salt.utils.cloud.cache_node(node[name], __active_provider_name__, __opts__)
    return node