# Buggy code
def _run_check(self, low_data):
    """
    Check that unless doesn't return 0, and that onlyif returns a 0.
    """
    ret = {"result": False, "comment": []}
    cmd_opts = {}

    if "shell" in self.opts["grains"]:
        cmd_opts["shell"] = self.opts["grains"].get("shell")

    if "onlyif" in low_data:
        _ret = self._run_check_onlyif(low_data, cmd_opts)
        ret["result"] = _ret["result"]
        ret["comment"].append(_ret["comment"])
        if "skip_watch" in _ret:
            ret["skip_watch"] = _ret["skip_watch"]

    if "unless" in low_data:
        _ret = self._run_check_unless(low_data, cmd_opts)
        # If either result is True, the returned result should be True
        ret["result"] = _ret["result"] or ret["result"]
        ret["comment"].append(_ret["comment"])
        if "skip_watch" in _ret:
            # If either result is True, the returned result should be True
            ret["skip_watch"] = _ret["skip_watch"] or ret["skip_watch"]

    return ret


# Traceback (KeyError)
----------
ID: zsh_fail_1
Function: cmd.run
Name: echo hey
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/modules/cmdmod.py", line 442, in _run
pwd.getpwnam(runas)
KeyError: "getpwnam(): name not found: 'cristi'"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 1981, in call
**cdata['kwargs'])
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1977, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/cmd.py", line 892, in run
cret = mod_run_check(cmd_kwargs, onlyif, unless, creates)
File "/usr/lib/python3/dist-packages/salt/states/cmd.py", line 366, in mod_run_check
cmd = __salt__['cmd.retcode'](unless, ignore_retcode=True, python_shell=True, **cmd_kwargs)
File "/usr/lib/python3/dist-packages/salt/modules/cmdmod.py", line 2277, in retcode
**kwargs)
File "/usr/lib/python3/dist-packages/salt/modules/cmdmod.py", line 445, in _run
'User \'{0}\' is not available'.format(runas)
salt.exceptions.CommandExecutionError: User 'cristi' is not available
Started: 11:52:32.097022
Duration: 9.035 ms
Changes:
----------
ID: zsh_test_1
Function: cmd.run
Name: echo "t1"
Result: True
Comment: Command "echo "t1"" run
Started: 11:52:32.106490
Duration: 37.838 ms
Changes:
----------
pid:
30057
retcode:
0
stderr:
stdout:
t1

# Fixed code
def _run_check(self, low_data):
    """
    Check that unless doesn't return 0, and that onlyif returns a 0.
    """
    ret = {"result": False, "comment": []}
    cmd_opts = {}

    if "shell" in self.opts["grains"]:
        cmd_opts["shell"] = self.opts["grains"].get("shell")

    if "onlyif" in low_data:
        _ret = self._run_check_onlyif(low_data, cmd_opts)
        ret["result"] = _ret["result"]
        ret["comment"].append(_ret["comment"])
        if "skip_watch" in _ret:
            ret["skip_watch"] = _ret["skip_watch"]

    if "unless" in low_data:
        _ret = self._run_check_unless(low_data, cmd_opts)
        # If either result is True, the returned result should be True
        ret["result"] = _ret["result"] or ret["result"]
        ret["comment"].append(_ret["comment"])
        if "skip_watch" in _ret:
            # If either result is True, the returned result should be True
            ret["skip_watch"] = _ret["skip_watch"] or ret["skip_watch"]

    if "creates" in low_data:
        _ret = self._run_check_creates(low_data)
        ret["result"] = _ret["result"] or ret["result"]
        ret["comment"].append(_ret["comment"])
        if "skip_watch" in _ret:
            # If either result is True, the returned result should be True
            ret["skip_watch"] = _ret["skip_watch"] or ret["skip_watch"]

    return ret