[common] introduce 'status' attribute to Extractors
allows reporting error codes for exceptions that are not handled by the Job.run() try-except block - fixes Job.status being 0 in certain situations even when errors occurred - fixes some URLs not getting written to -e/--error-file (#7758)
This commit is contained in:
@@ -36,6 +36,7 @@ class Extractor():
|
||||
directory_fmt = ("{category}",)
|
||||
filename_fmt = "{filename}.{extension}"
|
||||
archive_fmt = ""
|
||||
status = 0
|
||||
root = ""
|
||||
cookies_domain = ""
|
||||
cookies_index = 0
|
||||
@@ -207,6 +208,7 @@ class Extractor():
|
||||
response.encoding = encoding
|
||||
return response
|
||||
if notfound and code == 404:
|
||||
self.status |= exception.NotFoundError.code
|
||||
raise exception.NotFoundError(notfound)
|
||||
|
||||
msg = f"'{code} {response.reason}' for '{response.url}'"
|
||||
@@ -246,6 +248,8 @@ class Extractor():
|
||||
if not fatal or fatal is ...:
|
||||
self.log.warning(msg)
|
||||
return util.NullResponse(url, msg)
|
||||
|
||||
self.status |= exception.HttpError.code
|
||||
raise exception.HttpError(msg, response)
|
||||
|
||||
def request_location(self, url, **kwargs):
|
||||
|
||||
@@ -1166,15 +1166,15 @@ class DeviantartStatusExtractor(DeviantartExtractor):
|
||||
|
||||
def deviations(self):
|
||||
for status in self.api.user_statuses(self.user, self.offset):
|
||||
yield from self.status(status)
|
||||
yield from self.process_status(status)
|
||||
|
||||
def status(self, status):
|
||||
def process_status(self, status):
|
||||
for item in status.get("items") or (): # do not trust is_share
|
||||
# shared deviations/statuses
|
||||
if "deviation" in item:
|
||||
yield item["deviation"].copy()
|
||||
if "status" in item:
|
||||
yield from self.status(item["status"].copy())
|
||||
yield from self.process_status(item["status"].copy())
|
||||
# assume is_deleted == true means necessary fields are missing
|
||||
if status["is_deleted"]:
|
||||
self.log.warning(
|
||||
|
||||
@@ -186,6 +186,8 @@ class Job():
|
||||
self.handle_finalize()
|
||||
extractor.finalize()
|
||||
|
||||
if s := extractor.status:
|
||||
self.status |= s
|
||||
return self.status
|
||||
|
||||
def dispatch(self, msg):
|
||||
|
||||
Reference in New Issue
Block a user