Handle OSError(errno=EINVAL) that might be raised in Windows (#346)

In Windows might OSError(errno=EINVAL) be raised instead of the already
catched exceptions in some cases (depending on the Python version).

Suggested fix posted by JarrettR in
https://github.com/wireviz/WireViz/issues/344#issuecomment-2113476151

Co-authored-by: JarrettR <jrainier@gmail.com>
This commit is contained in:
KV 2024-05-16 00:32:31 +02:00
parent 9435fc2c2f
commit 77061a0656

View File

@ -408,11 +408,12 @@ def _get_yaml_data_and_path(inp: Union[str, Path, Dict]) -> (Dict, Path):
yaml_str = open_file_read(yaml_path).read()
except (FileNotFoundError, OSError) as e:
# if inp is a long YAML string, Pathlib will raise OSError: [errno.ENAMETOOLONG]
# (in Windows, it seems OSError [errno.EINVAL] might be raised in some cases)
# when trying to expand and resolve it as a path.
# Catch this error, but raise any others
from errno import ENAMETOOLONG
from errno import EINVAL, ENAMETOOLONG
if type(e) is OSError and e.errno != ENAMETOOLONG:
if type(e) is OSError and e.errno not in (EINVAL, ENAMETOOLONG):
raise e
# file does not exist; assume inp is a YAML string
yaml_str = inp