kou commented on code in PR #36517:
URL: https://github.com/apache/arrow/pull/36517#discussion_r1263416226


##########
cpp/src/arrow/flight/types.h:
##########
@@ -834,5 +837,129 @@ class ARROW_FLIGHT_EXPORT SimpleResultStream : public 
ResultStream {
   size_t position_;
 };
 
+/// \defgroup flight-error Error Handling
+/// Types for handling errors from RPCs.  Flight uses a set of status
+/// codes standardized across Flight implementations, so these types
+/// let applications work directly with those codes instead of having
+/// to translate to and from Arrow Status.
+
+/// \brief Abstract status code for an RPC as per the Flight
+///   specification.
+enum class TransportStatusCode {
+  // TODO: document meanings
+  kOk = 0,
+  kUnknown = 1,
+  kInternal = 2,
+  kInvalidArgument = 3,
+  kTimedOut = 4,
+  kNotFound = 5,
+  kAlreadyExists = 6,
+  kCancelled = 7,
+  kUnauthenticated = 8,
+  kUnauthorized = 9,
+  kUnimplemented = 10,
+  kUnavailable = 11,
+};
+
+std::string ToString(TransportStatusCode code);
+
+/// \brief An error from an RPC call, using Flight error codes
+///   directly instead of trying to translate to Arrow Status.
+///
+/// Client-side errors (i.e., internal to the client-side Flight
+/// implementation) may use the code kInternal or kUnimplemented, or
+/// may be attached in details.
+class ARROW_FLIGHT_EXPORT TransportStatus : public 
util::ToStringOstreamable<Status> {
+ public:
+  /// \brief Construct an empty OK status.
+  TransportStatus();
+  explicit TransportStatus(TransportStatusCode code);
+  explicit TransportStatus(TransportStatusCode code, std::string message);
+  explicit TransportStatus(TransportStatusCode code, std::string message,
+                           std::vector<std::unique_ptr<StatusDetail>> details);
+
+  /// \brief Is this status an error or not.
+  bool ok() const { return impl_ == NULLPTR; }
+
+  /// \brief Get the code.
+  TransportStatusCode code() const {
+    return impl_ ? impl_->code : TransportStatusCode::kOk;
+  }
+
+  /// \brief Get the message.
+  const std::string& message() const {
+    static std::string kEmpty;
+    return impl_ ? impl_->message : kEmpty;
+  }
+
+  /// \brief Move the message (mutates the status).
+  std::string MoveMessage() && { return impl_ ? std::move(impl_->message) : 
""; }
+
+  /// \brief Get the details.
+  const std::vector<std::unique_ptr<StatusDetail>>& details() const {
+    static std::vector<std::unique_ptr<StatusDetail>> kEmpty;
+    return impl_ ? impl_->details : kEmpty;
+  }
+
+  /// \brief Stringify the status.
+  std::string ToString() const;
+
+  /// \brief Convert an abstract transport status to a C++ status.
+  Status ToStatus() const;
+
+  /// \brief Convert a C++ status to an abstract transport status.
+  static TransportStatus FromStatus(const Status& arrow_status);
+
+  /// \brief Reconstruct a string-encoded TransportStatus.
+  static TransportStatus FromCodeStringAndMessage(const std::string& code_str,
+                                                  std::string message);
+
+ private:
+  struct Impl {
+    explicit Impl(TransportStatusCode code, std::string message,
+                  std::vector<std::unique_ptr<StatusDetail>> details);
+    TransportStatusCode code;
+    std::string message;
+    std::vector<std::unique_ptr<StatusDetail>> details;
+  };
+  std::unique_ptr<Impl> impl_;
+};
+
+/// \brief Additional server-provided binary error metadata.  This is
+///   meant for servers to provide rich error information using a format
+///   like Protocol Buffers for sophisticated API clients.
+class BinaryStatusDetail : public StatusDetail {
+ public:
+  constexpr static const char* kTypeId = "flight::BinaryStatusDetail";
+  explicit BinaryStatusDetail(std::string details) : 
details_(std::move(details)) {}
+  const char* type_id() const override { return kTypeId; }
+  std::string ToString() const override;
+
+  std::string_view details() const { return details_; }
+  std::string&& MoveDetails() && { return std::move(details_); }
+
+ private:
+  std::string details_;
+};
+
+/// \brief An Arrow Status, generated by the client-side Flight
+///   implementation (this generally means the server sent something
+///   out-of-spec, like invalid Arrow data) or sent by a synchronous
+///   C++ server implementation.
+class ArrowStatusDetail : public StatusDetail {
+ public:
+  constexpr static const char* kTypeId = "flight::ArrowStatusDetail";
+  explicit ArrowStatusDetail(Status status) : status_(std::move(status)) {}
+  const char* type_id() const override { return kTypeId; }
+  std::string ToString() const override;
+
+  const Status& status() const { return status_; }
+
+ private:
+  arrow::Status status_;
+};
+
+/// @}
+

Review Comment:
   ```suggestion
   ```



-- 
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-unsubscr...@arrow.apache.org

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

Reply via email to