Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom scripts to fail gracefully on errors detected by the scripts #11152

Closed
BarbarossaTM opened this issue Dec 9, 2022 · 2 comments · Fixed by #11621
Closed

Allow custom scripts to fail gracefully on errors detected by the scripts #11152

BarbarossaTM opened this issue Dec 9, 2022 · 2 comments · Fixed by #11621
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@BarbarossaTM
Copy link
Contributor

BarbarossaTM commented Dec 9, 2022

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.

@BarbarossaTM BarbarossaTM added the type: feature Introduction of new functionality to the application label Dec 9, 2022
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Jan 5, 2023
@jeremystretch
Copy link
Member

Sounds good. It might make sense to use the AbortRequest exception for this.

BarbarossaTM added a commit to BarbarossaTM/netbox that referenced this issue Jan 30, 2023
…cefully

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
@BarbarossaTM
Copy link
Contributor Author

Took the evening an had a look at this and it seems to be rather straight forward. What do you think @jeremystretch?

BarbarossaTM added a commit to BarbarossaTM/netbox that referenced this issue Feb 2, 2023
…cefully

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
jeremystretch pushed a commit that referenced this issue Feb 2, 2023
Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants