# Buggy code
def _get_source_sum(source_hash, file_path, saltenv):
    """
    Extract the hash sum, whether it is in a remote hash file, or just a string.
    """
    ret = dict()
    schemes = ("salt", "http", "https", "ftp", "swift", "s3", "file")
    invalid_hash_msg = (
        "Source hash '{0}' format is invalid. It must be in the format"
        " <hash type>=<hash>"
    ).format(source_hash)
    source_hash = str(source_hash)
    source_hash_scheme = _urlparse(source_hash).scheme

    if source_hash_scheme in schemes:
        # The source_hash is a file on a server
        cached_hash_file = __salt__["cp.cache_file"](source_hash, saltenv)

        if not cached_hash_file:
            raise CommandExecutionError(
                ("Source hash file {0} not found").format(source_hash)
            )

        ret = __salt__["file.extract_hash"](cached_hash_file, "", file_path)
        if ret is None:
            raise SaltInvocationError(invalid_hash_msg)
    else:
        # The source_hash is a hash string
        items = source_hash.split("=", 1)

        if len(items) != 2:
            invalid_hash_msg = ("{0}, or it must be a supported protocol: {1}").format(
                invalid_hash_msg, ", ".join(schemes)
            )
            raise SaltInvocationError(invalid_hash_msg)

        ret["hash_type"], ret["hsum"] = [item.strip().lower() for item in items]

    return ret


# Traceback (CommandExecutionError)
----------
ID: openvpn
Function: pkg.installed
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "C:\salt\bin\lib\site-packages\salt\state.py", line 1626, in call
**cdata['kwargs'])
File "C:\salt\bin\lib\site-packages\salt\loader.py", line 1492, in wrapper
return f(*args, **kwargs)
File "c:\salt\var\cache\salt\minion\extmods\states\pkg.py", line 984, in installed
**kwargs)
File "c:\salt\var\cache\salt\minion\extmods\states\pkg.py", line 294, in _find_install_targets
cur_pkgs = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs)
File "c:\salt\var\cache\salt\minion\extmods\modules\win_pkg.py", line 244, in list_pkgs
name_map = _get_name_map()
File "c:\salt\var\cache\salt\minion\extmods\modules\win_pkg.py", line 1067, in _get_name_map
name_map = get_repo_data().get('name_map', {})
File "c:\salt\var\cache\salt\minion\extmods\modules\win_pkg.py", line 1050, in get_repo_data
'Windows repo cache doesn\'t exist, pkg.refresh_db likely '
CommandExecutionError: Windows repo cache doesn't exist, pkg.refresh_db likely needed

# Fixed code
def _get_source_sum(source_hash, file_path, saltenv):
    """
    Extract the hash sum, whether it is in a remote hash file, or just a string.
    """
    ret = dict()
    schemes = ("salt", "http", "https", "ftp", "swift", "s3", "file")
    invalid_hash_msg = (
        "Source hash '{0}' format is invalid. It must be in "
        "the format <hash type>=<hash>"
    ).format(source_hash)
    source_hash = str(source_hash)
    source_hash_scheme = _urlparse(source_hash).scheme

    if source_hash_scheme in schemes:
        # The source_hash is a file on a server
        cached_hash_file = __salt__["cp.cache_file"](source_hash, saltenv)

        if not cached_hash_file:
            raise CommandExecutionError(
                ("Source hash file {0} not found").format(source_hash)
            )

        ret = __salt__["file.extract_hash"](cached_hash_file, "", file_path)
        if ret is None:
            raise SaltInvocationError(invalid_hash_msg)
    else:
        # The source_hash is a hash string
        items = source_hash.split("=", 1)

        if len(items) != 2:
            invalid_hash_msg = ("{0}, or it must be a supported protocol: {1}").format(
                invalid_hash_msg, ", ".join(schemes)
            )
            raise SaltInvocationError(invalid_hash_msg)

        ret["hash_type"], ret["hsum"] = [item.strip().lower() for item in items]

    return ret