Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delocalize error: warning: and note:. #1260

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/vcpkg/base/checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, error_prefix().append(message));
}
template<VCPKG_DECL_MSG_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, error_prefix().append(VCPKG_EXPAND_MSG_ARGS));
}

}
43 changes: 1 addition & 42 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
(),
Expand Down Expand Up @@ -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}...")
Expand Down Expand Up @@ -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,
(),
Expand Down Expand Up @@ -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,
(),
"",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}")
Expand Down
22 changes: 16 additions & 6 deletions include/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ namespace vcpkg
};

LocalizedString format_environment_variable(StringView variable_name);

// constants for the
// <file>:line:col: <prefix>: <content>
// 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);
Expand Down Expand Up @@ -187,38 +199,36 @@ namespace vcpkg::msg
msg::write_unlocalized_text_to_stdout(Color::none, "\n");
}

[[nodiscard]] LocalizedString format_error();
[[nodiscard]] LocalizedString format_error(const LocalizedString& s);
template<VCPKG_DECL_MSG_TEMPLATE>
[[nodiscard]] LocalizedString format_error(VCPKG_DECL_MSG_ARGS)
{
auto s = format_error();
auto s = error_prefix();
msg::format_to(s, VCPKG_EXPAND_MSG_ARGS);
return s;
}
void println_error(const LocalizedString& s);
template<VCPKG_DECL_MSG_TEMPLATE>
void println_error(VCPKG_DECL_MSG_ARGS)
{
auto s = format_error();
auto s = error_prefix();
msg::format_to(s, VCPKG_EXPAND_MSG_ARGS);
println(Color::error, s);
}

[[nodiscard]] LocalizedString format_warning();
[[nodiscard]] LocalizedString format_warning(const LocalizedString& s);
template<VCPKG_DECL_MSG_TEMPLATE>
[[nodiscard]] LocalizedString format_warning(VCPKG_DECL_MSG_ARGS)
{
auto s = format_warning();
auto s = warning_prefix();
msg::format_to(s, VCPKG_EXPAND_MSG_ARGS);
return s;
}
void println_warning(const LocalizedString& s);
template<VCPKG_DECL_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);
}
Expand Down
22 changes: 1 addition & 21 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <artifact>",
"_CmdAcquireExample1.comment": "This is a command line, only the <>s part should be localized",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand Down
9 changes: 3 additions & 6 deletions src/vcpkg/base/checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace vcpkg
if (!expression)
{
msg::println(Color::error,
msg::format(msgInternalErrorMessage)
internal_error_prefix()
.append(locale_invariant_lineinfo(line_info))
.append(msgChecksFailedCheck)
.append_raw('\n')
Expand All @@ -103,7 +103,7 @@ namespace vcpkg
if (!expression)
{
msg::println(Color::error,
msg::format(msgInternalErrorMessage)
internal_error_prefix()
.append(locale_invariant_lineinfo(line_info))
.append_raw(error_message)
.append_raw('\n')
Expand All @@ -120,10 +120,7 @@ namespace vcpkg
}
}

static void display_upgrade_message()
{
msg::println(Color::error, msg::format(msgNoteMessage).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)
{
Expand Down
8 changes: 2 additions & 6 deletions src/vcpkg/base/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,7 @@ namespace vcpkg::Hash
auto file = fs.open_for_read(path, ec);
if (ec)
{
return msg::format(msgErrorMessage)
.append(msgHashFileFailureToRead, msg::path = path)
.append_raw(ec.message());
return error_prefix().append(msgHashFileFailureToRead, msg::path = path).append_raw(ec.message());
}

return do_hash<ExpectedL<std::string>>(algo, [&](Hasher& hasher) -> ExpectedL<std::string> {
Expand All @@ -582,9 +580,7 @@ namespace vcpkg::Hash
}
else if ((ec = file.error()))
{
return msg::format(msgErrorMessage)
.append(msgHashFileFailureToRead, msg::path = path)
.append_raw(ec.message());
return error_prefix().append(msgHashFileFailureToRead, msg::path = path).append_raw(ec.message());
}
} while (!file.eof());

Expand Down
12 changes: 2 additions & 10 deletions src/vcpkg/base/message_sinks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ namespace

namespace vcpkg
{

void MessageSink::println_warning(const LocalizedString& s)
{
println(Color::warning, format(msgWarningMessage).append(s));
}

void MessageSink::println_error(const LocalizedString& s)
{
println(Color::error, format(msgErrorMessage).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;
Expand Down
12 changes: 7 additions & 5 deletions src/vcpkg/base/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -492,11 +497,8 @@ 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 error_prefix().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 warning_prefix().append(s); }
void println_warning(const LocalizedString& s) { println(Color::warning, format_warning(s)); }
}
11 changes: 3 additions & 8 deletions src/vcpkg/base/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ namespace vcpkg
{
LocalizedString res;
if (!origin.empty())
res = LocalizedString::from_raw(fmt::format("{}:{}:{}: ", origin, location.row, location.column));
if (kind == MessageKind::Warning)
{
res.append(msgWarningMessage);
res.append_raw(fmt::format("{}:{}:{}: ", origin, location.row, location.column));
}
else
{
res.append(msgErrorMessage);
}
res.append(message);

res.append_raw(kind == MessageKind::Warning ? WarningPrefix : ErrorPrefix);
res.append(message);
res.append_raw('\n');

auto line_end = Util::find_if(location.it, ParserBase::is_lineend);
Expand Down
Loading