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

[MATLAB] Integrate the latest libmexclass changes to support error-handling #35914

Closed
sgilmore10 opened this issue Jun 5, 2023 · 1 comment · Fixed by #35918
Closed

[MATLAB] Integrate the latest libmexclass changes to support error-handling #35914

sgilmore10 opened this issue Jun 5, 2023 · 1 comment · Fixed by #35918

Comments

@sgilmore10
Copy link
Member

Describe the enhancement requested

Integrate the latest version of libmexclass (commit 77f3d72) to support error-handling.

Here's an overview of the changes:

  1. Added a simple class called libmexclass::error::Error which has two std::string member properties: id and message.
  2. Added a new field named error to libmexclass::proxy::method::Context. error is a std::optional<libmexclass::error::Error>. Proxy class methods can set this field if an error occurred.
  3. The gateway MEX function checks if error is set. If so, it throws a MATLAB facing error using the id and message stored in error.
  4. To support throwing errors at construction, proxy classes are now required to define a static make function with the following signature: libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments); The output argument libmexclass::proxy::MakeResult is a typedef to std::variant<std::shared_ptr<libmexclass::proxy::Proxy>, libmexclass::error::Error>.

Component(s)

MATLAB

@sgilmore10
Copy link
Member Author

take

@kou kou closed this as completed in #35918 Jun 8, 2023
kou added a commit that referenced this issue Jun 8, 2023
…t error-handling (#35918)

### Rationale for this change
This change integrates the latest version of `mathworks/libmexclass` into the MATLAB interface which enables throwing  MATLAB errors. 

The  [77f3d72](mathworks/libmexclass@77f3d72) in `libmexclass` introduced the following changes:

1. Added a new class called `libmexclass::error::Error`.
2. Added a new field called `error` on the `libmexclass::proxy::method::Context` which is a `std::optional<libmexclass::proxy::Error>`. By default, this is a `std::nullopt`. To make MATLAB throw an error, set this optional. 
3. To support throwing errors at construction, `libmexclass` now requires all `Proxy` subclasses to define a static `make` method: `static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments)`. This workflow is similar to using an `arrow::Result<T>`object. 

Examples of throwing errors in MATLAB can be found on lines [45](https://github.com/mathworks/libmexclass/blob/77f3d72c22a9ddab7b54ba325d757c3e82e57987/example/proxy/Car.cpp#L45) and [94](https://github.com/mathworks/libmexclass/blob/77f3d72c22a9ddab7b54ba325d757c3e82e57987/example/proxy/Car.cpp#L94) in [libmexclass/example/proxy/Car.cpp](https://github.com/mathworks/libmexclass/blob/main/example/proxy/Car.cpp)

### What changes are included in this PR?

1. Pulled in the latest version of `libmexclass`: [77f3d72](mathworks/libmexclass@77f3d72). 
2. Added `static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments)` to `arrow::matlab::proxy::NumericArray<Type>`.
3.  Throw an error when trying to create an unknown proxy class. 

### Are these changes tested?

1. Added a new test class called `tGateway.m` that verifies `libmexclass.proxy.gateway("Create", ...)` errors if given the name of an unknown proxy class.

### Are there any user-facing changes?

No.

* Closes: #35914

Lead-authored-by: Sarah Gilmore <sgilmore@mathworks.com>
Co-authored-by: sgilmore10 <74676073+sgilmore10@users.noreply.github.com>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Co-authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
@kou kou added this to the 13.0.0 milestone Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants