# Buggy code
def run(self):
    """
    Execute the salt command line
    """
    self.parse_args()

    if self.config["verify_env"]:
        if (
            not self.config["log_file"].startswith("tcp://")
            or not self.config["log_file"].startswith("udp://")
            or not self.config["log_file"].startswith("file://")
        ):
            # Logfile is not using Syslog, verify
            verify_files([self.config["log_file"]], self.config["user"])

    # Setup file logging!
    self.setup_logfile_logger()

    try:
        local = salt.client.LocalClient(self.get_config_file_path())
    except SaltClientError as exc:
        self.exit(2, "{0}\n".format(exc))
        return

    if self.options.batch:
        batch = salt.cli.batch.Batch(self.config)
        # Printing the output is already taken care of in run() itself
        for res in batch.run():
            pass
    else:
        if self.options.timeout <= 0:
            self.options.timeout = local.opts["timeout"]

        kwargs = {
            "tgt": self.config["tgt"],
            "fun": self.config["fun"],
            "arg": self.config["arg"],
            "timeout": self.options.timeout,
            "show_timeout": self.options.show_timeout,
        }

        if "token" in self.config:
            kwargs["token"] = self.config["token"]

        if self.selected_target_option:
            kwargs["expr_form"] = self.selected_target_option
        else:
            kwargs["expr_form"] = "glob"

        if getattr(self.options, "return"):
            kwargs["ret"] = getattr(self.options, "return")

        # If using eauth and a token hasn't already been loaded into
        # kwargs, prompt the user to enter auth credentials
        if not "token" in kwargs and self.options.eauth:
            resolver = salt.auth.Resolver(self.config)
            res = resolver.cli(self.options.eauth)
            if self.options.mktoken and res:
                tok = resolver.token_cli(self.options.eauth, res)
                if tok:
                    kwargs["token"] = tok.get("token", "")
            if not res:
                sys.exit(2)
            kwargs.update(res)
            kwargs["eauth"] = self.options.eauth

        if self.config["async"]:
            jid = local.cmd_async(**kwargs)
            print("Executed command with job ID: {0}".format(jid))
            return
        try:
            # local will be None when there was an error
            if local:
                if self.options.subset:
                    cmd_func = local.cmd_subset
                    kwargs["sub"] = self.options.subset
                    kwargs["cli"] = True
                else:
                    cmd_func = local.cmd_cli
                if self.options.static:
                    if self.options.verbose:
                        kwargs["verbose"] = True
                    full_ret = local.cmd_full_return(**kwargs)
                    ret, out = self._format_ret(full_ret)
                    self._output_ret(ret, out)
                elif self.config["fun"] == "sys.doc":
                    ret = {}
                    out = ""
                    for full_ret in local.cmd_cli(**kwargs):
                        ret_, out = self._format_ret(full_ret)
                        ret.update(ret_)
                    self._output_ret(ret, out)
                else:
                    if self.options.verbose:
                        kwargs["verbose"] = True
                    for full_ret in cmd_func(**kwargs):
                        ret, out = self._format_ret(full_ret)
                        self._output_ret(ret, out)
        except (SaltInvocationError, EauthAuthenticationError) as exc:
            ret = str(exc)
            out = ""
            self._output_ret(ret, out)


# 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 run(self):
    """
    Execute the salt command line
    """
    self.parse_args()

    if self.config["verify_env"]:
        if not (
            self.config["log_file"].startswith("tcp://")
            or self.config["log_file"].startswith("udp://")
            or self.config["log_file"].startswith("file://")
        ):
            # Logfile is not using Syslog, verify
            verify_files([self.config["log_file"]], self.config["user"])

    # Setup file logging!
    self.setup_logfile_logger()

    try:
        local = salt.client.LocalClient(self.get_config_file_path())
    except SaltClientError as exc:
        self.exit(2, "{0}\n".format(exc))
        return

    if self.options.batch:
        batch = salt.cli.batch.Batch(self.config)
        # Printing the output is already taken care of in run() itself
        for res in batch.run():
            pass
    else:
        if self.options.timeout <= 0:
            self.options.timeout = local.opts["timeout"]

        kwargs = {
            "tgt": self.config["tgt"],
            "fun": self.config["fun"],
            "arg": self.config["arg"],
            "timeout": self.options.timeout,
            "show_timeout": self.options.show_timeout,
        }

        if "token" in self.config:
            kwargs["token"] = self.config["token"]

        if self.selected_target_option:
            kwargs["expr_form"] = self.selected_target_option
        else:
            kwargs["expr_form"] = "glob"

        if getattr(self.options, "return"):
            kwargs["ret"] = getattr(self.options, "return")

        # If using eauth and a token hasn't already been loaded into
        # kwargs, prompt the user to enter auth credentials
        if not "token" in kwargs and self.options.eauth:
            resolver = salt.auth.Resolver(self.config)
            res = resolver.cli(self.options.eauth)
            if self.options.mktoken and res:
                tok = resolver.token_cli(self.options.eauth, res)
                if tok:
                    kwargs["token"] = tok.get("token", "")
            if not res:
                sys.exit(2)
            kwargs.update(res)
            kwargs["eauth"] = self.options.eauth

        if self.config["async"]:
            jid = local.cmd_async(**kwargs)
            print("Executed command with job ID: {0}".format(jid))
            return
        try:
            # local will be None when there was an error
            if local:
                if self.options.subset:
                    cmd_func = local.cmd_subset
                    kwargs["sub"] = self.options.subset
                    kwargs["cli"] = True
                else:
                    cmd_func = local.cmd_cli
                if self.options.static:
                    if self.options.verbose:
                        kwargs["verbose"] = True
                    full_ret = local.cmd_full_return(**kwargs)
                    ret, out = self._format_ret(full_ret)
                    self._output_ret(ret, out)
                elif self.config["fun"] == "sys.doc":
                    ret = {}
                    out = ""
                    for full_ret in local.cmd_cli(**kwargs):
                        ret_, out = self._format_ret(full_ret)
                        ret.update(ret_)
                    self._output_ret(ret, out)
                else:
                    if self.options.verbose:
                        kwargs["verbose"] = True
                    for full_ret in cmd_func(**kwargs):
                        ret, out = self._format_ret(full_ret)
                        self._output_ret(ret, out)
        except (SaltInvocationError, EauthAuthenticationError) as exc:
            ret = str(exc)
            out = ""
            self._output_ret(ret, out)