# Buggy code
def lsattr(path):
    """
    .. versionadded:: 2018.3.0
    .. versionchanged:: 2018.3.1
        If ``lsattr`` is not installed on the system, ``None`` is returned.

    Obtain the modifiable attributes of the given file. If path
    is to a directory, an empty list is returned.

    path
        path to file to obtain attributes of. File/directory must exist.

    CLI Example:

    .. code-block:: bash

        salt '*' file.lsattr foo1.txt
    """
    if not salt.utils.path.which("lsattr"):
        return None

    if not os.path.exists(path):
        raise SaltInvocationError("File or directory does not exist.")

    cmd = ["lsattr", path]
    result = __salt__["cmd.run"](cmd, ignore_retcode=True, python_shell=False)

    results = {}
    for line in result.splitlines():
        if not line.startswith("lsattr: "):
            vals = line.split(None, 1)
            results[vals[1]] = re.findall(r"[acdijstuADST]", vals[0])

    return results


# Traceback (IndexError)
[DEBUG   ] output: lsattr: 0514-500 Usage error - /var/spool/cron/crontabs/root

Usage:
lsattr {-D[-O]| -E[-O] -P[-O]| -F Format [-Z Character]} -l Name
[-a Attribute]...[-H] [-f File]
lsattr {-D[-O]| -F Format [-Z Character]}{[-c Class][-s Subclass][-t Type]}
[-a Attribute]... [-H][-f File]
lsattr -R {-l Name | [-c Class][-s Subclass][-t Type]} -a Attribute [-H]
[-f File]
lsattr {-l Name | [-c Class][-s Subclass][-t Type]} -o Operation [...]
-F Format [-Z Character][-f File][-H]
lsattr -h
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
File "/opt/salt/lib/python2.7/site-packages/salt/state.py", line 1905, in call
**cdata['kwargs'])
File "/opt/salt/lib/python2.7/site-packages/salt/loader.py", line 1830, in wrapper
return f(*args, **kwargs)
File "/opt/salt/lib/python2.7/site-packages/salt/states/file.py", line 4119, in replace
backslash_literal=backslash_literal)
File "/opt/salt/lib/python2.7/site-packages/salt/modules/file.py", line 2420, in replace
check_perms(path, None, pre_user, pre_group, pre_mode)
File "/opt/salt/lib/python2.7/site-packages/salt/modules/file.py", line 4460, in check_perms
lattrs = lsattr(name)
File "/opt/salt/lib/python2.7/site-packages/salt/modules/file.py", line 573, in lsattr
results[vals[1]] = re.findall(r"[acdijstuADST]", vals[0])
IndexError: list index out of range

# Fixed code
def lsattr(path):
    """
    .. versionadded:: 2018.3.0
    .. versionchanged:: 2018.3.1
        If ``lsattr`` is not installed on the system, ``None`` is returned.
    .. versionchanged:: 2018.3.4
        If on ``AIX``, ``None`` is returned even if in filesystem as lsattr on ``AIX``
        is not the same thing as the linux version.

    Obtain the modifiable attributes of the given file. If path
    is to a directory, an empty list is returned.

    path
        path to file to obtain attributes of. File/directory must exist.

    CLI Example:

    .. code-block:: bash

        salt '*' file.lsattr foo1.txt
    """
    if not salt.utils.path.which("lsattr") or salt.utils.platform.is_aix():
        return None

    if not os.path.exists(path):
        raise SaltInvocationError("File or directory does not exist.")

    cmd = ["lsattr", path]
    result = __salt__["cmd.run"](cmd, ignore_retcode=True, python_shell=False)

    results = {}
    for line in result.splitlines():
        if not line.startswith("lsattr: "):
            vals = line.split(None, 1)
            results[vals[1]] = re.findall(r"[acdijstuADST]", vals[0])

    return results