@@ -393,19 +393,15 @@ def CaptureNamedVariable(self, name, value, depth, limits):
393393 Returns:
394394 Formatted captured data as per Variable proto with name.
395395 """
396- try :
397- if not hasattr (name , '__dict__' ):
398- name = str (name )
399- else : # TODO(vlif): call str(name) with immutability verifier here.
400- name = str (id (name ))
401- self ._total_size += len (name )
402-
403- v = (self .CheckDataVisiblity (value ) or
404- self .CaptureVariable (value , depth , limits ))
405- v ['name' ] = name
406- except RuntimeError as e :
407- raise RuntimeError (
408- 'INTERNAL ERROR while capturing {0}: {1}' .format (name , e ))
396+ if not hasattr (name , '__dict__' ):
397+ name = str (name )
398+ else : # TODO(vlif): call str(name) with immutability verifier here.
399+ name = str (id (name ))
400+ self ._total_size += len (name )
401+
402+ v = (self .CheckDataVisiblity (value ) or
403+ self .CaptureVariable (value , depth , limits ))
404+ v ['name' ] = name
409405 return v
410406
411407 def CheckDataVisiblity (self , value ):
@@ -451,57 +447,39 @@ def CaptureVariablesList(self, items, depth, empty_message, limits):
451447 List of formatted variable objects.
452448 """
453449 v = []
454- try :
455- for name , value in items :
456- if (self ._total_size >= self .max_size ) or (
457- len (v ) >= limits .max_list_items ):
458- v .append ({
459- 'status' : {
460- 'refers_to' : 'VARIABLE_VALUE' ,
461- 'description' : {
462- 'format' :
463- ('Only first $0 items were captured. Use in an '
464- 'expression to see all items.' ),
465- 'parameters' : [str (len (v ))]}}})
466- break
467- v .append (self .CaptureNamedVariable (name , value , depth , limits ))
450+ for name , value in items :
451+ if (self ._total_size >= self .max_size ) or (
452+ len (v ) >= limits .max_list_items ):
453+ v .append ({
454+ 'status' : {
455+ 'refers_to' : 'VARIABLE_VALUE' ,
456+ 'description' : {
457+ 'format' :
458+ ('Only first $0 items were captured. Use in an '
459+ 'expression to see all items.' ),
460+ 'parameters' : [str (len (v ))]}}})
461+ break
462+ v .append (self .CaptureNamedVariable (name , value , depth , limits ))
463+
464+ if not v :
465+ return [{'status' : {
466+ 'is_error' : False ,
467+ 'refers_to' : 'VARIABLE_NAME' ,
468+ 'description' : {'format' : empty_message }}}]
468469
469- if not v :
470- return [{'status' : {
471- 'is_error' : False ,
472- 'refers_to' : 'VARIABLE_NAME' ,
473- 'description' : {'format' : empty_message }}}]
474- except RuntimeError as e :
475- raise RuntimeError (
476- 'Failed while capturing variables: {0}\n '
477- 'The following elements were successfully captured: {1}' .format (
478- e , ', ' .join ([c ['name' ] for c in v if 'name' in c ])))
479470 return v
480471
481472 def CaptureVariable (self , value , depth , limits , can_enqueue = True ):
482473 """Try-Except wrapped version of CaptureVariableInternal."""
483474 try :
484475 return self .CaptureVariableInternal (value , depth , limits , can_enqueue )
485- except RuntimeError as e :
486- # Record as an error in the variable, and continue iterating.
487- return {
488- 'status' : {
489- 'is_error' : True ,
490- 'refers_to' : 'VARIABLE_VALUE' ,
491- 'description' : {
492- 'format' : 'Failed while capturing variable: $0' ,
493- 'parameters' : [str (e )]
494- }
495- }
496- }
497476 except BaseException as e : # pylint: disable=broad-except
498- # Record as an internal error in the variable, and continue iterating.
499477 return {
500478 'status' : {
501479 'isError' : True ,
480+ 'refersTo' : 'VARIABLE_VALUE' ,
502481 'description' : {
503- 'format' : ('INTERNAL ERROR: Failed while capturing '
504- 'variable: $0: $1' ),
482+ 'format' : ('Failed to capture variable: $0' ),
505483 'parameters' : [str (e )]
506484 }
507485 }
0 commit comments