-
Notifications
You must be signed in to change notification settings - Fork 10
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
Graceful error handling for host function calls from guest modules #89
base: main
Are you sure you want to change the base?
Conversation
After discussing with @zshipko I've changed the approach to use the existing So long as guests always check for host errors after host function calls, and hosts always check for guest errors after guest function calls (which should be happening already as I understand it), then we would never see a conflict. My assumption is that outdated PDKs that do not support this functionality will result in this PR having no effect since they would simply not know to call |
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.
Love it! I will wait for @zshipko to give it another look, thanks for the PR!
@mhmd-azeez thanks! Addressed all feedback. |
This commit is a rough example of a possible solution to the problem discussed in office hour today -- specifically that if a guest PDK does not know to check and reset an error set by a host function, then the host will see its own error when it checks here Line 529 in bef00f3
|
Hey thanks for digging into this! After discussing this with the team we're a little hesitant about the potentially large blast radius of this change and unsure about using special characters in error messages to signal intent. I don't think there is a good way to handle backwards compatibility if we're changing the semantics around error messages. Something closer to the posix errno API might be a better fit for Extism. Adding Additionally, if you're open to using an XTP schema to define your plugin interfaces you could use it to allow your plugin authors to stay up to date by leveraging the code generation. This would mean that changing the plugin interface to allow error messages as part of the call output could be added to your existing API without too much disruption! |
@zshipko ultimately, if this is something that extism does not want to support, regardless of the implementation, then I understand. Current Implementation
It's certainly possible that I don't understand all the implications of this change, and if you'd like to provide specific examples of how this implementation is not backwards compatible, I can think through those. From my initial work on this, my understanding was that this approach would be backwards compatible. The sentinel values used for denoting the error's source are configurable via environment variables, so a PDK does not have to commit now and forever to a specific sentinel value. In other words the SDK and PDK can dynamically negotiate the sentinel prefix. An errno would be better than nothing, but due to the fact that (1) it's impossible to enumerate all possible errors a PDK might want to through, and (2) err numbers don't communicate anything about the conditions leading up to those error, this solution would not work for our use-case. We have error messages like this
While the errno could communicate the timeout, it could not communicate the HTTP path we were attempting to GET, or the IP address of the target we were requesting from, etc. Vars Approach Next Steps |
This PR is intended to allow Go host modules to return errors to guest module function calls. In order for this to work properly, each of the PDKs also needs to be updated to expose an
extism:host/env
function calledhost_func_get_error
which returns an offset to an error message, or0
if no error was set. Host functions that return an error will save the error message within internal extism host state which is accessible byhost_func_get_error
.See extism/rust-pdk#73