From 3d62b9200725bbd294f435f25380d8c8bebfb768 Mon Sep 17 00:00:00 2001 From: MrTango Date: Wed, 17 Apr 2019 10:36:38 +0200 Subject: [PATCH 1/6] Catch errors on resolving tiles and return an error message instead of breaking the whole UI --- CHANGES.rst | 2 ++ plone/app/blocks/utils.py | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8ea64eff..a8dae514 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,8 @@ Changelog ------------------ Bug fixes: +- Catch errors on resolving tiles and return an error message instead of breaking the whole UI + [MrTango] - Fix issue where layout aware tile data storage read cache was not purged when data was updated programmatically [fixes #75] diff --git a/plone/app/blocks/utils.py b/plone/app/blocks/utils.py index d51dfa40..a63808a4 100644 --- a/plone/app/blocks/utils.py +++ b/plone/app/blocks/utils.py @@ -69,9 +69,31 @@ def extractCharset(response, default='utf-8'): def resolve(url, resolved=None): """Resolve the given URL to an lxml tree. """ - if resolved is None: - resolved = resolveResource(url) + try: + resolved = resolveResource(url) + except Exception as e: + logger.error( + 'Error while trying to resolve tile: {0} {1}'.format( + url, e + ), + ) + scheme, netloc, path, params, query, fragment = parse.urlparse(url) + tile_parts = { + 'scheme': scheme, + 'netloc': netloc, + 'path': path, + } + resolved = """ + + + + +""".format(**tile_parts) + if not resolved.strip(): return None try: From 754f6063efb89224b91ea5e723806eb672900ded Mon Sep 17 00:00:00 2001 From: MrTango Date: Wed, 17 Apr 2019 11:52:54 +0200 Subject: [PATCH 2/6] use logger.exception for error logging --- .gitignore | 1 + plone/app/blocks/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 8897b875..990c192d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ local/ parts/ var/ src/ +/pip-selfcheck.json diff --git a/plone/app/blocks/utils.py b/plone/app/blocks/utils.py index a63808a4..a9676922 100644 --- a/plone/app/blocks/utils.py +++ b/plone/app/blocks/utils.py @@ -72,10 +72,10 @@ def resolve(url, resolved=None): if resolved is None: try: resolved = resolveResource(url) - except Exception as e: - logger.error( - 'Error while trying to resolve tile: {0} {1}'.format( - url, e + except Exception: + logger.exception( + 'Error while trying to resolve tile: {0}'.format( + url, ), ) scheme, netloc, path, params, query, fragment = parse.urlparse(url) From de75de9237a517505840b0f5b2e552956f6b59f0 Mon Sep 17 00:00:00 2001 From: MrTango Date: Wed, 17 Apr 2019 17:57:09 +0200 Subject: [PATCH 3/6] Fix test in blocks --- plone/app/blocks/tests/test_tiles.py | 4 +++- plone/app/blocks/utils.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plone/app/blocks/tests/test_tiles.py b/plone/app/blocks/tests/test_tiles.py index 219e8ce1..84a702f7 100644 --- a/plone/app/blocks/tests/test_tiles.py +++ b/plone/app/blocks/tests/test_tiles.py @@ -35,6 +35,7 @@ def __call__(self):

Magic number: %(number)d; Form: %(form)s; Query string: %(queryString)s; URL: %(url)s + Umlauts: Übertile ;)

