Skip to content

Commit 520f4ce

Browse files
new: use a specific exception when we can't infer the filetype
Signed-off-by: thiswillbeyourgithub <[email protected]>
1 parent 8e6ca1a commit 520f4ce

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

wdoc/utils/batch_file_loader.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
unlazyload_modules,
4646
)
4747
from wdoc.utils.typechecker import optional_typecheck
48+
from wdoc.utils.errors import NoInferrableFiletype
4849

4950
assert env.WDOC_BEHAVIOR_EXCL_INCL_USELESS in [
5051
"warn",
@@ -102,7 +103,7 @@ def infer_filetype(path: str) -> str:
102103
return k
103104
fp = Path(path)
104105
if not fp.exists():
105-
raise Exception(
106+
raise NoInferrableFiletype(
106107
f"Failed to detect 'auto' filetype for '{fp}' with regex, and it's not a file (does not exist)"
107108
)
108109
try:
@@ -116,7 +117,7 @@ def infer_filetype(path: str) -> str:
116117
# start = temp.read(1024)
117118
# info = magic.from_buffer(start).lower()
118119
except Exception as err:
119-
raise Exception(
120+
raise NoInferrableFiletype(
120121
f"Failed to detect 'auto' filetype for '{fp}' with regex and even python-magic. Error: '{err}'"
121122
) from err
122123
if "pdf" in info:
@@ -126,7 +127,9 @@ def infer_filetype(path: str) -> str:
126127
elif "epub" in info:
127128
return "epub"
128129
else:
129-
raise Exception(f"No more python magic heuristics to try for path '{path}'")
130+
raise NoInferrableFiletype(
131+
f"No more python magic heuristics to try for path '{path}'"
132+
)
130133

131134

132135
@optional_typecheck

0 commit comments

Comments
 (0)