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

rust error callback #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mikea
Copy link

@mikea mikea commented Sep 16, 2024

Introduce ::rust::throw_rust_error callback of void (const char*, size_t) type. The callback is used every time rust functions returns Result::Err (or triggers panic with #2).

We will use the callback in workerd/edgeworker to integrate with kj::Exception

@mikea mikea force-pushed the maizatskyi/2024-09-16-throw-hook branch 3 times, most recently from 06f80db to fbd1361 Compare September 16, 2024 20:53
@mikea mikea marked this pull request as ready for review September 16, 2024 20:57
@mikea mikea force-pushed the maizatskyi/2024-09-16-throw-hook branch 2 times, most recently from d08f7cf to c52ee16 Compare September 17, 2024 18:09
writeln!(out, " return error;");
writeln!(out, " error.msg = msg;");
writeln!(out, " error.len = len;");
writeln!(out, " throw error;");
Copy link
Member

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.)?

Copy link
Author

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;");

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?

Copy link
Author

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

@mikea mikea force-pushed the maizatskyi/2024-09-16-throw-hook branch 2 times, most recently from 53592d9 to 7a3f0c6 Compare September 23, 2024 15:35
@mikea mikea requested review from kornelski and kentonv September 23, 2024 15:58
@kentonv
Copy link
Member

kentonv commented Sep 25, 2024

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
@mikea mikea force-pushed the maizatskyi/2024-09-16-throw-hook branch from 7a3f0c6 to 5bc06cc Compare October 3, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants