Skip to content

Commit

Permalink
Revert the ReaderMessage part of the change which became microsoft#…
Browse files Browse the repository at this point in the history
…1323 as requested by @ras0219-msft
  • Loading branch information
BillyONeal committed Jun 7, 2024
1 parent d3d53c9 commit fa86593
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 191 deletions.
27 changes: 7 additions & 20 deletions include/vcpkg/base/jsonreader.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <vcpkg/base/fwd/json.h>
#include <vcpkg/base/fwd/parse.h>

#include <vcpkg/base/chrono.h>
#include <vcpkg/base/json.h>
Expand Down Expand Up @@ -43,27 +42,11 @@ namespace vcpkg::Json
IDeserializer& operator=(IDeserializer&&) = default;
};

struct ReaderMessage
{
MessageKind kind;
LocalizedString message;

ReaderMessage(MessageKind kind, LocalizedString&& message);
ReaderMessage(const ReaderMessage&);
ReaderMessage(ReaderMessage&&);
ReaderMessage& operator=(const ReaderMessage&);
ReaderMessage& operator=(ReaderMessage&&);
};

LocalizedString join(const std::vector<ReaderMessage>& messages);
LocalizedString flatten_reader_messages(const std::vector<ReaderMessage>& messages, MessageSink& warningsSink);

