diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2019-03-16 17:16:51 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2019-03-16 17:17:46 +0100 |
commit | b0e31340b4551d997a8895fd9294b253ddf69dc5 (patch) | |
tree | c4614accf1470bf92a6c941d20b5cf1de5f2cced /crocoite | |
parent | 810f9b3fdfb729b23e77de13497f711b1e78d15e (diff) | |
download | crocoite-b0e31340b4551d997a8895fd9294b253ddf69dc5.tar.gz crocoite-b0e31340b4551d997a8895fd9294b253ddf69dc5.tar.bz2 crocoite-b0e31340b4551d997a8895fd9294b253ddf69dc5.zip |
browser: Raise exception if navigation failed
Stop early if there’s nothing to do.
Diffstat (limited to 'crocoite')
-rw-r--r-- | crocoite/browser.py | 5 | ||||
-rw-r--r-- | crocoite/cli.py | 5 | ||||
-rw-r--r-- | crocoite/test_browser.py | 10 |
3 files changed, 12 insertions, 8 deletions
diff --git a/crocoite/browser.py b/crocoite/browser.py index ce96f7e..10eaaff 100644 --- a/crocoite/browser.py +++ b/crocoite/browser.py @@ -269,6 +269,9 @@ class VarChangeEvent: await self.event.wait () return self._value +class NavigateError (IOError): + pass + class SiteLoader: """ Load site in Chrome and monitor network requests @@ -364,6 +367,8 @@ class SiteLoader: ret = await self.tab.Page.navigate(url=url) self.logger.debug ('navigate', uuid='9d47ded2-951f-4e09-86ee-fd4151e20666', result=ret) + if 'errorText' in ret: + raise NavigateError (ret['errorText']) # internal chrome callbacks async def _requestWillBeSent (self, **kwargs): diff --git a/crocoite/cli.py b/crocoite/cli.py index 0595eb9..fb9060d 100644 --- a/crocoite/cli.py +++ b/crocoite/cli.py @@ -32,7 +32,7 @@ try: except ModuleNotFoundError: pass -from . import behavior +from . import behavior, browser from .controller import SinglePageController, \ ControllerSettings, StatsHandler, LogHandler, \ RecursiveController, DepthLimit, PrefixLimit @@ -47,6 +47,7 @@ class SingleExitStatus(IntEnum): Ok = 0 Fail = 1 BrowserCrash = 2 + Navigate = 3 def single (): parser = argparse.ArgumentParser(description='Save website to WARC using Google Chrome.') @@ -90,6 +91,8 @@ def single (): except asyncio.CancelledError: # don’t log this one pass + except browser.NavigateError: + ret = SingleExitStatus.Navigate except Exception as e: ret = SingleExitStatus.Fail logger.error ('cli exception', diff --git a/crocoite/test_browser.py b/crocoite/test_browser.py index 7727259..6341bd6 100644 --- a/crocoite/test_browser.py +++ b/crocoite/test_browser.py @@ -34,7 +34,7 @@ import pytest from .browser import RequestResponsePair, SiteLoader, VarChangeEvent, Request, \ UnicodeBody, ReferenceTimestamp, Base64Body, UnicodeBody, Request, \ - Response + Response, NavigateError from .logger import Logger, Consumer from .devtools import Crashed, Process @@ -74,12 +74,8 @@ async def test_invalidurl (loader): resolved = await loop.getaddrinfo (host, None) except socket.gaierror: url = URL.build (scheme='http', host=host) - await loader.navigate (url) - async for it in loader: - assert it.request is not None - assert it.url == url - assert it.response is None - break + with pytest.raises (NavigateError): + await loader.navigate (url) else: pytest.skip (f'host {host} resolved to {resolved}') |