# Buggy code
def append(name, **kwargs):
    """
    Append a rule to a chain

    name
        A user-defined name to call this rule by in another part of a state or
        formula. This should not be an actual rule.

    All other arguments are passed in with the same name as the long option
    that would normally be used for iptables, with one exception: `--state` is
    specified as `connstate` instead of `state` (not to be confused with
    `ctstate`).
    """
    ret = {"name": name, "changes": {}, "result": None, "comment": ""}
    rule = __salt__["iptables.build_rule"](**kwargs)
    command = __salt__["iptables.build_rule"](full=True, command="A", **kwargs)
    if __salt__["iptables.check"](kwargs["table"], kwargs["chain"], rule) is True:
        ret["result"] = True
        ret["comment"] = "iptables rule for {0} already set ({1})".format(
            name, command.strip()
        )
        return ret
    if __opts__["test"]:
        ret["comment"] = "iptables rule for {0} needs to be set ({1})".format(
            name, command.strip()
        )
        return ret
    if not __salt__["iptables.append"](kwargs["table"], kwargs["chain"], rule):
        ret["changes"] = {"locale": name}
        ret["result"] = True
        ret["comment"] = "Set iptables rule for {0} to: {1}".format(
            name, command.strip()
        )
        return ret
    else:
        ret["result"] = False
        ret["comment"] = "Failed to set iptables rule for {0}".format(name)
        return ret


# Traceback (AttributeError)
[ERROR   ] Error in function _master_opts:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/master.py", line 1444, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/pymodules/python2.7/salt/master.py", line 891, in _master_opts
envs = self._file_envs()
File "/usr/lib/pymodules/python2.7/salt/fileserver/__init__.py", line 153, in envs
ret.update(self.servers[fstr]())
File "/usr/lib/pymodules/python2.7/salt/fileserver/hgfs.py", line 176, in envs
tags = repo.get_tags()
AttributeError: 'hgclient' object has no attribute 'get_tags'

# Fixed code
def append(name, **kwargs):
    """
    Append a rule to a chain

    name
        A user-defined name to call this rule by in another part of a state or
        formula. This should not be an actual rule.

    All other arguments are passed in with the same name as the long option
    that would normally be used for iptables, with one exception: `--state` is
    specified as `connstate` instead of `state` (not to be confused with
    `ctstate`).
    """
    ret = {"name": name, "changes": {}, "result": None, "comment": ""}

    for ignore in "__env__", "__sls__", "order":
        if ignore in kwargs:
            del kwargs[ignore]

    rule = __salt__["iptables.build_rule"](**kwargs)
    command = __salt__["iptables.build_rule"](full=True, command="A", **kwargs)
    if __salt__["iptables.check"](kwargs["table"], kwargs["chain"], rule) is True:
        ret["result"] = True
        ret["comment"] = "iptables rule for {0} already set ({1})".format(
            name, command.strip()
        )
        return ret
    if __opts__["test"]:
        ret["comment"] = "iptables rule for {0} needs to be set ({1})".format(
            name, command.strip()
        )
        return ret
    if not __salt__["iptables.append"](kwargs["table"], kwargs["chain"], rule):
        ret["changes"] = {"locale": name}
        ret["result"] = True
        ret["comment"] = "Set iptables rule for {0} to: {1}".format(
            name, command.strip()
        )
        return ret
    else:
        ret["result"] = False
        ret["comment"] = "Failed to set iptables rule for {0}".format(name)
        return ret