mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Collect crawler warnings/errors and include them in the report
This commit is contained in:
parent
90cb6e989b
commit
a82a0b19c2
@ -47,10 +47,12 @@ def noncritical(f: Wrapped) -> Wrapped:
|
|||||||
try:
|
try:
|
||||||
f(*args, **kwargs)
|
f(*args, **kwargs)
|
||||||
except (CrawlWarning, OutputDirError, MarkDuplicateError, MarkConflictError) as e:
|
except (CrawlWarning, OutputDirError, MarkDuplicateError, MarkConflictError) as e:
|
||||||
|
crawler.report.add_warning(str(e))
|
||||||
log.warn(str(e))
|
log.warn(str(e))
|
||||||
crawler.error_free = False
|
crawler.error_free = False
|
||||||
except: # noqa: E722 do not use bare 'except'
|
except Exception as e:
|
||||||
crawler.error_free = False
|
crawler.error_free = False
|
||||||
|
crawler.report.add_error(str(e))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return wrapper # type: ignore
|
return wrapper # type: ignore
|
||||||
@ -83,8 +85,10 @@ def anoncritical(f: AWrapped) -> AWrapped:
|
|||||||
except (CrawlWarning, OutputDirError, MarkDuplicateError, MarkConflictError) as e:
|
except (CrawlWarning, OutputDirError, MarkDuplicateError, MarkConflictError) as e:
|
||||||
log.warn(str(e))
|
log.warn(str(e))
|
||||||
crawler.error_free = False
|
crawler.error_free = False
|
||||||
except: # noqa: E722 do not use bare 'except'
|
crawler.report.add_warning(str(e))
|
||||||
|
except Exception as e:
|
||||||
crawler.error_free = False
|
crawler.error_free = False
|
||||||
|
crawler.report.add_error(str(e))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
@ -182,5 +182,13 @@ class Pferd:
|
|||||||
something_changed = True
|
something_changed = True
|
||||||
log.report(f" [bold bright_magenta]Not deleted[/] {fmt_path(path)}")
|
log.report(f" [bold bright_magenta]Not deleted[/] {fmt_path(path)}")
|
||||||
|
|
||||||
|
for warning in crawler.report.encountered_warnings:
|
||||||
|
something_changed = True
|
||||||
|
log.report(f" [bold bright_red]Warning[/] {warning}")
|
||||||
|
|
||||||
|
for error in crawler.report.encountered_errors:
|
||||||
|
something_changed = True
|
||||||
|
log.report(f" [bold bright_red]Error[/] {error}")
|
||||||
|
|
||||||
if not something_changed:
|
if not something_changed:
|
||||||
log.report(" Nothing changed")
|
log.report(" Nothing changed")
|
||||||
|
@ -67,8 +67,14 @@ class Report:
|
|||||||
self.deleted_files: Set[PurePath] = set()
|
self.deleted_files: Set[PurePath] = set()
|
||||||
# Files that should have been deleted by the cleanup but weren't
|
# Files that should have been deleted by the cleanup but weren't
|
||||||
self.not_deleted_files: Set[PurePath] = set()
|
self.not_deleted_files: Set[PurePath] = set()
|
||||||
|
|
||||||
|
# Custom crawler-specific data
|
||||||
self.custom: Dict[str, Any] = dict()
|
self.custom: Dict[str, Any] = dict()
|
||||||
|
|
||||||
|
# Encountered errors and warnings
|
||||||
|
self.encountered_warnings: List[str] = []
|
||||||
|
self.encountered_errors: List[str] = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_list_of_strs(data: Dict[str, Any], key: str) -> List[str]:
|
def _get_list_of_strs(data: Dict[str, Any], key: str) -> List[str]:
|
||||||
result: Any = data.get(key, [])
|
result: Any = data.get(key, [])
|
||||||
@ -119,6 +125,8 @@ class Report:
|
|||||||
for elem in self._get_list_of_strs(data, "not_deleted"):
|
for elem in self._get_list_of_strs(data, "not_deleted"):
|
||||||
self.not_delete_file(PurePath(elem))
|
self.not_delete_file(PurePath(elem))
|
||||||
self.custom = self._get_str_dictionary(data, "custom")
|
self.custom = self._get_str_dictionary(data, "custom")
|
||||||
|
self.encountered_errors = self._get_list_of_strs(data, "encountered_errors")
|
||||||
|
self.encountered_warnings = self._get_list_of_strs(data, "encountered_warnings")
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@ -135,7 +143,9 @@ class Report:
|
|||||||
"changed": [str(path) for path in sorted(self.changed_files)],
|
"changed": [str(path) for path in sorted(self.changed_files)],
|
||||||
"deleted": [str(path) for path in sorted(self.deleted_files)],
|
"deleted": [str(path) for path in sorted(self.deleted_files)],
|
||||||
"not_deleted": [str(path) for path in sorted(self.not_deleted_files)],
|
"not_deleted": [str(path) for path in sorted(self.not_deleted_files)],
|
||||||
"custom": self.custom
|
"custom": self.custom,
|
||||||
|
"encountered_warnings": self.encountered_warnings,
|
||||||
|
"encountered_errors": self.encountered_errors,
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
@ -214,3 +224,15 @@ class Report:
|
|||||||
Retrieves a custom value for the given key.
|
Retrieves a custom value for the given key.
|
||||||
"""
|
"""
|
||||||
return self.custom.get(key)
|
return self.custom.get(key)
|
||||||
|
|
||||||
|
def add_error(self, error: str) -> None:
|
||||||
|
"""
|
||||||
|
Adds an error to this report's error list.
|
||||||
|
"""
|
||||||
|
self.encountered_errors.append(error)
|
||||||
|
|
||||||
|
def add_warning(self, warning: str) -> None:
|
||||||
|
"""
|
||||||
|
Adds a warning to this report's warning list.
|
||||||
|
"""
|
||||||
|
self.encountered_warnings.append(warning)
|
||||||
|
Loading…
Reference in New Issue
Block a user