Skip to content

Commit 8512820

Browse files
committed
Adding 'ErrorMessage' for handling error messages that can be user facing.
1 parent a76b3eb commit 8512820

File tree

2 files changed

+97
-14
lines changed

2 files changed

+97
-14
lines changed

lldb/tools/lldb-dap/Protocol.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bool fromJSON(json::Value const &Params, Request &R, json::Path P) {
9696

9797
json::Value toJSON(const Response &R) {
9898
json::Object Result{{"type", "response"},
99-
{"req", 0},
99+
{"seq", 0},
100100
{"command", R.command},
101101
{"request_seq", R.request_seq},
102102
{"success", R.success}};
@@ -145,6 +145,36 @@ bool fromJSON(json::Value const &Params, Response &R, json::Path P) {
145145
mapRaw(Params, "body", R.rawBody, P);
146146
}
147147

148+
json::Value toJSON(const ErrorMessage &EM) {
149+
json::Object Result{{"id", EM.id}, {"format", EM.format}};
150+
151+
if (EM.variables) {
152+
json::Object variables;
153+
for (auto &var : *EM.variables)
154+
variables[var.first] = var.second;
155+
Result.insert({"variables", std::move(variables)});
156+
}
157+
if (EM.sendTelemetry && *EM.sendTelemetry)
158+
Result.insert({"sendTelemetry", *EM.sendTelemetry});
159+
if (EM.showUser && *EM.showUser)
160+
Result.insert({"showUser", *EM.showUser});
161+
if (EM.url)
162+
Result.insert({"url", EM.url});
163+
if (EM.urlLabel)
164+
Result.insert({"urlLabel", EM.urlLabel});
165+
166+
return std::move(Result);
167+
}
168+
169+
bool fromJSON(json::Value const &Params, ErrorMessage &EM, json::Path P) {
170+
json::ObjectMapper O(Params, P);
171+
return O && O.map("id", EM.id) && O.map("format", EM.format) &&
172+
O.map("variables", EM.variables) &&
173+
O.map("sendTelemetry", EM.sendTelemetry) &&
174+
O.map("showUser", EM.showUser) && O.map("url", EM.url) &&
175+
O.map("urlLabel", EM.urlLabel);
176+
}
177+
148178
json::Value toJSON(const Event &E) {
149179
json::Object Result{
150180
{"type", "event"},
@@ -155,9 +185,6 @@ json::Value toJSON(const Event &E) {
155185
if (E.rawBody)
156186
Result.insert({"body", E.rawBody});
157187

158-
if (E.statistics)
159-
Result.insert({"statistics", E.statistics});
160-
161188
return std::move(Result);
162189
}
163190

@@ -186,8 +213,7 @@ bool fromJSON(json::Value const &Params, Event &E, json::Path P) {
186213
return false;
187214
}
188215

189-
return mapRaw(Params, "body", E.rawBody, P) &&
190-
mapRaw(Params, "statistics", E.statistics, P);
216+
return mapRaw(Params, "body", E.rawBody, P);
191217
}
192218

193219
bool fromJSON(const json::Value &Params, Message &PM, json::Path P) {

lldb/tools/lldb-dap/Protocol.h

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#define LLDB_TOOLS_LLDB_DAP_PROTOCOL_H
2222

2323
#include "llvm/Support/JSON.h"
24-
#include <cstddef>
2524
#include <cstdint>
2625
#include <optional>
2726
#include <string>
@@ -85,9 +84,6 @@ bool fromJSON(const llvm::json::Value &, Request &, llvm::json::Path);
8584
struct Event {
8685
std::string event;
8786
std::optional<llvm::json::Value> rawBody;
88-
89-
/// lldb-dap specific extension on the 'terminated' event specifically.
90-
std::optional<llvm::json::Value> statistics;
9187
};
9288
llvm::json::Value toJSON(const Event &);
9389
bool fromJSON(const llvm::json::Value &, Event &, llvm::json::Path);
@@ -122,9 +118,9 @@ bool fromJSON(const llvm::json::Value &, Event &, llvm::json::Path);
122118
// " "is not shown in the UI.\nSome predefined values exist.",
123119
// "_enum" : [ "cancelled", "notStopped" ],
124120
// "enumDescriptions" : [
125-
// "the request was cancelled.", "the request may be retried once
126-
// the "
127-
// "adapter is in a 'stopped' state."
121+
// "the request was cancelled.",
122+
// "the request may be retried once the adapter is in a 'stopped'
123+
// state."
128124
// ]
129125
// },
130126
// "body" : {
@@ -142,14 +138,75 @@ bool fromJSON(const llvm::json::Value &, Event &, llvm::json::Path);
142138
// }
143139
struct Response {
144140
int64_t request_seq;
145-
bool success;
146141
std::string command;
142+
bool success;
147143
std::optional<std::string> message;
148144
std::optional<llvm::json::Value> rawBody;
149145
};
150146
bool fromJSON(const llvm::json::Value &, Response &, llvm::json::Path);
151147
llvm::json::Value toJSON(const Response &);
152148

149+
// "Message": {
150+
// "type": "object",
151+
// "description": "A structured message object. Used to return errors from
152+
// requests.", "properties": {
153+
// "id": {
154+
// "type": "integer",
155+
// "description": "Unique (within a debug adapter implementation)
156+
// identifier for the message. The purpose of these error IDs is to help
157+
// extension authors that have the requirement that every user visible
158+
// error message needs a corresponding error number, so that users or
159+
// customer support can find information about the specific error more
160+
// easily."
161+
// },
162+
// "format": {
163+
// "type": "string",
164+
// "description": "A format string for the message. Embedded variables
165+
// have the form `{name}`.\nIf variable name starts with an underscore
166+
// character, the variable does not contain user data (PII) and can be
167+
// safely used for telemetry purposes."
168+
// },
169+
// "variables": {
170+
// "type": "object",
171+
// "description": "An object used as a dictionary for looking up the
172+
// variables in the format string.", "additionalProperties": {
173+
// "type": "string",
174+
// "description": "All dictionary values must be strings."
175+
// }
176+
// },
177+
// "sendTelemetry": {
178+
// "type": "boolean",
179+
// "description": "If true send to telemetry."
180+
// },
181+
// "showUser": {
182+
// "type": "boolean",
183+
// "description": "If true show user."
184+
// },
185+
// "url": {
186+
// "type": "string",
187+
// "description": "A url where additional information about this message
188+
// can be found."
189+
// },
190+
// "urlLabel": {
191+
// "type": "string",
192+
// "description": "A label that is presented to the user as the UI for
193+
// opening the url."
194+
// }
195+
// },
196+
// "required": [ "id", "format" ]
197+
// },
198+
struct ErrorMessage {
199+
uint64_t id;
200+
std::string format;
201+
std::optional<std::map<std::string, std::string>> variables;
202+
std::optional<bool> sendTelemetry;
203+
std::optional<bool> showUser;
204+
std::optional<std::string> url;
205+
std::optional<std::string> urlLabel;
206+
};
207+
bool fromJSON(const llvm::json::Value &, ErrorMessage &, llvm::json::Path);
208+
llvm::json::Value toJSON(const ErrorMessage &);
209+
153210
// "ProtocolMessage": {
154211
// "type": "object",
155212
// "title": "Base Protocol",

0 commit comments

Comments
 (0)