You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "kevingurney (via GitHub)" <gi...@apache.org> on 2023/06/23 20:14:27 UTC

[GitHub] [arrow] kevingurney commented on a diff in pull request #36273: GH-36249: [MATLAB] Create a `MATLAB_ASSIGN_OR_ERROR` macro to mirror the C++ `ARROW_ASSIGN_OR_RAISE` macro

kevingurney commented on code in PR #36273:
URL: https://github.com/apache/arrow/pull/36273#discussion_r1240330406


##########
matlab/src/cpp/arrow/matlab/error/error.h:
##########
@@ -17,19 +17,154 @@
 
 #pragma once
 
-
 #include "arrow/status.h"
 #include "libmexclass/error/Error.h"
 
-#include <string_view>
-
+//
+// MATLAB_ERROR_IF_NOT_OK(expr, id)
+//
+//  --- Description ---
+//
+// A macro used to return an error to MATLAB if the arrow::Status returned
+// by the specified expression is not "OK" (i.e. error).
+//
+// **NOTE**: This macro should be used inside of the static make() member function for a
+//           Proxy class. Use MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT inside of a non-static
+//           Proxy member function.
+//
+// --- Arguments ---
+//
+// lhs - variable name to assign to (e.g. auto array)
+// expr - expression that returns an arrow::Status (e.g. builder.Append(...))
+// id - MATLAB error ID string (const char* - "arrow:matlab:proxy:make:FailedConstruction")
+//
+// --- Example ---
+//
+// MATLAB_ERROR_IF_NOT_OK(builder.Append(...), error::BUILDER_FAILED_TO_APPEND);
+//
 #define MATLAB_ERROR_IF_NOT_OK(expr, id)                               \
     do {                                                               \
         arrow::Status _status = (expr);                                \
         if (!_status.ok()) {                                           \
             return libmexclass::error::Error{(id), _status.message()}; \
         }                                                              \
-    } while (0)
+    } while (0)                                                        \
+
+//
+// MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(expr, context, id)
+//
+//  --- Description ---
+//
+// A macro used to return an error to MATLAB if the arrow::Status returned
+// by the specified expression is not "OK" (i.e. error).
+//
+// **NOTE**: This macro should be used inside of a non-static member function of a
+//           Proxy class which has a libmexclass::proxy::method::Context as an input argument.
+//           Use MATLAB_ERROR_IF_NOT_OK inside of a Proxy static make() member function.
+//
+// --- Arguments ---
+//
+// lhs - variable name to assign to (e.g. auto array)
+// expr - expression that returns an arrow::Status (e.g. builder.Append(...))
+// context - libmexclass::proxy::method::Context context input to a Proxy method
+// id - MATLAB error ID string (const char* - "arrow:matlab:proxy:make:FailedConstruction")
+//
+// --- Example ---
+//
+// MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(builder.Append(...), context, error::BUILDER_FAILED_TO_APPEND);
+//
+// #define MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(expr, context, id)                \
+//     do {                                                                      \
+//         arrow::Status _status = (expr);                                       \
+//         if (!_status.ok()) {                                                  \
+//             context.error = libmexclass::error::Error{id, _status.message()}; \
+//             return;                                                           \
+//         }                                                                     \
+//     } while (0)                                                               \
+
+#define MATLAB_ASSIGN_OR_RAISE_NAME(x, y) \

Review Comment:
   Good point!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org