def METHOD_NAME(
    script_file: t.Union[str, pathlib.Path], cwd: t.Optional[pathlib.Path] = None
) -> int:
    """Function to wrap try/except for subprocess.check_call()."""
    try:
        proc = subprocess.Popen(
            shlex.split(str(script_file)),
            stderr=subprocess.PIPE,
            stdout=subprocess.PIPE,
            cwd=cwd,
        )
        if proc.stdout is not None:
            for line in iter(proc.stdout.readline, b""):
                sys.stdout.write(console_to_str(line))
        proc.wait()
        if proc.returncode and proc.stderr is not None:
            stderr = proc.stderr.read()
            proc.stderr.close()
            stderr_strlist = console_to_str(stderr).split("\n")
            stderr_str = "\n".join(list(filter(None, stderr_strlist)))  # filter empty
            raise exc.BeforeLoadScriptError(
                proc.returncode,
                os.path.abspath(script_file),  # NOQA: PTH100
                stderr_str,
            )
        else:
            return proc.returncode
    except OSError as e:
        if e.errno == 2:
            raise exc.BeforeLoadScriptNotExists(
                e,
                os.path.abspath(script_file),  # NOQA: PTH100
            ) from e
        else:
            raise