Skip to content

Conversation

@rpatters1
Copy link
Contributor

I've been using Stack<>::get to pull values off the Lua stack inside proxy constructors. When I pass in the wrong types, it is producing the generic error message std::exception.

A way to fix this appears to be to implement the what method, so that's what this PR does. I am opening it as a draft for comment, because there may be ramifications I don't know about. I tried returning error_.message().c_str() but that produced a garbage error message. Hence the new msg_ member variable.

@kunitoki
Copy link
Owner

kunitoki commented Apr 4, 2023

We can't assume E is an error_code. We need to pass a message string to std::exception instead

@rpatters1
Copy link
Contributor Author

We need to pass a message string to std::exception instead.

That sounds like an excellent plan. Where does it come from if not from E? Or, put another way, is it ever acceptable not to have an error message?

@rpatters1
Copy link
Contributor Author

Okay, the string is now being passed in. It is not an optional parameter because I don't think we should ever throw a raw std::exception with no error message. But I don't know what the ramifications might be outside LB3 itself.

@rpatters1 rpatters1 force-pushed the RGP/add-message-to-BadExpectedAccess branch from 861ec34 to 05aa811 Compare April 5, 2023 21:21
@rpatters1 rpatters1 force-pushed the RGP/add-message-to-BadExpectedAccess branch from 05aa811 to 85d119b Compare April 5, 2023 23:16
@rpatters1 rpatters1 marked this pull request as ready for review April 5, 2023 23:18
#if LUABRIDGE_HAS_EXCEPTIONS
if (!hasValue())
throw BadExpectedAccess<E>(error());
throw BadExpectedAccess<E>(error(), error().message());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E is a templated class and can be anything. Here you are assuming is has a "message" method. We should solve it differently, using a detector on the E::message method (or eventually a to_string(E)) free function on the type if defined, inside the BadExpectedAccess constructor.

@kunitoki
Copy link
Owner

kunitoki commented Apr 5, 2023

Got an alternative one which doesn't create issues if you use an E error type without a message method.

See #110

@rpatters1 rpatters1 closed this Apr 6, 2023
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.

2 participants