Floris Bruynooghe committed 87c21bd

Add MibOperationError patch to keep track of idx and name

  • Participants
  • Parent commits 59b9085

Comments (0)

Files changed (2)


+# HG changeset patch
+# Parent 270f97b6b3dd6e8856faca2ac8be90a6ce23be07
+# User Floris Bruynooghe <>
+# Date 1324249337 -3600
+Tweak exceptions from MIB operations
+Normally if the SMI instrumentation code has an error it needs to
+raise a MibOperationError (or subclass) with the idx and name
+attributes based on one of the parameters.  However it can be
+cumbersome in the intrumentation code to keep passing around those
+parameters while it is perfectly possible for the calling code to keep
+track of this.  This patch takes this burden from the instrumentation
+code and places it in the MibInstrumController to keep track of this.
+Implementations just need to raise the correct exception.
+diff --git a/pysnmp/smi/ b/pysnmp/smi/
+--- a/pysnmp/smi/
++++ b/pysnmp/smi/
+@@ -212,6 +212,11 @@ class MibInstrumController:
+                     debug.logger & debug.flagIns and debug.logger('flipFlopFsm: fun %s failed %s for %s=%r' % (f, sys.exc_info()[1], name, val))
+                     if myErr is None:  # Take the first exception
+                         myErr = sys.exc_info()
++                        if isinstance(myErr[0], error.MibOperationError):
++                            if 'idx' not in myErr[0]:
++                                myErr[0].update(idx=idx)
++                            if 'name' not in myErr[0]:
++                                myErr[0].update(name=tuple(name))
+                     status = 'err'
+                     break
+                 else:
 # Placed by Bitbucket