# Buggy code
def flush(bank, key=None):
    """
    Remove the key from the cache bank with all the key content.
    """
    _init_client()
    if key is None:
        etcd_key = "{0}/{1}".format(path_prefix, bank)
    else:
        etcd_key = "{0}/{1}/{2}".format(path_prefix, bank, key)
    try:
        client.get(etcd_key)
    except etcd.EtcdKeyNotFound:
        return  # nothing to flush
    try:
        client.delete(etcd_key, recursive=True)
    except Exception as exc:
        raise SaltCacheError(
            "There was an error removing the key, {0}: {1}".format(etcd_key, exc)
        )


# Traceback (SaltCacheError)
salt-master[3903]: [ERROR   ] Error in function _mine:
salt-master[3903]: Traceback (most recent call last):
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1776, in run_func
salt-master[3903]:     ret = getattr(self, func)(load)
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1345, in _mine
salt-master[3903]:     return self.masterapi._mine(load, skip_verify=True)
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/daemons/masterapi.py", line 607, in _mine
salt-master[3903]:     data = self.cache.fetch(cbank, ckey)
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/cache/__init__.py", line 180, in fetch
salt-master[3903]:     return self.modules[fun](bank, key, **self._kwargs)
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/cache/etcd_cache.py", line 150, in fetch
salt-master[3903]:     etcd_key, exc
salt-master[3903]: SaltCacheError: There was an error reading the key, /salt_cache/minions/ca.aws-cc1.dev.xxx.yyy.com/mine: Key not found : /salt_cache/minions/ca.aws-cc1.dev.xxx.yyy.com/mine
salt-master[3903]: [ERROR   ] Error in function _mine_get:
salt-master[3903]: Traceback (most recent call last):
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1776, in run_func
salt-master[3903]:     ret = getattr(self, func)(load)
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/master.py", line 1331, in _mine_get
salt-master[3903]:     return self.masterapi._mine_get(load, skip_verify=True)
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/daemons/masterapi.py", line 589, in _mine_get
salt-master[3903]:     fdata = self.cache.fetch('minions/{0}'.format(minion), 'mine')
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/cache/__init__.py", line 180, in fetch
salt-master[3903]:     return self.modules[fun](bank, key, **self._kwargs)
salt-master[3903]:   File "/usr/lib/python2.7/dist-packages/salt/cache/etcd_cache.py", line 150, in fetch
salt-master[3903]:     etcd_key, exc
salt-master[3903]: SaltCacheError: There was an error reading the key, /salt_cache/minions/ca.aws-cc1.dev.xxx.yyy.com/mine: Key not found : /salt_cache/minions/ca.aws-cc1.dev.xxx.yyy.com/mine

# Fixed code
def flush(bank, key=None):
    """
    Remove the key from the cache bank with all the key content.
    """
    _init_client()
    if key is None:
        etcd_key = "{0}/{1}".format(path_prefix, bank)
    else:
        etcd_key = "{0}/{1}/{2}".format(path_prefix, bank, key)
    try:
        client.read(etcd_key)
    except etcd.EtcdKeyNotFound:
        return  # nothing to flush
    try:
        client.delete(etcd_key, recursive=True)
    except Exception as exc:
        raise SaltCacheError(
            "There was an error removing the key, {0}: {1}".format(etcd_key, exc)
        )