-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
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 error msg 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 a AbortTransaction Exception from the script I can't pass any message.
Database changes
None.
External dependencies
None.