pitrou commented on code in PR #36205:
URL: https://github.com/apache/arrow/pull/36205#discussion_r1238773857


##########
cpp/src/arrow/flight/types.h:
##########
@@ -716,5 +720,130 @@ 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::vector<std::byte> details)
+      : details_(std::move(details)) {}
+  const char* type_id() const override { return kTypeId; }
+  std::string ToString() const override;
+
+  const std::vector<std::byte> details() const { return details_; }

Review Comment:
   It seems a bit gratuitous to introduce `std::byte` in our codebase. Why not 
use `std::string` simply?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to