From 3e46e05b89b738a2ae25c9af5f3cf1c546dc0c6f Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Mon, 30 Oct 2023 16:48:22 -0700 Subject: [PATCH 1/2] Delocalize error: warning: and note:. Response to code review comment https://github.com/microsoft/vcpkg-tool/pull/1239#discussion_r1373803950 --- include/vcpkg/base/checks.h | 4 +- include/vcpkg/base/message-data.inc.h | 43 +------------ include/vcpkg/base/messages.h | 18 ++++-- locales/messages.json | 22 +------ src/vcpkg/base/checks.cpp | 6 +- src/vcpkg/base/hash.cpp | 4 +- src/vcpkg/base/message_sinks.cpp | 4 +- src/vcpkg/base/messages.cpp | 9 +-- src/vcpkg/base/parse.cpp | 6 +- src/vcpkg/binarycaching.cpp | 6 +- src/vcpkg/commands.build.cpp | 2 +- src/vcpkg/commands.ci-verify-versions.cpp | 2 +- src/vcpkg/commands.install.cpp | 1 + src/vcpkg/commands.z-generate-message-map.cpp | 60 ++++++++++++++----- src/vcpkg/paragraphs.cpp | 4 +- src/vcpkg/portfileprovider.cpp | 9 ++- src/vcpkg/registries.cpp | 18 +++--- src/vcpkg/sourceparagraph.cpp | 2 +- src/vcpkg/tools.cpp | 9 +-- src/vcpkg/vcpkgpaths.cpp | 6 +- src/vcpkg/versions.cpp | 2 +- 21 files changed, 104 insertions(+), 133 deletions(-) diff --git a/include/vcpkg/base/checks.h b/include/vcpkg/base/checks.h index 075bd5f9e6..8b1a81bd09 100644 --- a/include/vcpkg/base/checks.h +++ b/include/vcpkg/base/checks.h @@ -83,12 +83,12 @@ namespace vcpkg::Checks [[noreturn]] inline void msg_exit_with_error(const LineInfo& line_info, const LocalizedString& message) { - msg_exit_with_message(line_info, msg::format(msgErrorMessage).append(message)); + msg_exit_with_message(line_info, LocalizedString::from_raw(ErrorPrefix).append(message)); } template [[noreturn]] void msg_exit_with_error(const LineInfo& line_info, VCPKG_DECL_MSG_ARGS) { - msg_exit_with_message(line_info, msg::format(msgErrorMessage).append(VCPKG_EXPAND_MSG_ARGS)); + msg_exit_with_message(line_info, LocalizedString::from_raw(ErrorPrefix).append(VCPKG_EXPAND_MSG_ARGS)); } } diff --git a/include/vcpkg/base/message-data.inc.h b/include/vcpkg/base/message-data.inc.h index ac8f9acf48..f4aa6f8cda 100644 --- a/include/vcpkg/base/message-data.inc.h +++ b/include/vcpkg/base/message-data.inc.h @@ -482,7 +482,7 @@ DECLARE_MESSAGE(CISwitchOptSkipFailures, "Skips ports marked `=fail` in ci.baseline.txt") DECLARE_MESSAGE(CISwitchOptXUnitAll, (), "", "Reports unchanged ports in the XUnit output") DECLARE_MESSAGE(ClearingContents, (msg::path), "", "Clearing contents of {path}") -DECLARE_MESSAGE(CmakeTargetsExcluded, (msg::count), "", "note: {count} additional targets are not displayed.") +DECLARE_MESSAGE(CmakeTargetsExcluded, (msg::count), "", "{count} additional targets are not displayed.") DECLARE_MESSAGE(CMakeTargetsUsage, (msg::package_name), "'targets' are a CMake and Makefile concept", @@ -1099,12 +1099,6 @@ DECLARE_MESSAGE(ErrorInvalidManifestModeOption, (msg::option), "", "The option --{option} is not supported in manifest mode.") -DECLARE_MESSAGE(ErrorMessage, (), "", "error: ") -DECLARE_MESSAGE( - ErrorMessageMustUsePrintError, - (msg::value), - "{value} is is a localized message name like ErrorMessageMustUsePrintError", - "The message named {value} starts with error:, it must be changed to prepend ErrorMessage in code instead.") DECLARE_MESSAGE( ErrorMissingVcpkgRoot, (), @@ -1360,22 +1354,6 @@ DECLARE_MESSAGE(ForMoreHelp, "For More Help") DECLARE_MESSAGE(GeneratedConfiguration, (msg::path), "", "Generated configuration {path}.") DECLARE_MESSAGE(GeneratedInstaller, (msg::path), "", "{path} installer generated.") -DECLARE_MESSAGE(GenerateMsgErrorParsingFormatArgs, - (msg::value), - "example of {value} 'GenerateMsgNoComment'", - "parsing format string for {value}:") -DECLARE_MESSAGE(GenerateMsgIncorrectComment, - (msg::value), - "example of {value} is 'GenerateMsgNoComment'", - R"(message {value} has an incorrect comment:)") -DECLARE_MESSAGE(GenerateMsgNoArgumentValue, - (msg::value), - "example of {value} is 'arch'", - R"({{{value}}} was specified in a comment, but was not used in the message.)") -DECLARE_MESSAGE(GenerateMsgNoCommentValue, - (msg::value), - "example of {value} is 'arch'", - R"({{{value}}} was used in the message, but not commented.)") DECLARE_MESSAGE(GeneratingConfiguration, (msg::path), "", "Generating configuration {path}...") DECLARE_MESSAGE(GeneratingInstaller, (msg::path), "", "Generating installer {path}...") DECLARE_MESSAGE(GeneratingRepo, (msg::path), "", "Generating repository {path}...") @@ -1812,7 +1790,6 @@ DECLARE_MESSAGE(InternalCICommand, (), "", "vcpkg ci is an internal command which will change incompatibly or be removed at any time.") -DECLARE_MESSAGE(InternalErrorMessage, (), "", "internal error: ") DECLARE_MESSAGE( InternalErrorMessageContact, (), @@ -2059,17 +2036,6 @@ DECLARE_MESSAGE(LoadingOverlayTriplet, (msg::path), "'-- [OVERLAY]' at the beginning must be preserved", "-- [OVERLAY] Loading triplet configuration from: {path}") -DECLARE_MESSAGE(LocalizedMessageMustNotContainIndents, - (msg::value), - "{value} is is a localized message name like LocalizedMessageMustNotContainIndents. " - "The 'LocalizedString::append_indent' part is locale-invariant.", - "The message named {value} contains what appears to be indenting which must be " - "changed to use LocalizedString::append_indent instead.") -DECLARE_MESSAGE(LocalizedMessageMustNotEndWithNewline, - (msg::value), - "{value} is a localized message name like LocalizedMessageMustNotEndWithNewline", - "The message named {value} ends with a newline which should be added by formatting " - "rather than by localization.") DECLARE_MESSAGE(LocalPortfileVersion, (), "", @@ -2198,7 +2164,6 @@ DECLARE_MESSAGE(NonZeroRemainingArgs, "the command '{command_name}' does not accept any additional arguments") DECLARE_MESSAGE(NoOutdatedPackages, (), "", "There are no outdated packages.") DECLARE_MESSAGE(NoRegistryForPort, (msg::package_name), "", "no registry configured for port {package_name}") -DECLARE_MESSAGE(NoteMessage, (), "", "note: ") DECLARE_MESSAGE(NoUrlsAndHashSpecified, (msg::sha), "", "No urls specified to download SHA: {sha}") DECLARE_MESSAGE(NoUrlsAndNoHashSpecified, (), "", "No urls specified and no hash specified.") DECLARE_MESSAGE(NugetOutputNotCapturedBecauseInteractiveSpecified, @@ -3128,12 +3093,6 @@ DECLARE_MESSAGE(VSExaminedPaths, (), "", "The following paths were examined for DECLARE_MESSAGE(VSNoInstances, (), "", "Could not locate a complete Visual Studio instance") DECLARE_MESSAGE(WaitingForChildrenToExit, (), "", "Waiting for child processes to exit...") DECLARE_MESSAGE(WaitingToTakeFilesystemLock, (msg::path), "", "waiting to take filesystem lock on {path}...") -DECLARE_MESSAGE(WarningMessage, (), "", "warning: ") -DECLARE_MESSAGE(WarningMessageMustUsePrintWarning, - (msg::value), - "{value} is is a localized message name like WarningMessageMustUsePrintWarning", - "The message named {value} starts with warning:, it must be changed to prepend " - "WarningMessage in code instead.") 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}") diff --git a/include/vcpkg/base/messages.h b/include/vcpkg/base/messages.h index 767784602b..8168d78d40 100644 --- a/include/vcpkg/base/messages.h +++ b/include/vcpkg/base/messages.h @@ -72,6 +72,14 @@ namespace vcpkg::msg namespace vcpkg { + // constants for the + // :line:col: : + // error message format + inline constexpr StringLiteral ErrorPrefix = "error: "; + inline constexpr StringLiteral InternalErrorPrefix = "internal error: "; + inline constexpr StringLiteral NotePrefix = "note: "; + inline constexpr StringLiteral WarningPrefix = "warning: "; + struct LocalizedString { LocalizedString() = default; @@ -187,12 +195,11 @@ namespace vcpkg::msg msg::write_unlocalized_text_to_stdout(Color::none, "\n"); } - [[nodiscard]] LocalizedString format_error(); [[nodiscard]] LocalizedString format_error(const LocalizedString& s); template [[nodiscard]] LocalizedString format_error(VCPKG_DECL_MSG_ARGS) { - auto s = format_error(); + auto s = LocalizedString::from_raw(ErrorPrefix); msg::format_to(s, VCPKG_EXPAND_MSG_ARGS); return s; } @@ -200,17 +207,16 @@ namespace vcpkg::msg template void println_error(VCPKG_DECL_MSG_ARGS) { - auto s = format_error(); + auto s = LocalizedString::from_raw(ErrorPrefix); msg::format_to(s, VCPKG_EXPAND_MSG_ARGS); println(Color::error, s); } - [[nodiscard]] LocalizedString format_warning(); [[nodiscard]] LocalizedString format_warning(const LocalizedString& s); template [[nodiscard]] LocalizedString format_warning(VCPKG_DECL_MSG_ARGS) { - auto s = format_warning(); + auto s = LocalizedString::from_raw(WarningPrefix); msg::format_to(s, VCPKG_EXPAND_MSG_ARGS); return s; } @@ -218,7 +224,7 @@ namespace vcpkg::msg template void println_warning(VCPKG_DECL_MSG_ARGS) { - auto s = format_warning(); + auto s = LocalizedString::from_raw(WarningPrefix); msg::format_to(s, VCPKG_EXPAND_MSG_ARGS); println(Color::warning, s); } diff --git a/locales/messages.json b/locales/messages.json index 515adff7cf..1903ea83d6 100644 --- a/locales/messages.json +++ b/locales/messages.json @@ -296,7 +296,7 @@ "_CiBaselineUnexpectedPass.comment": "An example of {spec} is zlib:x64-windows. An example of {path} is /foo/bar.", "ClearingContents": "Clearing contents of {path}", "_ClearingContents.comment": "An example of {path} is /foo/bar.", - "CmakeTargetsExcluded": "note: {count} additional targets are not displayed.", + "CmakeTargetsExcluded": "{count} additional targets are not displayed.", "_CmakeTargetsExcluded.comment": "An example of {count} is 42.", "CmdAcquireExample1": "vcpkg acquire ", "_CmdAcquireExample1.comment": "This is a command line, only the <>s part should be localized", @@ -655,9 +655,6 @@ "_ErrorInvalidExtractOption.comment": "The keyword 'AUTO' should not be localized An example of {option} is editable.", "ErrorInvalidManifestModeOption": "The option --{option} is not supported in manifest mode.", "_ErrorInvalidManifestModeOption.comment": "An example of {option} is editable.", - "ErrorMessage": "error: ", - "ErrorMessageMustUsePrintError": "The message named {value} starts with error:, it must be changed to prepend ErrorMessage in code instead.", - "_ErrorMessageMustUsePrintError.comment": "{value} is is a localized message name like ErrorMessageMustUsePrintError", "ErrorMissingVcpkgRoot": "Could not detect vcpkg-root. If you are trying to use a copy of vcpkg that you've built, you must define the VCPKG_ROOT environment variable to point to a cloned copy of https://github.com/Microsoft/vcpkg.", "ErrorNoVSInstance": "in triplet {triplet}: Unable to find a valid Visual Studio instance", "_ErrorNoVSInstance.comment": "An example of {triplet} is x64-windows.", @@ -839,14 +836,6 @@ "_FormattedParseMessageExpression.comment": "Example of {value} is 'x64 & windows'", "GHAParametersMissing": "The GHA binary source requires the ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL environment variables to be set. See {url} for details.", "_GHAParametersMissing.comment": "An example of {url} is https://github.com/microsoft/vcpkg.", - "GenerateMsgErrorParsingFormatArgs": "parsing format string for {value}:", - "_GenerateMsgErrorParsingFormatArgs.comment": "example of {value} 'GenerateMsgNoComment'", - "GenerateMsgIncorrectComment": "message {value} has an incorrect comment:", - "_GenerateMsgIncorrectComment.comment": "example of {value} is 'GenerateMsgNoComment'", - "GenerateMsgNoArgumentValue": "{{{value}}} was specified in a comment, but was not used in the message.", - "_GenerateMsgNoArgumentValue.comment": "example of {value} is 'arch'", - "GenerateMsgNoCommentValue": "{{{value}}} was used in the message, but not commented.", - "_GenerateMsgNoCommentValue.comment": "example of {value} is 'arch'", "GeneratedConfiguration": "Generated configuration {path}.", "_GeneratedConfiguration.comment": "An example of {path} is /foo/bar.", "GeneratedInstaller": "{path} installer generated.", @@ -1033,7 +1022,6 @@ "_IntegrateZshHelp.comment": "'zsh' is a terminal program which should be unlocalized.", "IntegrationFailedVS2015": "Integration was not applied for Visual Studio 2015.", "InternalCICommand": "vcpkg ci is an internal command which will change incompatibly or be removed at any time.", - "InternalErrorMessage": "internal error: ", "InternalErrorMessageContact": "Please open an issue at https://github.com/microsoft/vcpkg/issues/new?template=other-type-of-bug-report.md&labels=category:vcpkg-bug with detailed steps to reproduce the problem.", "InvalidArchitecture": "invalid architecture: {value}", "_InvalidArchitecture.comment": "{value} is what the user entered that we did not understand", @@ -1169,10 +1157,6 @@ "LoadingOverlayTriplet": "-- [OVERLAY] Loading triplet configuration from: {path}", "_LoadingOverlayTriplet.comment": "'-- [OVERLAY]' at the beginning must be preserved An example of {path} is /foo/bar.", "LocalPortfileVersion": "Using local portfile versions. To update the local portfiles, use `git pull`.", - "LocalizedMessageMustNotContainIndents": "The message named {value} contains what appears to be indenting which must be changed to use LocalizedString::append_indent instead.", - "_LocalizedMessageMustNotContainIndents.comment": "{value} is is a localized message name like LocalizedMessageMustNotContainIndents. The 'LocalizedString::append_indent' part is locale-invariant.", - "LocalizedMessageMustNotEndWithNewline": "The message named {value} ends with a newline which should be added by formatting rather than by localization.", - "_LocalizedMessageMustNotEndWithNewline.comment": "{value} is a localized message name like LocalizedMessageMustNotEndWithNewline", "ManifestConflict": "Found both a manifest and CONTROL files in port \"{path}\"; please rename one or the other", "_ManifestConflict.comment": "An example of {path} is /foo/bar.", "ManifestFormatCompleted": "Succeeded in formatting the manifest files.", @@ -1242,7 +1226,6 @@ "_NonZeroOrOneRemainingArgs.comment": "An example of {command_name} is install.", "NonZeroRemainingArgs": "the command '{command_name}' does not accept any additional arguments", "_NonZeroRemainingArgs.comment": "An example of {command_name} is install.", - "NoteMessage": "note: ", "NugetOutputNotCapturedBecauseInteractiveSpecified": "NuGet command failed and output was not captured because --interactive was specified", "NugetPackageFileSucceededButCreationFailed": "NuGet package creation succeeded, but no .nupkg was produced. Expected: \"{path}\"", "_NugetPackageFileSucceededButCreationFailed.comment": "An example of {path} is /foo/bar.", @@ -1723,9 +1706,6 @@ "_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.", - "WarningMessage": "warning: ", - "WarningMessageMustUsePrintWarning": "The message named {value} starts with warning:, it must be changed to prepend WarningMessage in code instead.", - "_WarningMessageMustUsePrintWarning.comment": "{value} is is a localized message name like WarningMessageMustUsePrintWarning", "WarningsTreatedAsErrors": "previous warnings being interpreted as errors", "WhileCheckingOutBaseline": "while checking out baseline {commit_sha}", "_WhileCheckingOutBaseline.comment": "An example of {commit_sha} is 7cfad47ae9f68b183983090afd6337cd60fd4949.", diff --git a/src/vcpkg/base/checks.cpp b/src/vcpkg/base/checks.cpp index 6e7c5fc7b5..a2eb2702af 100644 --- a/src/vcpkg/base/checks.cpp +++ b/src/vcpkg/base/checks.cpp @@ -89,7 +89,7 @@ namespace vcpkg if (!expression) { msg::println(Color::error, - msg::format(msgInternalErrorMessage) + LocalizedString::from_raw(InternalErrorPrefix) .append(locale_invariant_lineinfo(line_info)) .append(msgChecksFailedCheck) .append_raw('\n') @@ -103,7 +103,7 @@ namespace vcpkg if (!expression) { msg::println(Color::error, - msg::format(msgInternalErrorMessage) + LocalizedString::from_raw(InternalErrorPrefix) .append(locale_invariant_lineinfo(line_info)) .append_raw(error_message) .append_raw('\n') @@ -122,7 +122,7 @@ namespace vcpkg static void display_upgrade_message() { - msg::println(Color::error, msg::format(msgNoteMessage).append(msgChecksUpdateVcpkg)); + msg::println(Color::error, LocalizedString::from_raw(NotePrefix).append(msgChecksUpdateVcpkg)); } [[noreturn]] void Checks::exit_maybe_upgrade(const LineInfo& line_info) diff --git a/src/vcpkg/base/hash.cpp b/src/vcpkg/base/hash.cpp index c0103db4ec..8d25e1202b 100644 --- a/src/vcpkg/base/hash.cpp +++ b/src/vcpkg/base/hash.cpp @@ -565,7 +565,7 @@ namespace vcpkg::Hash auto file = fs.open_for_read(path, ec); if (ec) { - return msg::format(msgErrorMessage) + return LocalizedString::from_raw(ErrorPrefix) .append(msgHashFileFailureToRead, msg::path = path) .append_raw(ec.message()); } @@ -582,7 +582,7 @@ namespace vcpkg::Hash } else if ((ec = file.error())) { - return msg::format(msgErrorMessage) + return LocalizedString::from_raw(ErrorPrefix) .append(msgHashFileFailureToRead, msg::path = path) .append_raw(ec.message()); } diff --git a/src/vcpkg/base/message_sinks.cpp b/src/vcpkg/base/message_sinks.cpp index c1f92349d0..54f47f2c7c 100644 --- a/src/vcpkg/base/message_sinks.cpp +++ b/src/vcpkg/base/message_sinks.cpp @@ -32,12 +32,12 @@ namespace vcpkg void MessageSink::println_warning(const LocalizedString& s) { - println(Color::warning, format(msgWarningMessage).append(s)); + println(Color::warning, LocalizedString::from_raw(WarningPrefix).append(s)); } void MessageSink::println_error(const LocalizedString& s) { - println(Color::error, format(msgErrorMessage).append(s)); + println(Color::error, LocalizedString::from_raw(ErrorPrefix).append(s)); } MessageSink& null_sink = null_sink_instance; diff --git a/src/vcpkg/base/messages.cpp b/src/vcpkg/base/messages.cpp index 374cae96da..dda98a144f 100644 --- a/src/vcpkg/base/messages.cpp +++ b/src/vcpkg/base/messages.cpp @@ -492,11 +492,12 @@ namespace vcpkg::msg return nullopt; } - LocalizedString format_error() { return format(msgErrorMessage); } - LocalizedString format_error(const LocalizedString& s) { return format(msgErrorMessage).append(s); } + LocalizedString format_error(const LocalizedString& s) { return LocalizedString::from_raw(ErrorPrefix).append(s); } void println_error(const LocalizedString& s) { println(Color::error, format_error(s)); } - LocalizedString format_warning() { return format(msgWarningMessage); } - LocalizedString format_warning(const LocalizedString& s) { return format(msgWarningMessage).append(s); } + LocalizedString format_warning(const LocalizedString& s) + { + return LocalizedString::from_raw(WarningPrefix).append(s); + } void println_warning(const LocalizedString& s) { println(Color::warning, format_warning(s)); } } diff --git a/src/vcpkg/base/parse.cpp b/src/vcpkg/base/parse.cpp index 363ab554c7..569960b3b8 100644 --- a/src/vcpkg/base/parse.cpp +++ b/src/vcpkg/base/parse.cpp @@ -38,14 +38,14 @@ namespace vcpkg res = LocalizedString::from_raw(fmt::format("{}:{}:{}: ", origin, location.row, location.column)); if (kind == MessageKind::Warning) { - res.append(msgWarningMessage); + res.append_raw(WarningPrefix); } else { - res.append(msgErrorMessage); + res.append_raw(ErrorPrefix); } - res.append(message); + res.append(message); res.append_raw('\n'); auto line_end = Util::find_if(location.it, ParserBase::is_lineend); diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index ad78d9c761..f9ba7cfddf 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -2307,7 +2307,7 @@ ExpectedL vcpkg::parse_download_configuration(const Optio { return LocalizedString::from_raw(err->to_string()) // note that this already contains error: .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgSeeURL, msg::url = docs::assetcaching_url); } @@ -2315,14 +2315,14 @@ ExpectedL vcpkg::parse_download_configuration(const Optio { return msg::format_error(msgAMaximumOfOneAssetWriteUrlCanBeSpecified) .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgSeeURL, msg::url = docs::assetcaching_url); } if (s.url_templates_to_get.size() > 1) { return msg::format_error(msgAMaximumOfOneAssetReadUrlCanBeSpecified) .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgSeeURL, msg::url = docs::assetcaching_url); } diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index 27e7f6b216..bfe441b8ec 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -166,7 +166,7 @@ namespace vcpkg msg::print(msgElapsedForPackage, msg::spec = spec, msg::elapsed = build_timer); if (result.code == BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES) { - LocalizedString errorMsg = msg::format(msgErrorMessage).append(msgBuildDependenciesMissing); + LocalizedString errorMsg = msg::format_error(msgBuildDependenciesMissing); for (const auto& p : result.unmet_dependencies) { errorMsg.append_raw('\n').append_indent().append_raw(p.to_string()); diff --git a/src/vcpkg/commands.ci-verify-versions.cpp b/src/vcpkg/commands.ci-verify-versions.cpp index 51c01bbe2a..d508f80dcf 100644 --- a/src/vcpkg/commands.ci-verify-versions.cpp +++ b/src/vcpkg/commands.ci-verify-versions.cpp @@ -310,7 +310,7 @@ namespace vcpkg msg::write_unlocalized_text_to_stdout(Color::error, fmt::format("FAIL: {}\n", port_name)); errors.emplace(LocalizedString::from_raw(port_path) .append_raw(": ") - .append(msgErrorMessage) + .append_raw(ErrorPrefix) .append(msgPortMissingManifest2, msg::package_name = port_name)); continue; } diff --git a/src/vcpkg/commands.install.cpp b/src/vcpkg/commands.install.cpp index 8ccd17875d..3b3b0db4e0 100644 --- a/src/vcpkg/commands.install.cpp +++ b/src/vcpkg/commands.install.cpp @@ -941,6 +941,7 @@ namespace vcpkg { msg.append_indent() .append_raw("# ") + .append_raw(NotePrefix) .append(msgCmakeTargetsExcluded, msg::count = omitted) .append_raw('\n'); } diff --git a/src/vcpkg/commands.z-generate-message-map.cpp b/src/vcpkg/commands.z-generate-message-map.cpp index 083c4b5f6a..ea96d93f15 100644 --- a/src/vcpkg/commands.z-generate-message-map.cpp +++ b/src/vcpkg/commands.z-generate-message-map.cpp @@ -15,6 +15,12 @@ namespace constexpr CommandSwitch GENERATE_MESSAGE_MAP_SWITCHES[]{ {OPTION_NO_OUTPUT_COMMENTS, msgCmdGenerateMessageMapOptNoOutputComments}, }; + + struct BadPrefixTest + { + StringLiteral prefix; + StringLiteral prefix_name; + }; } // unnamed namespace namespace vcpkg @@ -143,52 +149,74 @@ namespace vcpkg bool has_errors = false; LocalizedString format_string_parsing_error; Json::Object obj; + + std::vector tests{ + {"error:", "ErrorPrefix"}, + {"internal error:", "InternalErrorPrefix"}, + {"note:", "NotePrefix"}, + {"warning:", "WarningPrefix"}, + }; + for (auto& msg : messages) { - if (msg.name != "ErrorMessage" && Strings::case_insensitive_ascii_starts_with(msg.value, "error:")) - { - has_errors = true; - msg::println_error(msgErrorMessageMustUsePrintError, msg::value = msg.name); - } - - if (msg.name != "WarningMessage" && Strings::case_insensitive_ascii_starts_with(msg.value, "warning:")) + for (auto&& test : tests) { - has_errors = true; - msg::println_error(msgWarningMessageMustUsePrintWarning, msg::value = msg.name); + if (Strings::case_insensitive_ascii_starts_with(msg.value, test.prefix)) + { + has_errors = true; + msg::print(LocalizedString::from_raw(ErrorPrefix) + .append_raw(fmt::format("The message named {} starts with {}, it must be changed " + "to prepend {} in code instead.\n", + msg.name, + test.prefix, + test.prefix_name))); + } } if (Strings::contains(msg.value, " ")) { has_errors = true; - msg::println_error(msgLocalizedMessageMustNotContainIndents, msg::value = msg.name); + msg::print(LocalizedString::from_raw(ErrorPrefix) + .append_raw(fmt::format( + "The message named {} contains what appears to be indenting which must be " + "changed to use LocalizedString::append_indent instead.\n", + msg.name))); } if (!msg.value.empty() && msg.value.back() == '\n') { has_errors = true; - msg::println_error(msgLocalizedMessageMustNotEndWithNewline, msg::value = msg.name); + msg::print(LocalizedString::from_raw(ErrorPrefix) + .append_raw(fmt::format("The message named {} ends with a newline which should be added " + "by formatting rather than by localization.", + msg.name))); } auto mismatches = get_format_arg_mismatches(msg.value, msg.comment, format_string_parsing_error); if (!format_string_parsing_error.data().empty()) { has_errors = true; - msg::println_error(msg::format(msgGenerateMsgErrorParsingFormatArgs, msg::value = msg.name) - .append(format_string_parsing_error)); + msg::print(LocalizedString::from_raw(ErrorPrefix) + .append_raw(fmt::format("parsing format string for {}:\n", msg.name))); } if (!mismatches.arguments_without_comment.empty() || !mismatches.comments_without_argument.empty()) { has_errors = true; - msg::println_error(msgGenerateMsgIncorrectComment, msg::value = msg.name); + msg::print(LocalizedString::from_raw(ErrorPrefix) + .append_raw(fmt::format("message {} has an incorrect comment:\n", msg.name))); for (const auto& arg : mismatches.arguments_without_comment) { - msg::println(Color::error, msgGenerateMsgNoCommentValue, msg::value = arg); + msg::print(LocalizedString::from_raw(ErrorPrefix) + .append_raw(fmt::format( + "{{{}}} was specified in a comment, but was not used in the message.\n", arg))); } for (const auto& comment : mismatches.comments_without_argument) { - msg::println(Color::error, msgGenerateMsgNoArgumentValue, msg::value = comment); + msg::print( + LocalizedString::from_raw(ErrorPrefix) + .append_raw(fmt::format("{{{}}} was used in the message, but not commented.\n", comment))); } } diff --git a/src/vcpkg/paragraphs.cpp b/src/vcpkg/paragraphs.cpp index a030e6246c..cfc39bd66c 100644 --- a/src/vcpkg/paragraphs.cpp +++ b/src/vcpkg/paragraphs.cpp @@ -467,13 +467,13 @@ namespace vcpkg::Paragraphs { return LocalizedString::from_raw(port_directory) .append_raw(": ") - .append(msgErrorMessage) + .append_raw(ErrorPrefix) .append(msgPortMissingManifest2, msg::package_name = port_name); } return LocalizedString::from_raw(port_directory) .append_raw(": ") - .append(msgErrorMessage) + .append_raw(ErrorPrefix) .append(msgPortDoesNotExist, msg::package_name = port_name); } diff --git a/src/vcpkg/portfileprovider.cpp b/src/vcpkg/portfileprovider.cpp index 472037ed91..321c5ea8f0 100644 --- a/src/vcpkg/portfileprovider.cpp +++ b/src/vcpkg/portfileprovider.cpp @@ -203,11 +203,10 @@ namespace vcpkg } else { - return msg::format(msgErrorMessage) - .append(msgVersionSpecMismatch, - msg::path = path->path, - msg::expected_version = version_spec, - msg::actual_version = scf_vspec); + return msg::format_error(msgVersionSpecMismatch, + msg::path = path->path, + msg::expected_version = version_spec, + msg::actual_version = scf_vspec); } } else diff --git a/src/vcpkg/registries.cpp b/src/vcpkg/registries.cpp index cff0efd53c..6d75be6579 100644 --- a/src/vcpkg/registries.cpp +++ b/src/vcpkg/registries.cpp @@ -667,30 +667,30 @@ namespace fs.create_directories(destination_parent, ec); if (ec) { - return {msg::format(msgErrorMessage) + return {LocalizedString::from_raw(ErrorPrefix) .append(format_filesystem_call_error(ec, "create_directories", {destination_parent})) .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgWhileCheckingOutBaseline, msg::commit_sha = commit_sha), expected_right_tag}; } fs.write_contents(destination_tmp, *contents, ec); if (ec) { - return {msg::format(msgErrorMessage) + return {LocalizedString::from_raw(ErrorPrefix) .append(format_filesystem_call_error(ec, "write_contents", {destination_tmp})) .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgWhileCheckingOutBaseline, msg::commit_sha = commit_sha), expected_right_tag}; } fs.rename(destination_tmp, destination, ec); if (ec) { - return {msg::format(msgErrorMessage) + return {LocalizedString::from_raw(ErrorPrefix) .append(format_filesystem_call_error(ec, "rename", {destination_tmp, destination})) .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgWhileCheckingOutBaseline, msg::commit_sha = commit_sha), expected_right_tag}; } @@ -1126,7 +1126,7 @@ namespace { return format_version_git_entry_missing(port_name, version, port_versions) .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgChecksUpdateVcpkg); } @@ -1388,7 +1388,7 @@ namespace { return LocalizedString::from_raw(origin) .append_raw(": ") - .append(msgErrorMessage) + .append_raw(ErrorPrefix) .append(msgMissingRequiredField, msg::json_field = baseline, msg::json_type = msg::format(msgABaselineObject)); @@ -1547,7 +1547,7 @@ namespace vcpkg ExpectedL> RegistrySet::baseline_for_port(StringView port_name) const { auto impl = registry_for_port(port_name); - if (!impl) return msg::format(msgErrorMessage).append(msgNoRegistryForPort, msg::package_name = port_name); + if (!impl) return msg::format_error(msgNoRegistryForPort, msg::package_name = port_name); return impl->get_baseline_version(port_name); } diff --git a/src/vcpkg/sourceparagraph.cpp b/src/vcpkg/sourceparagraph.cpp index abc00ef1a4..ff8fe343f7 100644 --- a/src/vcpkg/sourceparagraph.cpp +++ b/src/vcpkg/sourceparagraph.cpp @@ -385,7 +385,7 @@ namespace vcpkg return ParseControlErrorInfo::from_error(origin, msg::format_error(msgDefaultFeatureIdentifier) .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgParseIdentifierError, msg::value = default_feature, msg::url = docs::manifests_url)); diff --git a/src/vcpkg/tools.cpp b/src/vcpkg/tools.cpp index 9253afb38e..be6ca6245b 100644 --- a/src/vcpkg/tools.cpp +++ b/src/vcpkg/tools.cpp @@ -839,8 +839,7 @@ namespace vcpkg } // If no acceptable tool was found and downloading was unavailable, emit an error message - LocalizedString s = msg::format(msgErrorMessage); - s.append(msgToolFetchFailed, msg::tool_name = tool.tool_data_name()); + LocalizedString s = msg::format_error(msgToolFetchFailed, msg::tool_name = tool.tool_data_name()); if (env_force_system_binaries && download_available) { s.append_raw(' ').append(msgDownloadAvailable, @@ -924,8 +923,7 @@ namespace vcpkg const auto tools = fs.find_from_PATH(Tools::TAR); if (tools.empty()) { - return msg::format(msgErrorMessage) - .append(msgToolFetchFailed, msg::tool_name = Tools::TAR) + return msg::format_error(msgToolFetchFailed, msg::tool_name = Tools::TAR) #if defined(_WIN32) .append(msgToolInWin10) #else @@ -964,8 +962,7 @@ namespace vcpkg } #endif - return msg::format(msgErrorMessage) - .append(msgToolFetchFailed, msg::tool_name = Tools::CMAKE) + return msg::format_error(msgToolFetchFailed, msg::tool_name = Tools::CMAKE) #if !defined(_WIN32) .append(msgInstallWithSystemManager) #endif diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp index e39d3639a5..e2425bfab9 100644 --- a/src/vcpkg/vcpkgpaths.cpp +++ b/src/vcpkg/vcpkgpaths.cpp @@ -944,7 +944,7 @@ namespace vcpkg return std::move(maybe_tree) .error() - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgWhileCheckingOutPortTreeIsh, msg::package_name = port_name, msg::commit_sha = git_tree); } @@ -1006,7 +1006,7 @@ namespace vcpkg .append_raw('\n') .append(std::move(maybe_output).error()) .append_raw('\n') - .append(msgNoteMessage) + .append_raw(NotePrefix) .append(msgWhileGettingLocalTreeIshObjectsForPorts); } @@ -1191,7 +1191,7 @@ namespace vcpkg fs.rename_with_retry(git_tree_temp, destination, ec); if (ec) { - return msg::format(msgErrorMessage) + return LocalizedString::from_raw(ErrorPrefix) .append(format_filesystem_call_error(ec, "rename_with_retry", {git_tree_temp, destination})); } diff --git a/src/vcpkg/versions.cpp b/src/vcpkg/versions.cpp index c02d3aa597..cc6c2fb7d2 100644 --- a/src/vcpkg/versions.cpp +++ b/src/vcpkg/versions.cpp @@ -303,7 +303,7 @@ namespace vcpkg static LocalizedString format_invalid_date_version(StringView version) { - return msg::format(msgErrorMessage).append(msg::format(msgVersionInvalidDate, msg::version = version)); + return msg::format_error(msgVersionInvalidDate, msg::version = version); } ExpectedL DateVersion::try_parse(StringView version) From 56c5cb3fe9d2d16c3041bfab55728a8aa887b804 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Tue, 31 Oct 2023 16:17:32 -0700 Subject: [PATCH 2/2] CR feedback --- include/vcpkg/base/checks.h | 4 +- include/vcpkg/base/messages.h | 26 ++++++----- src/vcpkg/base/checks.cpp | 9 ++-- src/vcpkg/base/hash.cpp | 8 +--- src/vcpkg/base/message_sinks.cpp | 12 +---- src/vcpkg/base/messages.cpp | 13 +++--- src/vcpkg/base/parse.cpp | 9 +--- src/vcpkg/commands.z-generate-message-map.cpp | 45 +++++++++---------- src/vcpkg/registries.cpp | 6 +-- src/vcpkg/vcpkgpaths.cpp | 4 +- 10 files changed, 58 insertions(+), 78 deletions(-) diff --git a/include/vcpkg/base/checks.h b/include/vcpkg/base/checks.h index 8b1a81bd09..634f8f8f7d 100644 --- a/include/vcpkg/base/checks.h +++ b/include/vcpkg/base/checks.h @@ -83,12 +83,12 @@ namespace vcpkg::Checks [[noreturn]] inline void msg_exit_with_error(const LineInfo& line_info, const LocalizedString& message) { - msg_exit_with_message(line_info, LocalizedString::from_raw(ErrorPrefix).append(message)); + msg_exit_with_message(line_info, error_prefix().append(message)); } template [[noreturn]] void msg_exit_with_error(const LineInfo& line_info, VCPKG_DECL_MSG_ARGS) { - msg_exit_with_message(line_info, LocalizedString::from_raw(ErrorPrefix).append(VCPKG_EXPAND_MSG_ARGS)); + msg_exit_with_message(line_info, error_prefix().append(VCPKG_EXPAND_MSG_ARGS)); } } diff --git a/include/vcpkg/base/messages.h b/include/vcpkg/base/messages.h index 8168d78d40..20f8ddf316 100644 --- a/include/vcpkg/base/messages.h +++ b/include/vcpkg/base/messages.h @@ -72,14 +72,6 @@ namespace vcpkg::msg namespace vcpkg { - // constants for the - // :line:col: : - // error message format - inline constexpr StringLiteral ErrorPrefix = "error: "; - inline constexpr StringLiteral InternalErrorPrefix = "internal error: "; - inline constexpr StringLiteral NotePrefix = "note: "; - inline constexpr StringLiteral WarningPrefix = "warning: "; - struct LocalizedString { LocalizedString() = default; @@ -147,6 +139,18 @@ namespace vcpkg }; LocalizedString format_environment_variable(StringView variable_name); + + // constants for the + // :line:col: : + // error message format + inline constexpr StringLiteral ErrorPrefix = "error: "; + LocalizedString error_prefix(); + inline constexpr StringLiteral InternalErrorPrefix = "internal error: "; + LocalizedString internal_error_prefix(); + inline constexpr StringLiteral NotePrefix = "note: "; + LocalizedString note_prefix(); + inline constexpr StringLiteral WarningPrefix = "warning: "; + LocalizedString warning_prefix(); } VCPKG_FORMAT_AS(vcpkg::LocalizedString, vcpkg::StringView); @@ -199,7 +203,7 @@ namespace vcpkg::msg template [[nodiscard]] LocalizedString format_error(VCPKG_DECL_MSG_ARGS) { - auto s = LocalizedString::from_raw(ErrorPrefix); + auto s = error_prefix(); msg::format_to(s, VCPKG_EXPAND_MSG_ARGS); return s; } @@ -207,7 +211,7 @@ namespace vcpkg::msg template void println_error(VCPKG_DECL_MSG_ARGS) { - auto s = LocalizedString::from_raw(ErrorPrefix); + auto s = error_prefix(); msg::format_to(s, VCPKG_EXPAND_MSG_ARGS); println(Color::error, s); } @@ -216,7 +220,7 @@ namespace vcpkg::msg template [[nodiscard]] LocalizedString format_warning(VCPKG_DECL_MSG_ARGS) { - auto s = LocalizedString::from_raw(WarningPrefix); + auto s = warning_prefix(); msg::format_to(s, VCPKG_EXPAND_MSG_ARGS); return s; } diff --git a/src/vcpkg/base/checks.cpp b/src/vcpkg/base/checks.cpp index a2eb2702af..c4296824aa 100644 --- a/src/vcpkg/base/checks.cpp +++ b/src/vcpkg/base/checks.cpp @@ -89,7 +89,7 @@ namespace vcpkg if (!expression) { msg::println(Color::error, - LocalizedString::from_raw(InternalErrorPrefix) + internal_error_prefix() .append(locale_invariant_lineinfo(line_info)) .append(msgChecksFailedCheck) .append_raw('\n') @@ -103,7 +103,7 @@ namespace vcpkg if (!expression) { msg::println(Color::error, - LocalizedString::from_raw(InternalErrorPrefix) + internal_error_prefix() .append(locale_invariant_lineinfo(line_info)) .append_raw(error_message) .append_raw('\n') @@ -120,10 +120,7 @@ namespace vcpkg } } - static void display_upgrade_message() - { - msg::println(Color::error, LocalizedString::from_raw(NotePrefix).append(msgChecksUpdateVcpkg)); - } + static void display_upgrade_message() { msg::println(Color::error, note_prefix().append(msgChecksUpdateVcpkg)); } [[noreturn]] void Checks::exit_maybe_upgrade(const LineInfo& line_info) { diff --git a/src/vcpkg/base/hash.cpp b/src/vcpkg/base/hash.cpp index 8d25e1202b..39117ad46b 100644 --- a/src/vcpkg/base/hash.cpp +++ b/src/vcpkg/base/hash.cpp @@ -565,9 +565,7 @@ namespace vcpkg::Hash auto file = fs.open_for_read(path, ec); if (ec) { - return LocalizedString::from_raw(ErrorPrefix) - .append(msgHashFileFailureToRead, msg::path = path) - .append_raw(ec.message()); + return error_prefix().append(msgHashFileFailureToRead, msg::path = path).append_raw(ec.message()); } return do_hash>(algo, [&](Hasher& hasher) -> ExpectedL { @@ -582,9 +580,7 @@ namespace vcpkg::Hash } else if ((ec = file.error())) { - return LocalizedString::from_raw(ErrorPrefix) - .append(msgHashFileFailureToRead, msg::path = path) - .append_raw(ec.message()); + return error_prefix().append(msgHashFileFailureToRead, msg::path = path).append_raw(ec.message()); } } while (!file.eof()); diff --git a/src/vcpkg/base/message_sinks.cpp b/src/vcpkg/base/message_sinks.cpp index 54f47f2c7c..ab79e3aa02 100644 --- a/src/vcpkg/base/message_sinks.cpp +++ b/src/vcpkg/base/message_sinks.cpp @@ -29,16 +29,8 @@ namespace namespace vcpkg { - - void MessageSink::println_warning(const LocalizedString& s) - { - println(Color::warning, LocalizedString::from_raw(WarningPrefix).append(s)); - } - - void MessageSink::println_error(const LocalizedString& s) - { - println(Color::error, LocalizedString::from_raw(ErrorPrefix).append(s)); - } + void MessageSink::println_warning(const LocalizedString& s) { println(Color::warning, warning_prefix().append(s)); } + void MessageSink::println_error(const LocalizedString& s) { println(Color::error, error_prefix().append(s)); } MessageSink& null_sink = null_sink_instance; MessageSink& stderr_sink = stderr_sink_instance; diff --git a/src/vcpkg/base/messages.cpp b/src/vcpkg/base/messages.cpp index dda98a144f..b930c5d3e7 100644 --- a/src/vcpkg/base/messages.cpp +++ b/src/vcpkg/base/messages.cpp @@ -121,6 +121,11 @@ namespace vcpkg return LocalizedString::from_raw(fmt::format("${}", variable_name)); #endif // ^^^ !_WIN32 } + + LocalizedString error_prefix() { return LocalizedString::from_raw(ErrorPrefix); } + LocalizedString internal_error_prefix() { return LocalizedString::from_raw(InternalErrorPrefix); } + LocalizedString note_prefix() { return LocalizedString::from_raw(NotePrefix); } + LocalizedString warning_prefix() { return LocalizedString::from_raw(WarningPrefix); } } namespace vcpkg::msg @@ -492,12 +497,8 @@ namespace vcpkg::msg return nullopt; } - LocalizedString format_error(const LocalizedString& s) { return LocalizedString::from_raw(ErrorPrefix).append(s); } + LocalizedString format_error(const LocalizedString& s) { return error_prefix().append(s); } void println_error(const LocalizedString& s) { println(Color::error, format_error(s)); } - - LocalizedString format_warning(const LocalizedString& s) - { - return LocalizedString::from_raw(WarningPrefix).append(s); - } + LocalizedString format_warning(const LocalizedString& s) { return warning_prefix().append(s); } void println_warning(const LocalizedString& s) { println(Color::warning, format_warning(s)); } } diff --git a/src/vcpkg/base/parse.cpp b/src/vcpkg/base/parse.cpp index 569960b3b8..89e1b7fde3 100644 --- a/src/vcpkg/base/parse.cpp +++ b/src/vcpkg/base/parse.cpp @@ -35,16 +35,11 @@ namespace vcpkg { LocalizedString res; if (!origin.empty()) - res = LocalizedString::from_raw(fmt::format("{}:{}:{}: ", origin, location.row, location.column)); - if (kind == MessageKind::Warning) { - res.append_raw(WarningPrefix); - } - else - { - res.append_raw(ErrorPrefix); + res.append_raw(fmt::format("{}:{}:{}: ", origin, location.row, location.column)); } + res.append_raw(kind == MessageKind::Warning ? WarningPrefix : ErrorPrefix); res.append(message); res.append_raw('\n'); diff --git a/src/vcpkg/commands.z-generate-message-map.cpp b/src/vcpkg/commands.z-generate-message-map.cpp index ea96d93f15..8c8d47f2ef 100644 --- a/src/vcpkg/commands.z-generate-message-map.cpp +++ b/src/vcpkg/commands.z-generate-message-map.cpp @@ -164,59 +164,54 @@ namespace vcpkg if (Strings::case_insensitive_ascii_starts_with(msg.value, test.prefix)) { has_errors = true; - msg::print(LocalizedString::from_raw(ErrorPrefix) - .append_raw(fmt::format("The message named {} starts with {}, it must be changed " - "to prepend {} in code instead.\n", - msg.name, - test.prefix, - test.prefix_name))); + msg::print( + error_prefix().append_raw(fmt::format("The message named {} starts with {}, it must be changed " + "to prepend {} in code instead.\n", + msg.name, + test.prefix, + test.prefix_name))); } } if (Strings::contains(msg.value, " ")) { has_errors = true; - msg::print(LocalizedString::from_raw(ErrorPrefix) - .append_raw(fmt::format( - "The message named {} contains what appears to be indenting which must be " - "changed to use LocalizedString::append_indent instead.\n", - msg.name))); + msg::print(error_prefix().append_raw( + fmt::format("The message named {} contains what appears to be indenting which must be " + "changed to use LocalizedString::append_indent instead.\n", + msg.name))); } if (!msg.value.empty() && msg.value.back() == '\n') { has_errors = true; - msg::print(LocalizedString::from_raw(ErrorPrefix) - .append_raw(fmt::format("The message named {} ends with a newline which should be added " - "by formatting rather than by localization.", - msg.name))); + msg::print(error_prefix().append_raw( + fmt::format("The message named {} ends with a newline which should be added " + "by formatting rather than by localization.", + msg.name))); } auto mismatches = get_format_arg_mismatches(msg.value, msg.comment, format_string_parsing_error); if (!format_string_parsing_error.data().empty()) { has_errors = true; - msg::print(LocalizedString::from_raw(ErrorPrefix) - .append_raw(fmt::format("parsing format string for {}:\n", msg.name))); + msg::print(error_prefix().append_raw(fmt::format("parsing format string for {}:\n", msg.name))); } if (!mismatches.arguments_without_comment.empty() || !mismatches.comments_without_argument.empty()) { has_errors = true; - msg::print(LocalizedString::from_raw(ErrorPrefix) - .append_raw(fmt::format("message {} has an incorrect comment:\n", msg.name))); + msg::print(error_prefix().append_raw(fmt::format("message {} has an incorrect comment:\n", msg.name))); for (const auto& arg : mismatches.arguments_without_comment) { - msg::print(LocalizedString::from_raw(ErrorPrefix) - .append_raw(fmt::format( - "{{{}}} was specified in a comment, but was not used in the message.\n", arg))); + msg::print(error_prefix().append_raw( + fmt::format("{{{}}} is in the message, but is not commented\n", arg))); } for (const auto& comment : mismatches.comments_without_argument) { - msg::print( - LocalizedString::from_raw(ErrorPrefix) - .append_raw(fmt::format("{{{}}} was used in the message, but not commented.\n", comment))); + msg::print(error_prefix().append_raw( + fmt::format("{{{}}} is in the comment, but not used in the message\n", comment))); } } diff --git a/src/vcpkg/registries.cpp b/src/vcpkg/registries.cpp index 6d75be6579..b99d645228 100644 --- a/src/vcpkg/registries.cpp +++ b/src/vcpkg/registries.cpp @@ -667,7 +667,7 @@ namespace fs.create_directories(destination_parent, ec); if (ec) { - return {LocalizedString::from_raw(ErrorPrefix) + return {error_prefix() .append(format_filesystem_call_error(ec, "create_directories", {destination_parent})) .append_raw('\n') .append_raw(NotePrefix) @@ -677,7 +677,7 @@ namespace fs.write_contents(destination_tmp, *contents, ec); if (ec) { - return {LocalizedString::from_raw(ErrorPrefix) + return {error_prefix() .append(format_filesystem_call_error(ec, "write_contents", {destination_tmp})) .append_raw('\n') .append_raw(NotePrefix) @@ -687,7 +687,7 @@ namespace fs.rename(destination_tmp, destination, ec); if (ec) { - return {LocalizedString::from_raw(ErrorPrefix) + return {error_prefix() .append(format_filesystem_call_error(ec, "rename", {destination_tmp, destination})) .append_raw('\n') .append_raw(NotePrefix) diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp index e2425bfab9..8cb5fedb0f 100644 --- a/src/vcpkg/vcpkgpaths.cpp +++ b/src/vcpkg/vcpkgpaths.cpp @@ -1191,8 +1191,8 @@ namespace vcpkg fs.rename_with_retry(git_tree_temp, destination, ec); if (ec) { - return LocalizedString::from_raw(ErrorPrefix) - .append(format_filesystem_call_error(ec, "rename_with_retry", {git_tree_temp, destination})); + return error_prefix().append( + format_filesystem_call_error(ec, "rename_with_retry", {git_tree_temp, destination})); } fs.remove(git_tree_index, IgnoreErrors{});