Allow custom scripts to fail gracefully on errors detected by the scripts #11152
Labels
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
NetBox version
v3.3.9
Feature type
Change to existing functionality
Proposed functionality
It would be nice if a custom script (and I guess a report, too), would have the option to throw a special kind of Exception (say
AbortScript (msg: str)
, which stops the script, aborts the DB transaction, and stores the errormsg
so the caller can see the fact that the script was aborted and why.Happy to open a PR to add this into the
_run_script()
function. If there is a way to do this, which I didn't find, I'm more than happy for a pointer :-)Use case
I wrote a scripts which should aid in provisioning things inside our network, which will do some sanity checks and if all is good set up a number of things (prefixes, IPs, sub-interfaces, IPs on them, etc.). The reason to do this inside a script is to do this in an atomic operation, so either the full provision process is done, or nothing is changed at all.
Now I was looking into exiting the script on an error and only found the option to throw any
Exception
which will produce a stack trace of all my internal Exceptions I caught and handled. When I throw aAbortTransaction
Exception from the script I can't pass any message.Database changes
None.
External dependencies
None.
The text was updated successfully, but these errors were encountered: