# Buggy code
def info(name):
    """
    Return user information

    CLI Example:

    .. code-block:: bash

        salt '*' user.info root
    """
    ret = {}
    items = {}
    for line in __salt__["cmd.run"]("net user {0}".format(name)).splitlines():
        if "name could not be found" in line:
            return {}
        if "successfully" not in line:
            comps = line.split("    ", 1)
            if not len(comps) > 1:
                continue
            items[comps[0].strip()] = comps[1].strip()
    grouplist = []
    groups = items["Local Group Memberships"].split("  ")
    for group in groups:
        if not group:
            continue
        grouplist.append(group.strip(" *"))

    ret["fullname"] = items["Full Name"]
    ret["name"] = items["User name"]
    ret["comment"] = items["Comment"]
    ret["active"] = items["Account active"]
    ret["logonscript"] = items["Logon script"]
    ret["profile"] = items["User profile"]
    if not ret["profile"]:
        ret["profile"] = _get_userprofile_from_registry(name)
    ret["home"] = items["Home directory"]
    ret["groups"] = grouplist
    ret["gid"] = ""

    return ret


# Traceback (KeyError)
C:\salt>salt-call.exe --local user.info Administrateur
[INFO    ] Executing command 'net user Administrateur' in directory 'C:\\Users\\user'
[INFO    ] output: Nom d’utilisateur                              Administrateur
Nom complet
Commentaire                                    Compte d’utilisateur d’administration
Commentaires utilisateur
Code du pays                                   000 (Valeur par défaut du système)
Compte : actif                                 Oui
Le compte expire                               Jamais

Mot de passe : dernier changmt.                21/01/2013 15:02:50
Le mot de passe expire                         Jamais
Le mot de passe modifiable                     22/01/2013 15:02:50
Mot de passe exigé                             Oui
L’utilisateur peut changer de mot de passe     Oui

Stations autorisées                            Tout
Script d’ouverture de session
Profil d’utilisateur
Répertoire de base
Dernier accès                                  21/01/2013 15:04:44

Heures d’accès autorisé                        Tout

Appartient aux groupes locaux                  *Administrateurs
*Utilisateurs du débog
Appartient aux groupes globaux                 *None
La commande s’est terminée correctement.
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
KeyError: 'Local Group Memberships'
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "__main__.py", line 726, in <module>
File "__main__.py", line 332, in bootstrap
File "__main__.py", line 359, in chainload
File "__main__.py", line 715, in _chainload
File "__main__.py", line 128, in <module>
File "__main__salt-call__.py", line 14, in <module>
File "salt/scripts.py", line 82, in salt_call
File "salt/cli/__init__.py", line 319, in run
File "salt/cli/caller.py", line 144, in run
File "salt/cli/caller.py", line 81, in call
File "C:\salt\salt-2014.1.7.win-amd64\salt-2014.1.7-py2.7.egg\salt\modules\win_useradd.py", line 290, in info
groups = items['Local Group Memberships'].split('  ')
KeyError: 'Local Group Memberships'

# Fixed code
def info(name):
    """
    Return user information

    CLI Example:

    .. code-block:: bash

        salt '*' user.info root
    """
    ret = {}
    items = {}
    try:
        items = win32net.NetUserGetInfo(None, name, 4)
    except win32net.error:
        pass

    if items:
        groups = []
        try:
            groups = win32net.NetUserGetLocalGroups(None, name)
        except win32net.error:
            pass

        ret["fullname"] = items["full_name"]
        ret["name"] = items["name"]
        ret["comment"] = items["comment"]
        ret["active"] = not bool(items["flags"] & win32netcon.UF_ACCOUNTDISABLE)
        ret["logonscript"] = items["script_path"]
        ret["profile"] = items["profile"]
        if not ret["profile"]:
            ret["profile"] = _get_userprofile_from_registry(name)
        ret["home"] = items["home_dir"]
        ret["groups"] = groups
        ret["gid"] = ""

    return ret