# Buggy code
def autodetect_vs_version(build):
    vs_version = os.getenv("VisualStudioVersion", None)
    vs_install_dir = os.getenv("VSINSTALLDIR", None)
    if not vs_version and not vs_install_dir:
        raise MesonException(
            "Could not detect Visual Studio: VisualStudioVersion and VSINSTALLDIR are unset!\n"
            "Are we inside a Visual Studio build environment? "
            "You can also try specifying the exact backend to use."
        )
    # VisualStudioVersion is set since Visual Studio 12.0, but sometimes
    # vcvarsall.bat doesn't set it, so also use VSINSTALLDIR
    if vs_version == "14.0" or "Visual Studio 14" in vs_install_dir:
        from mesonbuild.backend.vs2015backend import Vs2015Backend

        return Vs2015Backend(build)
    if (
        vs_version == "15.0"
        or "Visual Studio 17" in vs_install_dir
        or "Visual Studio\\2017" in vs_install_dir
    ):
        from mesonbuild.backend.vs2017backend import Vs2017Backend

        return Vs2017Backend(build)
    if "Visual Studio 10.0" in vs_install_dir:
        return Vs2010Backend(build)
    raise MesonException(
        "Could not detect Visual Studio using VisualStudioVersion: {!r} or VSINSTALLDIR: {!r}!\n"
        "Please specify the exact backend to use.".format(vs_version, vs_install_dir)
    )


# Traceback (TypeError)
1>------ Build started: Project: REGEN, Configuration: debug Win32 ------
1>Checking whether solution needs to be regenerated.
1>The Meson build system
1>Version: 0.45.0.dev1
1>Source dir: C:\msys64\home\Polarina\mysa
1>Build dir: C:\msys64\home\Polarina\mysa\build
1>Build type: native build
1>Traceback (most recent call last):
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 365, in run
1>    app.generate()
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 151, in generate
1>    self._generate(env)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 174, in _generate
1>    g = vs2010backend.autodetect_vs_version(b)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\backend\vs2010backend.py", line 38, in autodetect_vs_version
1>    if vs_version == '14.0' or 'Visual Studio 14' in vs_install_dir:
1>TypeError: argument of type 'NoneType' is not iterable
1>Traceback (most recent call last):
1>  File "C:\Users\Polarina\AppData\Local\Programs\Python\Python36-32\Scripts\meson.py", line 26, in <module>
1>    sys.exit(main())
1>  File "C:\Users\Polarina\AppData\Local\Programs\Python\Python36-32\Scripts\meson.py", line 23, in main
1>    return mesonmain.run(sys.argv[1:], launcher)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 322, in run
1>    sys.exit(run_script_command(args[1:]))
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\mesonmain.py", line 278, in run_script_command
1>    return cmdfunc(cmdargs)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\scripts\regen_checker.py", line 55, in run
1>    regen(regeninfo, mesonscript, backend)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\site-packages\mesonbuild\scripts\regen_checker.py", line 41, in regen
1>    subprocess.check_call(cmd)
1>  File "c:\users\polarina\appdata\local\programs\python\python36-32\lib\subprocess.py", line 291, in check_call
1>    raise CalledProcessError(retcode, cmd)
1>subprocess.CalledProcessError: Command '['c:\\users\\polarina\\appdata\\local\\programs\\python\\python36-32\\python.exe', 'C:\\Users\\Polarina\\AppData\\Local\\Programs\\Python\\Python36-32\\Scripts\\meson.py', '--internal', 'regenerate', 'C:\\msys64\\home\\Polarina\\mysa\\build', 'C:\\msys64\\home\\Polarina\\mysa', '--backend=vs']' returned non-zero exit status 1.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1.
1>Done building project "REGEN.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

# Fixed code
def autodetect_vs_version(build):
    vs_version = os.getenv("VisualStudioVersion", None)
    vs_install_dir = os.getenv("VSINSTALLDIR", None)
    if not vs_install_dir:
        raise MesonException(
            "Could not detect Visual Studio: Environment variable VSINSTALLDIR is not set!\n"
            "Are you running meson from the Visual Studio Developer Command Prompt?"
        )
    # VisualStudioVersion is set since Visual Studio 12.0, but sometimes
    # vcvarsall.bat doesn't set it, so also use VSINSTALLDIR
    if vs_version == "14.0" or "Visual Studio 14" in vs_install_dir:
        from mesonbuild.backend.vs2015backend import Vs2015Backend

        return Vs2015Backend(build)
    if (
        vs_version == "15.0"
        or "Visual Studio 17" in vs_install_dir
        or "Visual Studio\\2017" in vs_install_dir
    ):
        from mesonbuild.backend.vs2017backend import Vs2017Backend

        return Vs2017Backend(build)
    if "Visual Studio 10.0" in vs_install_dir:
        return Vs2010Backend(build)
    raise MesonException(
        "Could not detect Visual Studio using VisualStudioVersion: {!r} or VSINSTALLDIR: {!r}!\n"
        "Please specify the exact backend to use.".format(vs_version, vs_install_dir)
    )