@@ -337,7 +337,8 @@ class BaseDebugWrapperSession(session.SessionInterface):
337337 # TODO(cais): Add on_cont_start and on_cont_end callbacks once the stepper is
338338 # is available.
339339
340- def __init__ (self , sess , thread_name_filter = None ):
340+ def __init__ (self , sess , thread_name_filter = None ,
341+ pass_through_operrors = False ):
341342 """Constructor of `BaseDebugWrapperSession`.
342343
343344 Args:
@@ -349,6 +350,8 @@ def __init__(self, sess, thread_name_filter=None):
349350 by applying the `match` method of the compiled pattern. The default
350351 `None` means that the wrapper session will be active on all threads.
351352 E.g., r"MainThread$", r"QueueRunnerThread.*".
353+ pass_through_operrors: If True, all captured OpErrors will be
354+ propagated. By default this captures all OpErrors.
352355
353356 Raises:
354357 ValueError: On invalid `OnSessionInitAction` value.
@@ -361,6 +364,8 @@ def __init__(self, sess, thread_name_filter=None):
361364 self ._sess = sess
362365 self ._thread_name_filter_pattern = (re .compile (thread_name_filter )
363366 if thread_name_filter else None )
367+ # TODO(cais/kstevens): Unittest this pass through feature.
368+ self ._pass_through_operrors = pass_through_operrors
364369
365370 # Keeps track of number of run calls that have been performed on this
366371 # debug-wrapper session. The count can be used for purposes such as
@@ -480,6 +485,8 @@ def run(self,
480485 options = decorated_run_options ,
481486 run_metadata = run_metadata )
482487 except errors .OpError as op_error :
488+ if self ._pass_through_operrors :
489+ raise op_error
483490 tf_error = op_error
484491 retvals = op_error
485492
@@ -783,7 +790,8 @@ def __repr__(self):
783790class NonInteractiveDebugWrapperSession (BaseDebugWrapperSession ):
784791 """Base class for non-interactive (i.e., non-CLI) debug wrapper sessions."""
785792
786- def __init__ (self , sess , watch_fn = None , thread_name_filter = None ):
793+ def __init__ (self , sess , watch_fn = None , thread_name_filter = None ,
794+ pass_through_operrors = False ):
787795 """Constructor of DumpingDebugWrapperSession.
788796
789797 Args:
@@ -802,12 +810,15 @@ def __init__(self, sess, watch_fn=None, thread_name_filter=None):
802810 thread_name_filter: Regular-expression white list for threads on which the
803811 wrapper session will be active. See doc of `BaseDebugWrapperSession` for
804812 more details.
813+ pass_through_operrors: If true, all captured OpErrors will be
814+ propagated. By default this captures all OpErrors.
805815 Raises:
806816 TypeError: If a non-None `watch_fn` is specified and it is not callable.
807817 """
808818
809819 BaseDebugWrapperSession .__init__ (
810- self , sess , thread_name_filter = thread_name_filter )
820+ self , sess , thread_name_filter = thread_name_filter ,
821+ pass_through_operrors = pass_through_operrors )
811822
812823 self ._watch_fn = None
813824 if watch_fn is not None :
0 commit comments