[ https://issues.apache.org/jira/browse/ARROW-13956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17412386#comment-17412386 ]
Junwang Zhao commented on ARROW-13956: -------------------------------------- hi [~apitrou], could you pls review this issue, I came up with this when I see this kind of using in [0], thought it might be better if we provide this macro. [0]: https://github.com/apache/arrow/pull/10991/files/5ca6aa26b84d9fd89384032383c36bd48259e60b# > [C++] Add a RETURN_NOT_OK_ELSE_WITH_STATUS macro to support changing the > Status > ------------------------------------------------------------------------------- > > Key: ARROW-13956 > URL: https://issues.apache.org/jira/browse/ARROW-13956 > Project: Apache Arrow > Issue Type: Improvement > Components: C++ > Reporter: Junwang Zhao > Assignee: Junwang Zhao > Priority: Minor > Labels: pull-request-available > Time Spent: 10m > Remaining Estimate: 0h > > As Result<T> is encourged to be used, it's better to supply a Marcro to > change the internal Status. We could do this by using RETURN_NOT_OK_ELSE, > one example is: > > {code:java} > auto reader = arrow::adapters::orc::ORCFileReader::Open(input, pool); > RETURN_NOT_OK_ELSE(reader, _s.WithMessage("Could not open ORC input source > '", source.path(), "': ", _s.message())); > return reader; > {code} > but it's ugly since it use the _s of the macro. > > Recommend fix: > Add a macro RETURN_NOT_OK_ELSE_WITH_STATUS: > {code:java} > // Use this when you want to change the status in else_ expr > #define RETURN_NOT_OK_ELSE_WITH_STATUS(s, _s, else_) \ > do { \ > ::arrow::Status _s = ::arrow::internal::GenericToStatus(s); \ > if (!_s.ok()) { \ > else_; \ > return _s; \ > } \ > } while (false) > {code} > And the following statements are more natural > > {code:java} > auto reader = arrow::adapters::orc::ORCFileReader::Open(input, pool); > RETURN_NOT_OK_ELSE_WITH_STATUS(reader, status, status.WithMessage("Could not > open ORC input source '", source.path(), "': ", status.message())); > return reader; > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)