""" % dict(name=self.id, number=self.data['magicNumber'] or -1, @@ -225,6 +226,7 @@ def testRenderTiles(self): self.assertIn('This is a demo tile with id tile2', result) self.assertIn('This is a demo tile with id tile3', result) self.assertIn('This is a demo tile with id tile4', result) + self.assertIn('Umlauts: Übertile', result) def testRenderTilesError(self): serializer = getHTMLSerializer([testLayout2]) @@ -234,7 +236,7 @@ def testRenderTilesError(self): result = str(serializer) self.assertIn('This is a demo tile with id tile2', result) self.assertNotIn('This is a demo tile with id tile3', result) - self.assertIn('There was an error while rendering this tile', result) + self.assertIn('There was an error', result) self.assertIn('This is a demo tile with id tile4', result) def testRenderSubTiles(self): diff --git a/plone/app/blocks/utils.py b/plone/app/blocks/utils.py index a9676922..eafae97e 100644 --- a/plone/app/blocks/utils.py +++ b/plone/app/blocks/utils.py @@ -74,7 +74,7 @@ def resolve(url, resolved=None): resolved = resolveResource(url) except Exception: logger.exception( - 'Error while trying to resolve tile: {0}'.format( + 'There was an error while resolving the tile: {0}'.format( url, ), ) @@ -88,7 +88,7 @@ def resolve(url, resolved=None): From 9eb351ae9fe45f572f49c63579a5da09b20a0e25 Mon Sep 17 00:00:00 2001 From: MrTango Date: Tue, 2 Jul 2019 14:31:13 +0300 Subject: [PATCH 4/6] Update buildout config --- buildout.cfg | 2 +- test-5.2.x.cfg | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/buildout.cfg b/buildout.cfg index 9960ae37..8ef20284 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -1,6 +1,6 @@ [buildout] extends = - test-x.x.x.cfg + test-5.2.x.cfg package-name = plone.app.blocks package-extras = [test] diff --git a/test-5.2.x.cfg b/test-5.2.x.cfg index f3d1b76d..8d9ac3c8 100644 --- a/test-5.2.x.cfg +++ b/test-5.2.x.cfg @@ -7,9 +7,17 @@ parts += createcoverage extensions = mr.developer -auto-checkout = +auto-checkout = plone.subrequest + +[remotes] +plone = https://github.com/plone +plone-push = git+ssh://git@github.com/plone +collective = https://github.com/collective +collective-push = git+ssh://git@github.com/collective [sources] +plone.subrequest = git ${remotes:plone}/plone.subrequest.git pushurl=${remotes:plone-push}/plone.subrequest.git + [versions] setuptools = From 98557403d5541e849844bf3a9113f5f1477a6f52 Mon Sep 17 00:00:00 2001 From: MrTango Date: Tue, 2 Jul 2019 17:52:31 +0300 Subject: [PATCH 5/6] fix test --- plone/app/blocks/tests/test_tiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plone/app/blocks/tests/test_tiles.py b/plone/app/blocks/tests/test_tiles.py index 84a702f7..3a8d7711 100644 --- a/plone/app/blocks/tests/test_tiles.py +++ b/plone/app/blocks/tests/test_tiles.py @@ -226,7 +226,7 @@ def testRenderTiles(self): self.assertIn('This is a demo tile with id tile2', result) self.assertIn('This is a demo tile with id tile3', result) self.assertIn('This is a demo tile with id tile4', result) - self.assertIn('Umlauts: Übertile', result) + self.assertIn(u'Umlauts: Übertile', result) def testRenderTilesError(self): serializer = getHTMLSerializer([testLayout2]) From 0aeaa53c39f06022d8b588c2f7658c14ced1bac5 Mon Sep 17 00:00:00 2001 From: MrTango Date: Tue, 2 Jul 2019 20:41:51 +0300 Subject: [PATCH 6/6] fix test for py2/3 --- plone/app/blocks/tests/test_tiles.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plone/app/blocks/tests/test_tiles.py b/plone/app/blocks/tests/test_tiles.py index 3a8d7711..f245434c 100644 --- a/plone/app/blocks/tests/test_tiles.py +++ b/plone/app/blocks/tests/test_tiles.py @@ -13,6 +13,13 @@ import unittest +try: + # Python 2: "unicode" is built-in + unicode +except NameError: + unicode = str + + class ITestTile(Interface): magicNumber = schema.Int(title=u"Magic number", required=False) @@ -222,11 +229,11 @@ def testRenderTiles(self): request = self.layer['request'] tree = serializer.tree renderTiles(request, tree) - result = str(serializer) + result = unicode(serializer) self.assertIn('This is a demo tile with id tile2', result) self.assertIn('This is a demo tile with id tile3', result) self.assertIn('This is a demo tile with id tile4', result) - self.assertIn(u'Umlauts: Übertile', result) + self.assertIn(u'Umlauts: \xdcbertile', result) def testRenderTilesError(self): serializer = getHTMLSerializer([testLayout2])