Skip to content

Commit 3866b41

Browse files
committed
add skip_scan_error
1 parent f82bec4 commit 3866b41

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

comiclib/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Settings(BaseSettings):
1919
display_subtitle: Optional[bool] = None
2020
UA_convert_jxl: str = 'Android'
2121
UA_convert_all: str = r'\b\B' # default: match nothing
22+
skip_scan_error: bool = False
2223

2324
settings = Settings()
2425

comiclib/scan.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import copy
66
import hashlib
77
import time
8+
import traceback
89
from pathlib import Path
910
from pprint import pformat
1011

@@ -35,11 +36,14 @@
3536

3637

3738
def scan(paths):
39+
exceptions = Exception if settings.skip_scan_error else ()
40+
errors = {}
3841
with Session(engine) as db:
3942
try:
4043
for p in paths:
4144
checkpoint = db.begin_nested()
4245
try:
46+
name = None
4347
p = Path(os.path.relpath(p, settings.content))
4448
if p.is_relative_to('thumb'):
4549
continue
@@ -59,10 +63,11 @@ def scan(paths):
5963
prev_scanners = []
6064
for scanner, name in scanners:
6165
prev_metadata = copy.deepcopy(metadata)
62-
if scanner.scan(real_path, archive_id, metadata, prev_scanners):
66+
if scanner.scan(path=real_path, id=archive_id, metadata=metadata, prev_scanners=prev_scanners):
6367
prev_scanners.append(name)
6468
else:
6569
metadata = prev_metadata
70+
name = 'post_process'
6671
if not prev_scanners:
6772
continue
6873
if not any(tag.startswith("date_added:") for tag in metadata["tags"]):
@@ -91,11 +96,16 @@ def scan(paths):
9196
a.id = metadata["id"]
9297
db.add(a)
9398
checkpoint.commit()
99+
except exceptions:
100+
logger.error(traceback.format_exc())
101+
errors[str(p)] = name
94102
finally:
95103
if checkpoint.is_active:
96104
checkpoint.rollback()
97105
finally:
98106
db.commit()
107+
if settings.skip_scan_error and errors:
108+
logger.error('Processing failed while scanning the following files:\n%s', pformat(errors))
99109

100110
def get_files_inuse():
101111
ret = set()

0 commit comments

Comments
 (0)