Swift: Drop support for plaintext diagnostics (and helpLinks).

The recommended option is Markdown diagnostics, and we have already migrated everything to emit them. The empty help link we're currently emitting everywhere is a bug.
This commit is contained in:
Alexandre Boulgakov
2023-05-19 14:54:17 +01:00
parent a1beaa6300
commit b3e76d6052
11 changed files with 5 additions and 55 deletions

View File

@@ -40,9 +40,7 @@ nlohmann::json SwiftDiagnostic::json(const std::chrono::system_clock::time_point
{"telemetry", has(Visibility::telemetry)},
}},
{"severity", severityToString(severity)},
{"helpLinks", std::vector<std::string_view>(absl::StrSplit(helpLinks, ' '))},
{format == Format::markdown ? "markdownMessage" : "plaintextMessage",
absl::StrCat(message, "\n\n", action)},
{"markdownMessage", absl::StrCat(message, "\n\n", action)},
{"timestamp", fmt::format("{:%FT%T%z}", timestamp)},
};
if (location) {

View File

@@ -35,11 +35,6 @@ struct SwiftDiagnosticsLocation {
// These are internally stored into a map on id's. A specific error log can use binlog's category
// as id, which will then be used to recover the diagnostic source while dumping.
struct SwiftDiagnostic {
enum class Format {
plaintext,
markdown,
};
enum class Visibility : unsigned char {
none = 0b000,
statusPage = 0b001,
@@ -56,31 +51,18 @@ struct SwiftDiagnostic {
error,
};
// wrapper for passing optional help links to constructor
struct HelpLinks {
std::string_view value;
};
static constexpr std::string_view extractorName = "swift";
std::string_view id;
std::string_view name;
std::string_view action;
Format format{Format::markdown};
Visibility visibility{Visibility::all};
Severity severity{Severity::error};
// space separated if more than 1. Not a vector to allow constexpr
// TODO(C++20) with vector going constexpr this can be turned to `std::vector<std::string_view>`
std::string_view helpLinks{""};
std::optional<SwiftDiagnosticsLocation> location{};
// notice help links are really required only for plaintext messages, otherwise they should be
// directly embedded in the markdown message
// optional arguments can be any of HelpLinks, Severity, Visibility or Format to set the
// corresponding field
// optional arguments can be either Severity or Visibility to set the corresponding field.
// TODO(C++20) this constructor won't really be necessary anymore with designated initializers
template <typename... OptionalArgs>
constexpr SwiftDiagnostic(std::string_view id,
@@ -91,10 +73,9 @@ struct SwiftDiagnostic {
(setOptionalArg(optionalArgs), ...);
}
// create a JSON diagnostics for this source with the given `timestamp` and `message`
// Depending on format, either a plaintextMessage or markdownMessage is used that includes both
// the message and the action to take. The id is used to construct the source id in the form
// `swift/<prog name>/<id>`
// create a JSON diagnostics for this source with the given `timestamp` and Markdown `message`
// A markdownMessage is emitted that includes both the message and the action to take. The id is
// used to construct the source id in the form `swift/<prog name>/<id>`
nlohmann::json json(const std::chrono::system_clock::time_point& timestamp,
std::string_view message) const;
@@ -114,8 +95,6 @@ struct SwiftDiagnostic {
private:
bool has(Visibility v) const;
constexpr void setOptionalArg(HelpLinks h) { helpLinks = h.value; }
constexpr void setOptionalArg(Format f) { format = f; }
constexpr void setOptionalArg(Visibility v) { visibility = v; }
constexpr void setOptionalArg(Severity s) { severity = s; }

View File

@@ -1,7 +1,4 @@
{
"helpLinks": [
""
],
"markdownMessage": "CodeQL encountered an unexpected internal error with the following message:\n> Assertion failed: `false`. Format the int 1234 and string myString if this assertion fails.\n\nSome or all of the Swift analysis may have failed.\n\nIf the error persists, contact support, quoting the error message and describing what happened, or [open an issue in our open source repository][1].\n\n[1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md",
"severity": "warning",
"source": {