|
10 | 10 | #define LLDB_TOOLS_LLDB_DAP_HANDLER_HANDLER_H |
11 | 11 |
|
12 | 12 | #include "DAP.h" |
| 13 | +#include "DAPError.h" |
13 | 14 | #include "DAPLog.h" |
14 | 15 | #include "Protocol/ProtocolBase.h" |
15 | 16 | #include "Protocol/ProtocolRequests.h" |
16 | 17 | #include "lldb/API/SBError.h" |
17 | 18 | #include "llvm/ADT/StringRef.h" |
| 19 | +#include "llvm/Support/Error.h" |
18 | 20 | #include "llvm/Support/JSON.h" |
19 | 21 | #include <optional> |
20 | 22 | #include <type_traits> |
@@ -118,20 +120,38 @@ class RequestHandler : public BaseRequestHandler { |
118 | 120 | std::string parse_failure; |
119 | 121 | llvm::raw_string_ostream OS(parse_failure); |
120 | 122 | root.printErrorContext(request.arguments, OS); |
| 123 | + |
| 124 | + protocol::ErrorMessage error_message; |
| 125 | + error_message.format = parse_failure; |
| 126 | + |
| 127 | + protocol::ErrorResponseBody body; |
| 128 | + body.error = error_message; |
| 129 | + |
121 | 130 | response.success = false; |
122 | | - response.message = parse_failure; |
| 131 | + response.body = std::move(body); |
| 132 | + |
123 | 133 | dap.Send(response); |
124 | 134 | return; |
125 | 135 | } |
126 | 136 |
|
127 | | - auto body = Run(arguments); |
128 | | - // FIXME: Add a dedicated DAPError for enhanced errors that are |
129 | | - // user-visibile. |
| 137 | + llvm::Expected<Body> body = Run(arguments); |
130 | 138 | if (auto Err = body.takeError()) { |
| 139 | + protocol::ErrorMessage error_message; |
| 140 | + error_message.sendTelemetry = false; |
| 141 | + if (llvm::Error unhandled = llvm::handleErrors( |
| 142 | + std::move(Err), [&](const DAPError &E) -> llvm::Error { |
| 143 | + error_message.format = E.getMessage(); |
| 144 | + error_message.showUser = E.getShowUser(); |
| 145 | + error_message.id = E.convertToErrorCode().value(); |
| 146 | + error_message.url = E.getURL(); |
| 147 | + error_message.urlLabel = E.getURLLabel(); |
| 148 | + return llvm::Error::success(); |
| 149 | + })) |
| 150 | + error_message.format = llvm::toString(std::move(unhandled)); |
| 151 | + protocol::ErrorResponseBody body; |
| 152 | + body.error = error_message; |
131 | 153 | response.success = false; |
132 | | - // FIXME: Build ErrorMessage based on error details instead of using the |
133 | | - // 'message' field. |
134 | | - response.message = llvm::toString(std::move(Err)); |
| 154 | + response.body = std::move(body); |
135 | 155 | } else { |
136 | 156 | response.success = true; |
137 | 157 | if constexpr (!std::is_same_v<Body, std::monostate>) |
|
0 commit comments