Task #5156 (closed)
Bug: gateway's getPlanes does not handle exceptions.
| Reported by: | jamoore | Owned by: | atarkowska |
|---|---|---|---|
| Priority: | major | Milestone: | OMERO-Beta4.3 |
| Component: | General | Version: | n.a. |
| Keywords: | n.a. | Cc: | wmoore |
| Resources: | n.a. | Referenced By: | n.a. |
| References: | n.a. | Remaining Time: | 0.0d |
| Sprint: | 2011-05-19 (12) |
Description
In [ab7842f2b19e7120375b278589493dbd6b20aea7/ome.git] a try/finally was removed from a generator and replaced by except:pass which would swallow any exceptions.
try:
for zct in zctList:
z,c,t = zct
rawPlane = rawPixelsStore.getPlane(z, c, t)
convertedPlane = unpack(convertType, rawPlane)
remappedPlane = numpy.array(convertedPlane, numpyType)
remappedPlane.resize(sizeY, sizeX)
yield remappedPlane
except:
pass
rawPixelsStore.close()
The proper idiom (though ugly) is probably:
svc = createService()
exc = None
try:
yield svc.method()
except exceptions.Exception, e:
exc = e
try:
svc.close()
except exceptions.Exception, e:
if exc is None:
exc = e
else:
log.error(e)
if exc is not None:
raise exc
We may want to create a method or decorator to handle this logic if it will be used frequently.
Change History (8)
comment:1 Changed 8 years ago by jmoore <josh@…>
comment:2 Changed 8 years ago by atarkowska
- Remaining Time set to 0.1
comment:3 Changed 8 years ago by atarkowska
- Status changed from new to accepted
comment:4 Changed 8 years ago by Aleksandra Tarkowska <aleksandrat@…>
- Remaining Time changed from 0.1 to 0
- Resolution set to fixed
- Status changed from accepted to closed
(In [ff2f002cec81ad8cfebc396b0b41bb9fbfec96f0/ome.git] on branch develop) this fixes #5156
comment:5 Changed 8 years ago by jmoore
- Remaining Time changed from 0 to 0.25
- Resolution fixed deleted
- Status changed from closed to reopened
Running tests the there is still an error:
~/git/components/tools/OmeroPy $ python test/gatewaytest/pixels.py PixelsTest.testGetPlanesExceptionOnClose
Traceback (most recent call last):
File "test/gatewaytest/pixels.py", line 169, in testGetPlanesExceptionOnClose
for x in pixels.getPlanes(((0,0,0), (1,1,1))):
File "/Users/moore/git/components/tools/OmeroPy/build/lib/omero/gateway/__init__.py", line 4422, in getTiles
except exceptions.Exception, e:
NameError: global name 'exceptions' is not defined
E
======================================================================
ERROR: testGetPlanesExceptionOnClose (__main__.PixelsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/gatewaytest/pixels.py", line 177, in testGetPlanesExceptionOnClose
self.assert_(e.close)
AttributeError: 'exceptions.NameError' object has no attribute 'close'
----------------------------------------------------------------------
Ran 1 test in 3.931s
FAILED (errors=1)
to get the extra print out of the internal stack trace I added this temporarily:
~/git/components/tools/OmeroPy $ git diff .
diff --git a/components/tools/OmeroPy/test/gatewaytest/pixels.py b/components/tools/OmeroPy/test/gatewaytest/pixels.py
index ae102ee..27f08e7 100644
--- a/components/tools/OmeroPy/test/gatewaytest/pixels.py
+++ b/components/tools/OmeroPy/test/gatewaytest/pixels.py
@@ -172,6 +172,8 @@ class PixelsTest (lib.GTest):
except AssertionError:
raise
except exceptions.Exception, e:
+ import traceback as tb
+ tb.print_exc()
self.assert_(e.close)
self.assertEquals(2, found)
comment:6 Changed 8 years ago by Aleksandra Tarkowska <aleksandrat@…>
(In [8bb57f3e15ba21ef45d8ec35af7ebe80879c3b5f/ome.git] on branch develop) this fixes NameError?: global name 'exceptions' is not defined, see #5156
comment:7 Changed 8 years ago by atarkowska
- Remaining Time changed from 0.25 to 0
- Status changed from reopened to closed
comment:8 Changed 8 years ago by Will Moore <will@…>
(In [bb26971090ff3236cdff05af9b0f24fe3f1b3bf1/ome.git] on branch develop) Better error reporting for pixelWrapper.getTiles(). See #5151, #5156
(In [500817cb70e05b2f69017cc9131e484c0cfbd9af/ome.git] on branch develop) Adding tests showing expected behavior of try/except (See #5156)