Best way to protect application from script bugs


#1

Suppose you have an arbitrary script with a collection of functions. Inside a chaiscript function, if a function name is mistyped, it can crash the app in which it’s embedded. I don’t really want users to have to put everything inside a try/catch (if that would even work) and am wondering if there are other ways to prevent a broken script from bringing down the main app.


#2

Any error that can happen in ChaiScript can be caught inside the host app. You can get the line number of the error and everything and display that to the user.

I can see a potential issue that makes this issue harder if you are passing around callbacks as std::function<> objects and to some extent you don’t know exactly when and where ChaiScript is being evaluated because this has been hidden from you. I don’t know the exact architecture of you system.

But you’ll want to do something like what I do in main.cpp, and provide the protection and error handling from the C++ side. I suggest you try using something like a Lippincott function for maximum code reuse in your error handling routines.

Example from main.cpp:


ChaiScript script evaluation should have a non-throwing alternative
#3

Actually, pretty much everything other than an “initialize” section (which I can already handle with a try/catch in C++) will happen as a consequence of a callback into the scripting system as the consequence of some real-time event, such as time passing or data arriving and so forth. The issue is not so much informing the user where the error occurred, but rather just not having an error bring down the app. I’m seeing this happen if a script has a reference to a function that is not defined (typically due to a typo).

I could certainly wrap all the callbacks in try/except clauses but these callbacks can happen many thousands of times per second. The thing is, if we know in advance that the code is correct syntactically, then we are much less concerned about this issue.