Index: mojo/public/cpp/bindings/error.h |
diff --git a/mojo/public/cpp/bindings/error.h b/mojo/public/cpp/bindings/error.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d149bc73f7076d72fadfe3f137c9502bdc261d45 |
--- /dev/null |
+++ b/mojo/public/cpp/bindings/error.h |
@@ -0,0 +1,94 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MOJO_PUBLIC_CPP_BINDINGS_ERROR_H_ |
+#define MOJO_PUBLIC_CPP_BINDINGS_ERROR_H_ |
+ |
+#include <string> |
+ |
+#include "mojo/public/cpp/bindings/message.h" |
+ |
+namespace mojo { |
+ |
+// An error type used to signal various specific error conditions between |
+// internal bindings components. |
+class Error { |
+ public: |
+ enum class Type { |
+ // Not really an error. |
+ NONE, |
+ |
+ // A request was dropped because it didn't have a bound receiver after being |
+ // read from a pipe. This may be raised on the receiving end of a request. |
yzshen1
2016/06/14 16:45:32
Do you want to also return this code when the requ
Ken Rockot(use gerrit already)
2016/06/14 21:20:40
Done
|
+ REQUEST_DROPPED, |
+ |
+ // A request expecting a response has become impossible to fulfill (i.e. |
+ // a response callback was destroyed without being Run.) This may be raised |
+ // on the receiving side of a request, i.e. the responder. |
yzshen1
2016/06/14 16:45:32
Does this error code also include the case that th
Ken Rockot(use gerrit already)
2016/06/14 21:20:40
That case is actually treated as a BAD_MESSAGE (se
|
+ RESPONSE_DROPPED, |
+ |
+ // A sent request which expects a response can no longer receive a response, |
+ // e.g. because of pipe closure. This may be raised on the sending side of |
+ // a request. |
+ REQUEST_CANCELED, |
yzshen1
2016/06/14 16:45:32
Reading the code, it seems this error code is used
Ken Rockot(use gerrit already)
2016/06/14 21:20:40
Oops, this is gone now. The only uses that existed
|
+ |
+ // A message could not be sent for some reason, e.g., peer closure detected |
+ // on a pipe. |
+ SEND_FAILED, |
+ |
+ // An unexpected or malformed message was received. |
+ BAD_MESSAGE, |
+ }; |
+ |
+ Error(); |
+ Error(Error&& other); |
+ explicit Error(Type type); |
+ Error(Type type, const std::string& details); |
+ |
+ ~Error(); |
+ |
+ Error& operator=(Error&& other); |
+ |
+ // Set the Message object associated with this error, if any. Takes ownership |
+ // of the contents of |*message|. |
+ void set_message(Message* message) { |
+ DCHECK(message); |
+ message->MoveTo(&message_); |
+ } |
+ |
+ Type type() const { return type_; } |
+ const std::string& details() const { return details_; } |
+ Message& message() { return message_; } |
+ |
+ static Error ForBadMessage(const std::string& details, |
+ Message* message); |
+ |
+ static Error ForBadRequest(const std::string& interface_name, |
+ const std::string& method_name, |
+ Message* message); |
+ |
+ static Error ForBadResponse(const std::string& interface_name, |
+ const std::string& method_name, |
+ Message* message); |
+ |
+ static Error ForUnexpectedRequest(const std::string& interface_name, |
+ Message* message); |
+ |
+ static Error ForUnexpectedResponse(const std::string& interface_name, |
+ Message* message); |
+ |
+ static Error ForBadControlMessage(const std::string& interface_name, |
+ Message* message); |
+ |
+ private: |
+ Type type_; |
+ std::string details_; |
+ Message message_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Error); |
+}; |
+ |
+} // namespace mojo |
+ |
+#endif // MOJO_PUBLIC_CPP_BINDINGS_ERROR_H_ |