MDSplus / mdsplus

The MDSplus data management system
https://mdsplus.org/
Other
71 stars 43 forks source link

Is it possible to throw custom errors in TDI? #2403

Open merlea opened 2 years ago

merlea commented 2 years ago

Hello,

I wonder if it is possible to throw custom errors in TDI?

For example on TCV some nodes rely on the execution of a custom TDI function and in some cases we would like to pass the information that something has gone wrong. We usually just returned a string with the error message but this means that the user has to check both that the returned status is OK and that the returned values is not a string (which becomes cumbersome when you are expecting a string back) - we usually almost exclusively work in a thin client configuration.

Thanks, Antoine.

merlea commented 2 years ago

So I have just come across the abort() statement in TDI.

I guess what we are looking for is something similar but where we could insert the desired error status, which we could add to one of the *_messages.xml file.

Would it maybe be possible to do similar things calling a Python function from the TDI interpreter?

joshStillerman commented 2 years ago

We have not generalized this facility so that the list of message sources is extensible. However, I created ~/mdsplus/tmp/custom_messages.xml:

~/mdsplus$ cat tmp/custom_messages.xml 
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- 
Copyright (c) 2017, Massachusetts Institute of Technology All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<messages>
  <facility name="Custom" value="99">
    <status name="NORMAL" value="1" severity="Success" text="Normal successful completion"/>
    <status name="FAILED" value="2" severity="Warning" text="Something bad happened"/>
  </facility>
</messages>

and then ran:

jas@mfews09:~/mdsplus$ python deploy/gen_messages.py
camshr_messages.xml
mdsdcl_messages.xml
mdsshr_messages.xml
mitdevices_messages.xml
servershr_messages.xml
tcl_messages.xml
tdishr_messages.xml
treeshr_messages.xml
custom_messages.xml

and it created:

include/custom_messages.h

and added the custom messages to: ./python/MDSplus/mdsExceptions.py It is this last part that is not 'extensible' since that file is part of the MDSplus distribution.

You could then chop the part of it that you need out, or include the modified version of it in you mdsplus python source.

WhoBrokeTheBuild commented 1 year ago

While reviewing old tickets we've discussed this again, and believe the above suggestion is not good as it relies on internals of the build system. Instead we recommend catching the error conditionally in TDI and returning a string containing the error. Then you can check for that in the caller.