Skip to content

Commit b437151

Browse files
committed
Adjusting 'showUser' to default to true for a DAPError and adding a missing ErrorResponseBody.
1 parent a696c1c commit b437151

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

lldb/tools/lldb-dap/Handler/RequestHandler.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,31 +121,37 @@ class RequestHandler : public BaseRequestHandler {
121121
llvm::raw_string_ostream OS(parse_failure);
122122
root.printErrorContext(request.arguments, OS);
123123

124-
protocol::ErrorMessage error;
125-
error.format = parse_failure;
124+
protocol::ErrorMessage error_message;
125+
error_message.format = parse_failure;
126+
127+
protocol::ErrorResponseBody body;
128+
body.error = error_message;
126129

127130
response.success = false;
128-
response.body = std::move(error);
131+
response.body = std::move(body);
129132

130133
dap.Send(response);
131134
return;
132135
}
133136

134137
llvm::Expected<Body> body = Run(arguments);
135138
if (auto Err = body.takeError()) {
136-
protocol::ErrorMessage error;
139+
protocol::ErrorMessage error_message;
140+
error_message.sendTelemetry = false;
137141
if (llvm::Error unhandled = llvm::handleErrors(
138142
std::move(Err), [&](const DAPError &E) -> llvm::Error {
139-
error.format = E.getMessage();
140-
error.showUser = E.getShowUser();
141-
error.id = E.convertToErrorCode().value();
143+
error_message.format = E.getMessage();
144+
error_message.showUser = E.getShowUser();
145+
error_message.id = E.convertToErrorCode().value();
142146
// TODO: We could add url/urlLabel to the error message for more
143147
// information for users.
144148
return llvm::Error::success();
145149
}))
146-
error.format = llvm::toString(std::move(unhandled));
150+
error_message.format = llvm::toString(std::move(unhandled));
151+
protocol::ErrorResponseBody body;
152+
body.error = error_message;
147153
response.success = false;
148-
response.body = std::move(error);
154+
response.body = std::move(body);
149155
} else {
150156
response.success = true;
151157
if constexpr (!std::is_same_v<Body, std::monostate>)

lldb/tools/lldb-dap/Protocol/ProtocolBase.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,13 @@ json::Value toJSON(const Message &M) {
286286
return std::visit([](auto &M) { return toJSON(M); }, M);
287287
}
288288

289+
json::Value toJSON(const ErrorResponseBody &E) {
290+
json::Object result{};
291+
292+
if (E.error)
293+
result.insert({"error", *E.error});
294+
295+
return result;
296+
}
297+
289298
} // namespace lldb_dap::protocol

lldb/tools/lldb-dap/Protocol/ProtocolBase.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct ErrorMessage {
109109
/// requirement that every user visible error message needs a corresponding
110110
/// error number, so that users or customer support can find information about
111111
/// the specific error more easily.
112-
uint64_t id;
112+
uint64_t id = 0;
113113

114114
/// A format string for the message. Embedded variables have the form
115115
/// `{name}`. If variable name starts with an underscore character, the
@@ -122,10 +122,10 @@ struct ErrorMessage {
122122
std::optional<std::map<std::string, std::string>> variables;
123123

124124
/// If true send to telemetry.
125-
bool sendTelemetry;
125+
bool sendTelemetry = false;
126126

127127
/// If true show user.
128-
bool showUser;
128+
bool showUser = false;
129129

130130
/// A url where additional information about this message can be found.
131131
std::optional<std::string> url;
@@ -141,6 +141,13 @@ using Message = std::variant<Request, Response, Event>;
141141
bool fromJSON(const llvm::json::Value &, Message &, llvm::json::Path);
142142
llvm::json::Value toJSON(const Message &);
143143

144+
/// On error (whenever `success` is false), the body can provide more details.
145+
struct ErrorResponseBody {
146+
/// A structured error message.
147+
std::optional<ErrorMessage> error;
148+
};
149+
llvm::json::Value toJSON(const ErrorResponseBody &);
150+
144151
/// This is just an acknowledgement, so no body field is required.
145152
using VoidResponse = std::monostate;
146153

0 commit comments

Comments
 (0)