-
Notifications
You must be signed in to change notification settings - Fork 1
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
rust error callback #4
base: master
Are you sure you want to change the base?
Conversation
06f80db
to
fbd1361
Compare
d08f7cf
to
c52ee16
Compare
writeln!(out, " return error;"); | ||
writeln!(out, " error.msg = msg;"); | ||
writeln!(out, " error.len = len;"); | ||
writeln!(out, " throw error;"); |
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.
This seems to throw a value of type Error
... but don't we want to convert to a kj::Exception
and throw it with kj::throwFatalException()
(which adds stack traces, etc.)?
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 will set our own throw_rust_error
callback that will do kj::throw
. This function is used only if callback is not overriden
writeln!(out, " error.msg = static_cast<char const *>(repr.ptr);"); | ||
writeln!(out, " error.len = repr.len;"); | ||
writeln!(out, " return error;"); | ||
writeln!(out, " error.msg = msg;"); |
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.
what's the lifetime/ownership of msg
? Is it pointing to Rust-owned memory?
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.
I have added a comment to cxx.h (not sure what's the best place for it): it points to c++ memory and will belong to c++.
https://github.com/cloudflare/workerd-cxx/blob/master/src/result.rs#L60
53592d9
to
7a3f0c6
Compare
Well I don't really know what's going on here but it seems plausible. :) Sorry for slow review, been swamped. |
Rather then throw things directly, introduce a global callback. We will override the callback in workerd to integrate with kj::Exception
7a3f0c6
to
5bc06cc
Compare
Introduce
::rust::throw_rust_error
callback ofvoid (const char*, size_t)
type. The callback is used every time rust functions returnsResult::Err
(or triggers panic with #2).We will use the callback in workerd/edgeworker to integrate with kj::Exception