-
Notifications
You must be signed in to change notification settings - Fork 24
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
Avoid panics #14
Comments
Adding a check and returning a specific error instead of a panic would indeed be possible. |
Perhaps some special mode (e.g. you can call it safe or limited) where only those actions will be performed that are guaranteed not to cause panic, but only throw an error, would be a good solution. eval := goval.NewSafeEvaluator()
result, err := eval.Evaluate("2 / 0") |
It is possible to ensure called functions do not panic, because the functions do not originate from this module and are added at the application developer's discretion.
The evaluated expression may be something entered by a user, and there is no good way to check if the user input contains divisions by zero without re-implementing the functionality in this module. The expected behavior of a program in this scenario is to display a readable error to the user, not a panic, which would be far less awkward if Evaluate returned a division by zero error. |
Detecting division by zero sounds reasonable. I'll take a look at it once I have some spare time. |
A fairly trivial check of division by zero causes panic. Do you plan any protection against such cases? And a way to avoid panics?
The text was updated successfully, but these errors were encountered: