File tree Expand file tree Collapse file tree 6 files changed +73
-3
lines changed
unhandled_unserializable_error Expand file tree Collapse file tree 6 files changed +73
-3
lines changed Original file line number Diff line number Diff line change @@ -166,9 +166,18 @@ def worker_id(self):
166
166
return self ._worker_id
167
167
168
168
def _serialize_exception (self , exc ):
169
- return protos .RpcException (
170
- message = f'{ type (exc ).__name__ } : { exc .args [0 ]} ' ,
171
- stack_trace = '' .join (traceback .format_tb (exc .__traceback__ )))
169
+ try :
170
+ message = f'{ type (exc ).__name__ } : { exc } '
171
+ except Exception :
172
+ message = (f'Unhandled exception in function. '
173
+ f'Could not serialize original exception message.' )
174
+
175
+ try :
176
+ stack_trace = '' .join (traceback .format_tb (exc .__traceback__ ))
177
+ except Exception :
178
+ stack_trace = ''
179
+
180
+ return protos .RpcException (message = message , stack_trace = stack_trace )
172
181
173
182
async def _dispatch_grpc_request (self , request ):
174
183
content_type = request .WhichOneof ('content' )
Original file line number Diff line number Diff line change
1
+ {
2
+ "scriptFile" : " main.py" ,
3
+ "disabled" : false ,
4
+ "bindings" : [
5
+ {
6
+ "type" : " httpTrigger" ,
7
+ "direction" : " in" ,
8
+ "name" : " req"
9
+ },
10
+ {
11
+ "type" : " http" ,
12
+ "direction" : " out" ,
13
+ "name" : " $return"
14
+ }
15
+ ]
16
+ }
Original file line number Diff line number Diff line change
1
+ import azure .functions as func
2
+
3
+
4
+ class UnserializableException (Exception ):
5
+ def __str__ (self ):
6
+ raise RuntimeError ('cannot serialize me' )
7
+
8
+
9
+ def main (req : func .HttpRequest ) -> str :
10
+ raise UnserializableException ('foo' )
Original file line number Diff line number Diff line change
1
+ {
2
+ "scriptFile" : " main.py" ,
3
+ "disabled" : false ,
4
+ "bindings" : [
5
+ {
6
+ "type" : " httpTrigger" ,
7
+ "direction" : " in" ,
8
+ "name" : " req"
9
+ },
10
+ {
11
+ "type" : " http" ,
12
+ "direction" : " out" ,
13
+ "name" : " $return"
14
+ }
15
+ ]
16
+ }
Original file line number Diff line number Diff line change
1
+ from urllib .request import urlopen
2
+
3
+ import azure .functions as func
4
+
5
+
6
+ def main (req : func .HttpRequest ) -> str :
7
+ image_url = req .params .get ('img' )
8
+ urlopen (image_url ).read ()
Original file line number Diff line number Diff line change @@ -159,6 +159,17 @@ def test_unhandled_error(self):
159
159
# https://github.com/Azure/azure-functions-host/issues/2706
160
160
# self.assertIn('Exception: ZeroDivisionError', r.text)
161
161
162
+ def test_unhandled_urllib_error (self ):
163
+ r = self .webhost .request (
164
+ 'GET' , 'unhandled_urllib_error' ,
165
+ params = {'img' : 'http://example.com/nonexistent.jpg' })
166
+ self .assertEqual (r .status_code , 500 )
167
+
168
+ def test_unhandled_unserializable_error (self ):
169
+ r = self .webhost .request (
170
+ 'GET' , 'unhandled_unserializable_error' )
171
+ self .assertEqual (r .status_code , 500 )
172
+
162
173
def test_return_route_params (self ):
163
174
r = self .webhost .request ('GET' , 'return_route_params/foo/bar' )
164
175
self .assertEqual (r .status_code , 200 )
You can’t perform that action at this time.
0 commit comments