# Buggy code
def error(self, message):
    import re
    import subprocess
    from .find_commands import find_executable

    exc = sys.exc_info()[1]
    if exc:
        # this is incredibly lame, but argparse stupidly does not expose
        # reasonable hooks for customizing error handling
        if hasattr(exc, "argument_name"):
            argument = self._get_action_from_name(exc.argument_name)
        else:
            argument = None
        if argument and argument.dest == "cmd":
            m = re.compile(r"invalid choice: '([\w\-]+)'").match(exc.message)
            if m:
                cmd = m.group(1)
                executable = find_executable("conda-" + cmd)
                if not executable:
                    raise CommandNotFoundError(cmd)

                args = [find_executable("conda-" + cmd)]
                args.extend(sys.argv[2:])
                p = subprocess.Popen(args)
                try:
                    p.communicate()
                except KeyboardInterrupt:
                    p.wait()
                finally:
                    sys.exit(p.returncode)

    super(ArgumentParser, self).error(message)


# Traceback (CalledProcessError)
________________________________ test_skeleton_pypi ________________________________
Traceback (most recent call last):
File "/home/dev/code/conda-build/tests/test_published_examples.py", line 15, in test_skeleton_pypi
check_call_env(cmd.split())
File "/home/dev/code/conda-build/conda_build/utils.py", line 670, in check_call_env
return _func_defaulting_env_to_os_environ(subprocess.check_call, *popenargs, **kwargs)
File "/home/dev/code/conda-build/conda_build/utils.py", line 666, in _func_defaulting_env_to_os_environ
return func(_args, **kwargs)
File "/opt/miniconda/lib/python2.7/subprocess.py", line 541, in check_call
raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['conda', 'skeleton', 'pypi', 'pyinstrument']' returned non-zero exit status 2
------------------------------- Captured stderr call -------------------------------
usage: conda [-h] [-V] command ...
conda: error: argument command: invalid choice: u'skeleton' (choose from u'info', u'help', u'list', u'search', u'create', u'install', u'update', u'upgrade', u'remove', u'uninstall', u'config', u'clean', u'package')

# Fixed code
def error(self, message):
    import re
    import subprocess
    from .find_commands import find_executable

    exc = sys.exc_info()[1]
    if exc:
        # this is incredibly lame, but argparse stupidly does not expose
        # reasonable hooks for customizing error handling
        if hasattr(exc, "argument_name"):
            argument = self._get_action_from_name(exc.argument_name)
        else:
            argument = None
        if argument and argument.dest == "cmd":
            m = re.compile(r"invalid choice: u?'([\w\-]+)'").match(exc.message)
            if m:
                cmd = m.group(1)
                executable = find_executable("conda-" + cmd)
                if not executable:
                    raise CommandNotFoundError(cmd)

                args = [find_executable("conda-" + cmd)]
                args.extend(sys.argv[2:])
                p = subprocess.Popen(args)
                try:
                    p.communicate()
                except KeyboardInterrupt:
                    p.wait()
                finally:
                    sys.exit(p.returncode)

    super(ArgumentParser, self).error(message)