Skip to content

Commit 601b44c

Browse files
committed
Handle UnicodeDecodeError instead of Exception
1 parent bd566d0 commit 601b44c

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

logya/content.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,10 @@
88
from logya.util import load_yaml, slugify
99

1010
# Extensions of content files that will be processed.
11-
process_extensions = {
12-
'.css',
13-
'.htm',
14-
'.html',
15-
'.js',
16-
'.json',
17-
'.markdown',
18-
'.md',
19-
'.php',
20-
'.txt',
21-
'.xml'
22-
}
11+
process_extensions = {'.css', '.htm', '.html', '.js', '.json', '.markdown', '.md', '.php', '.txt', '.xml'}
2312

2413
# Extensions of content files that will be removed.
25-
remove_extensions = {
26-
'.htm',
27-
'.html',
28-
'.markdown',
29-
'.md'
30-
}
14+
remove_extensions = {'.htm', '.html', '.markdown', '.md'}
3115

3216

3317
def content_type(path: Path) -> str | None:
@@ -75,7 +59,7 @@ def parse(content: str) -> dict:
7559
header_start = lines.index('---') + 1
7660
header_end = lines[header_start:].index('---') + 1
7761
header = '\n'.join(lines[header_start:header_end])
78-
body = '\n'.join(lines[header_end + 1:]).strip()
62+
body = '\n'.join(lines[header_end + 1 :]).strip()
7963
parsed = load_yaml(header)
8064
parsed['body'] = body
8165
return parsed
@@ -84,7 +68,7 @@ def parse(content: str) -> dict:
8468
def read(path: Path, path_rel: Path, markdown_extensions: list) -> dict | None:
8569
try:
8670
doc = parse(path.read_text().strip())
87-
except Exception as err:
71+
except UnicodeDecodeError as err:
8872
print(f'Error reading/parsing: {path}\n{err}')
8973
return None
9074

0 commit comments

Comments
 (0)