| 1 | //===-- MCPError.h --------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "Protocol.h" |
| 10 | #include "llvm/Support/Error.h" |
| 11 | #include "llvm/Support/FormatVariadic.h" |
| 12 | #include <string> |
| 13 | |
| 14 | namespace lldb_private::mcp { |
| 15 | |
| 16 | class MCPError : public llvm::ErrorInfo<MCPError> { |
| 17 | public: |
| 18 | static char ID; |
| 19 | |
| 20 | MCPError(std::string message, int64_t error_code = kInternalError); |
| 21 | |
| 22 | void log(llvm::raw_ostream &OS) const override; |
| 23 | std::error_code convertToErrorCode() const override; |
| 24 | |
| 25 | const std::string &getMessage() const { return m_message; } |
| 26 | |
| 27 | protocol::Error toProtcolError() const; |
| 28 | |
| 29 | static constexpr int64_t kResourceNotFound = -32002; |
| 30 | static constexpr int64_t kInternalError = -32603; |
| 31 | |
| 32 | private: |
| 33 | std::string m_message; |
| 34 | int64_t m_error_code; |
| 35 | }; |
| 36 | |
| 37 | class UnsupportedURI : public llvm::ErrorInfo<UnsupportedURI> { |
| 38 | public: |
| 39 | static char ID; |
| 40 | |
| 41 | UnsupportedURI(std::string uri); |
| 42 | |
| 43 | void log(llvm::raw_ostream &OS) const override; |
| 44 | std::error_code convertToErrorCode() const override; |
| 45 | |
| 46 | private: |
| 47 | std::string m_uri; |
| 48 | }; |
| 49 | |
| 50 | } // namespace lldb_private::mcp |
| 51 | |