struct Reader
{
explicit Reader(StringView origin);

const std::vector<ReaderMessage>& messages() const { return m_messages; }
std::size_t error_count() const { return m_error_count; }
const std::vector<LocalizedString>& errors() const { return m_errors; }

void add_missing_field_error(const LocalizedString& type, StringView key, const LocalizedString& key_type);
void add_expected_type_error(const LocalizedString& expected_type);
Expand All @@ -72,15 +55,19 @@ namespace vcpkg::Json

void add_warning(LocalizedString type, StringView msg);

const std::vector<LocalizedString>& warnings() const { return m_warnings; }

LocalizedString join() const;

std::string path() const noexcept;
StringView origin() const noexcept;

private:
template<class Type>
friend struct IDeserializer;

std::vector<ReaderMessage> m_messages;
std::size_t m_error_count;
std::vector<LocalizedString> m_errors;
std::vector<LocalizedString> m_warnings;
struct JsonPathElement
{
constexpr JsonPathElement() = default;
Expand Down
6 changes: 6 additions & 0 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,11 @@ DECLARE_MESSAGE(FailedToParseCMakeConsoleOut,
(),
"",
"Failed to parse CMake console output to locate block start/end markers.")
DECLARE_MESSAGE(FailedToParseBaseline, (msg::path), "", "Failed to parse baseline: {path}")
DECLARE_MESSAGE(FailedToParseConfig, (msg::path), "", "Failed to parse configuration: {path}")
DECLARE_MESSAGE(FailedToParseControl, (msg::path), "", "Failed to parse CONTROL file: {path}")
DECLARE_MESSAGE(FailedToParseManifest, (msg::path), "", "Failed to parse manifest file: {path}")
DECLARE_MESSAGE(FailedToParseVersionFile, (msg::path), "", "Failed to parse version file: {path}")
DECLARE_MESSAGE(FailedToParseNoTopLevelObj, (msg::path), "", "Failed to parse {path}, expected a top-level object.")
DECLARE_MESSAGE(FailedToParseNoVersionsArray, (msg::path), "", "Failed to parse {path}, expected a 'versions' array.")
DECLARE_MESSAGE(FailedToParseSerializedBinParagraph,
Expand Down Expand Up @@ -3018,6 +3023,7 @@ DECLARE_MESSAGE(VSNoInstances, (), "", "Could not locate a complete Visual Studi
DECLARE_MESSAGE(WaitingForChildrenToExit, (), "", "Waiting for child processes to exit...")
DECLARE_MESSAGE(WaitingToTakeFilesystemLock, (msg::path), "", "waiting to take filesystem lock on {path}...")
DECLARE_MESSAGE(WarningsTreatedAsErrors, (), "", "previous warnings being interpreted as errors")
DECLARE_MESSAGE(WarnOnParseConfig, (msg::path), "", "Found the following warnings in configuration {path}:")
DECLARE_MESSAGE(WhileCheckingOutBaseline, (msg::commit_sha), "", "while checking out baseline {commit_sha}")
DECLARE_MESSAGE(WhileCheckingOutPortTreeIsh,
(msg::package_name, msg::git_tree_sha),
Expand Down
12 changes: 12 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,13 +736,23 @@
"FailedToObtainPackageVersion": "Cannot find desired package version.",
"FailedToOpenAlgorithm": "failed to open {value}",
"_FailedToOpenAlgorithm.comment": "{value} is a crypto algorithm like SHA-1 or SHA-512",
"FailedToParseBaseline": "Failed to parse baseline: {path}",
"_FailedToParseBaseline.comment": "An example of {path} is /foo/bar.",
"FailedToParseCMakeConsoleOut": "Failed to parse CMake console output to locate block start/end markers.",
"FailedToParseConfig": "Failed to parse configuration: {path}",
"_FailedToParseConfig.comment": "An example of {path} is /foo/bar.",
"FailedToParseControl": "Failed to parse CONTROL file: {path}",
"_FailedToParseControl.comment": "An example of {path} is /foo/bar.",
"FailedToParseManifest": "Failed to parse manifest file: {path}",
"_FailedToParseManifest.comment": "An example of {path} is /foo/bar.",
"FailedToParseNoTopLevelObj": "Failed to parse {path}, expected a top-level object.",
"_FailedToParseNoTopLevelObj.comment": "An example of {path} is /foo/bar.",
"FailedToParseNoVersionsArray": "Failed to parse {path}, expected a 'versions' array.",
"_FailedToParseNoVersionsArray.comment": "An example of {path} is /foo/bar.",
"FailedToParseSerializedBinParagraph": "[sanity check] Failed to parse a serialized binary paragraph.\nPlease open an issue at https://github.com/microsoft/vcpkg, with the following output:\n{error_msg}\nSerialized Binary Paragraph:",
"_FailedToParseSerializedBinParagraph.comment": "'{error_msg}' is the error message for failing to parse the Binary Paragraph. An example of {error_msg} is File Not Found.",
"FailedToParseVersionFile": "Failed to parse version file: {path}",
"_FailedToParseVersionFile.comment": "An example of {path} is /foo/bar.",
"FailedToParseVersionXML": "Could not parse version for tool {tool_name}. Version string was: {version}",
"_FailedToParseVersionXML.comment": "An example of {tool_name} is aria2. An example of {version} is 1.3.8.",
"FailedToReadParagraph": "Failed to read paragraphs from {path}",
Expand Down Expand Up @@ -1647,6 +1657,8 @@
"WaitingForChildrenToExit": "Waiting for child processes to exit...",
"WaitingToTakeFilesystemLock": "waiting to take filesystem lock on {path}...",
"_WaitingToTakeFilesystemLock.comment": "An example of {path} is /foo/bar.",
"WarnOnParseConfig": "Found the following warnings in configuration {path}:",
"_WarnOnParseConfig.comment": "An example of {path} is /foo/bar.",
"WarningsTreatedAsErrors": "previous warnings being interpreted as errors",
"WhileCheckingOutBaseline": "while checking out baseline {commit_sha}",
"_WhileCheckingOutBaseline.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.",
Expand Down
6 changes: 3 additions & 3 deletions src/vcpkg-test/configmetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static Configuration parse_test_configuration(StringView text)

Json::Reader reader(origin);
auto parsed_config_opt = reader.visit(object, get_configuration_deserializer());
REQUIRE(reader.messages().empty());
REQUIRE(reader.errors().empty());

return std::move(parsed_config_opt).value_or_exit(VCPKG_LINE_INFO);
}
Expand All @@ -61,9 +61,9 @@ static void check_errors(const std::string& config_text, const std::string& expe

Json::Reader reader(origin);
auto parsed_config_opt = reader.visit(object, get_configuration_deserializer());
REQUIRE(reader.error_count() != 0);
REQUIRE(!reader.errors().empty());

CHECK_LINES(Json::join(reader.messages()).data(), expected_errors);
CHECK_LINES(Strings::join("\n", reader.errors()), expected_errors);
}

TEST_CASE ("config registries only", "[ce-metadata]")
Expand Down
Loading

0 comments on commit fa86593

Please sign in to comment.