# Buggy code
def blkid(device=None):
    """
    Return block device attributes: UUID, LABEL, etc.  This function only works
    on systems where blkid is available.

    CLI Example:

    .. code-block:: bash

        salt '*' disk.blkid
        salt '*' disk.blkid /dev/sda
    """
    args = ""
    if device:
        args = " " + device

    ret = {}
    for line in __salt__["cmd.run_stdout"]("blkid" + args, python_shell=False).split(
        "\n"
    ):
        comps = line.split()
        device = comps[0][:-1]
        info = {}
        device_attributes = re.split(('"*"'), line.partition(" ")[2])
        for key, value in zip(*[iter(device_attributes)] * 2):
            key = key.strip("=").strip(" ")
            info[key] = value.strip('"')
        ret[device] = info

    return ret


# Traceback (IndexError)
$ salt-call -l debug disk.blkid
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/masterless.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/masterless.conf
[DEBUG   ] Configuration file path: /etc/salt/minion
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/masterless.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/masterless.conf
[WARNING ] Although 'dmidecode' was found in path, the current user cannot execute it. Grains output might not be accurate.
[DEBUG   ] Mako not available
[…]
[INFO    ] Executing command 'blkid' in directory '/root'
[ERROR   ] Command 'blkid' failed with return code: 2
[ERROR   ] retcode: 2
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
IndexError: list index out of range
Traceback (most recent call last):
File "/bin/salt-call", line 11, in <module>
salt_call()
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 123, in salt_call
client.run()
File "/usr/lib/python2.7/site-packages/salt/cli/__init__.py", line 420, in run
caller.run()
File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 225, in run
ret = self.call()
File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 129, in call
ret['return'] = func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/modules/disk.py", line 215, in blkid
device = comps[0][:-1]
IndexError: list index out of range
Traceback (most recent call last):
File "/bin/salt-call", line 11, in <module>
salt_call()
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 123, in salt_call
client.run()
File "/usr/lib/python2.7/site-packages/salt/cli/__init__.py", line 420, in run
caller.run()
File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 225, in run
ret = self.call()
File "/usr/lib/python2.7/site-packages/salt/cli/caller.py", line 129, in call
ret['return'] = func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/modules/disk.py", line 215, in blkid
device = comps[0][:-1]
IndexError: list index out of range

# Fixed code
def blkid(device=None):
    """
    Return block device attributes: UUID, LABEL, etc.  This function only works
    on systems where blkid is available.

    CLI Example:

    .. code-block:: bash

        salt '*' disk.blkid
        salt '*' disk.blkid /dev/sda
    """
    args = ""
    if device:
        args = " " + device

    ret = {}
    blkid_result = __salt__["cmd.run_all"]("blkid" + args, python_shell=False)
    if blkid_result["retcode"] > 0:
        return ret
    for line in blkid_result["stdout"].split("\n"):
        comps = line.split()
        device = comps[0][:-1]
        info = {}
        device_attributes = re.split(('"*"'), line.partition(" ")[2])
        for key, value in zip(*[iter(device_attributes)] * 2):
            key = key.strip("=").strip(" ")
            info[key] = value.strip('"')
        ret[device] = info

    return ret