This kind of approach is sometimes used as an error guard on an iRODS api call and its possible consequence, the raising of an iRODSException due to a fatal error of some sort during the server operation :
import irods.exception as ex
try:
value = ses.data_objects.replica_truncate(path, length)
except ex.iRODSException as e:
logging.getLogger().info(returned server code = %d',e.code)
print ('Exception during replica_truncate: {!r}'.format(e))
#raise # (... only if we want to abort)
Two possible cases arise:
the API call runs with no fatal error (error code of 0) and returns normally, with return value possibly deriving from som information in the raw response message from the server (replica_truncate actually extracts only the returned JSON message in the form of a Python dict, from the server's returning message
an error occurs that results in the API call returning a nonzero error code , indicating a fatal error occurred, in which case currently msg cannot be returned.
However it turns out the designer of the server API in question (true for replica_truncate in particular) may wish to convey information and/or some error message, for example a JSON string contained in the msg structure, which then should be accessible regardless of the exception being thrown.
We seek some way in which this can be done. In the absence of a better plan, we will attach the msgvalue which would have been returned. Thus we could intercept the returning JSON choose whether to convert it to a data structure for further utilitiy, or simply do this:
This kind of approach is sometimes used as an error guard on an iRODS api call and its possible consequence, the raising of an iRODSException due to a fatal error of some sort during the server operation :
Two possible cases arise:
value
possibly deriving from som information in the raw response message from the server (replica_truncate
actually extracts only the returned JSON message in the form of a Python dict, from the server's returning messagemsg
cannot be returned.However it turns out the designer of the server API in question (true for
replica_truncate
in particular) may wish to convey information and/or some error message, for example a JSON string contained in themsg
structure, which then should be accessible regardless of the exception being thrown.We seek some way in which this can be done. In the absence of a better plan, we will attach the
msg
value which would have been returned. Thus we could intercept the returning JSON choose whether to convert it to a data structure for further utilitiy, or simply do this: