1 | //===-- DAPError.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 "llvm/Support/Error.h" |
10 | #include <optional> |
11 | #include <string> |
12 | #include <system_error> |
13 | |
14 | namespace lldb_dap { |
15 | |
16 | /// An error that is reported as a DAP Error Message, which may be presented to |
17 | /// the user. |
18 | class DAPError : public llvm::ErrorInfo<DAPError> { |
19 | public: |
20 | static char ID; |
21 | |
22 | DAPError(std::string message, |
23 | std::error_code EC = llvm::inconvertibleErrorCode(), |
24 | bool show_user = true, std::optional<std::string> url = std::nullopt, |
25 | std::optional<std::string> url_label = std::nullopt); |
26 | |
27 | void log(llvm::raw_ostream &OS) const override; |
28 | std::error_code convertToErrorCode() const override; |
29 | |
30 | const std::string &getMessage() const { return m_message; } |
31 | bool getShowUser() const { return m_show_user; } |
32 | const std::optional<std::string> &getURL() const { return m_url; } |
33 | const std::optional<std::string> &getURLLabel() const { return m_url; } |
34 | |
35 | private: |
36 | std::string m_message; |
37 | std::error_code m_ec; |
38 | bool m_show_user; |
39 | std::optional<std::string> m_url; |
40 | std::optional<std::string> m_url_label; |
41 | }; |
42 | |
43 | /// An error that indicates the current request handler cannot execute because |
44 | /// the process is not stopped. |
45 | class NotStoppedError : public llvm::ErrorInfo<NotStoppedError> { |
46 | public: |
47 | static char ID; |
48 | void log(llvm::raw_ostream &OS) const override; |
49 | std::error_code convertToErrorCode() const override; |
50 | }; |
51 | |
52 | } // namespace lldb_dap |
53 | |