-
-
Notifications
You must be signed in to change notification settings - Fork 440
Add ability to return errors from custom functions. #159
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
Add ability to return errors from custom functions. #159
Conversation
Also provide initial documentation on using and providing functions.
Awesome Work! Nice with tests! But why current method is not okay? You can just panic in custom func. |
Thank you for your comment. While true that panic's will also return errors it is not always useful. For example there could be cases when "panic" is forbidden by style-guide. Also checking for returned error message instead of it's type or behavior is not the best approach either. I learned that it is useful to re-use already existing functions in the environment, but in some(if not most) cases such functions/methods can also return error to specify is something went wrong. Leaving out the error in such case could lead to unpredictable results of expression evaluation. It will also be possible to check if the error is from compiling or running stage(like types mismatch) or from the functions that are being called in expression. In such case if error is And most useful feature would be to preserve the context of the error, such as its type. Consider this example:
While it is simple and crude example, it shows that this approach can be used to get error type and even capture context in a type that implements |
This is a great argument. Give me some time to review your PR. |
Hello, Sorry to bother, but have you had any time to check this out? |
I still need time to review it, as change is quite big. |
Any progress on this PR? |
Will try to have a look on this weekend. Sorry for a delay. |
Hi @antonmedv is there any issue with this PR? |
Sorry for a loooong delay)) |
vm.push(fn.(func(...interface{}) interface{})(in...)) | ||
if typed, ok := fn.(func(...interface{}) interface{}); ok { | ||
vm.push(typed(in...)) | ||
} else if typed, ok := fn.(func(...interface{}) (interface{}, error)); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CallFast is a special case. We don't want to change the signature of call fast methods. The idea for call fast funcs is what they are created manually for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't change it here, but rather allowing to add a new one, that also returns an error.
So both variants will work.
Also provide initial documentation on using and providing functions.