Skip to content

Commit

Permalink
Adjust exception formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
elacuesta committed Mar 30, 2020
1 parent 46befb8 commit 1261f5a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions scrapy/core/engine.py
Expand Up @@ -169,7 +169,8 @@ def _next_request_from_scheduler(self, spider):
def _handle_downloader_output(self, response, request, spider):
if not isinstance(response, (Request, Response, Failure)):
raise TypeError(
"Incorrect type: expected Request, Response or Failure, got %s" % type(response)
"Incorrect type: expected Request, Response or Failure, got %s: %r"
% (type(response), response)
)
# downloader middleware can return requests (for example, redirects)
if isinstance(response, Request):
Expand Down Expand Up @@ -239,7 +240,8 @@ def _download(self, request, spider):
def _on_success(response):
if not isinstance(response, (Response, Request)):
raise TypeError(
"Incorrect type: expected Response or Request, got %s" % type(response)
"Incorrect type: expected Response or Request, got %s: %r"
% (type(response), response)
)
if isinstance(response, Response):
response.request = request # tie request to response received
Expand Down
3 changes: 2 additions & 1 deletion scrapy/core/scraper.py
Expand Up @@ -125,7 +125,8 @@ def _scrape(self, response, request, spider):
callback/errback"""
if not isinstance(response, (Response, Failure)):
raise TypeError(
"Incorrect type: expected Response or Failure, got %s" % type(response)
"Incorrect type: expected Response or Failure, got %s: %r"
% (type(response), response)
)

dfd = self._scrape2(response, request, spider) # returns spider's processed output
Expand Down
6 changes: 3 additions & 3 deletions scrapy/pipelines/files.py
Expand Up @@ -107,7 +107,7 @@ def __init__(self, uri):
from boto.s3.connection import S3Connection
self.S3Connection = S3Connection
if not uri.startswith("s3://"):
raise ValueError("Incorrect URI scheme in %s, expected s3" % uri)
raise ValueError("Incorrect URI scheme in %s, expected 's3'" % uri)
self.bucket, self.prefix = uri[5:].split('/', 1)

def stat_file(self, path, info):
Expand Down Expand Up @@ -267,8 +267,8 @@ class FTPFilesStore:
USE_ACTIVE_MODE = None

def __init__(self, uri):
if not uri.startswith('ftp://'):
raise ValueError("Incorrect URI scheme in %s, expected ftp" % uri)
if not uri.startswith("ftp://"):
raise ValueError("Incorrect URI scheme in %s, expected 'ftp'" % uri)
u = urlparse(uri)
self.port = u.port
self.host = u.hostname
Expand Down
5 changes: 4 additions & 1 deletion scrapy/utils/iterators.py
Expand Up @@ -130,7 +130,10 @@ def _body_or_str(obj, unicode=True):
expected_types = (Response, str, bytes)
if not isinstance(obj, expected_types):
expected_types_str = " or ".join(t.__name__ for t in expected_types)
raise TypeError("obj must be %s, not %s" % (expected_types_str, type(obj).__name__))
raise TypeError(
"Object %r must be %s, not %s"
% (obj, expected_types_str, type(obj).__name__)
)
if isinstance(obj, Response):
if not unicode:
return obj.body
Expand Down

0 comments on commit 1261f5a

Please sign in to comment.