Skip to content

Commit

Permalink
Improve printed filesystem error message (#332)
Browse files Browse the repository at this point in the history
* Improve printed filesystem error message

* Apply CR
  • Loading branch information
autoantwort authored Jan 28, 2022
1 parent 488ba5f commit f95f306
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/vcpkg/base/basic_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace vcpkg::Checks
// Display an error message to the user and exit the tool.
[[noreturn]] void exit_with_message(const LineInfo& line_info, StringView error_message);

// Display an error message and the line to the user and exit the tool.
[[noreturn]] void exit_with_message_and_line(const LineInfo& line_info, StringView error_message);

// If expression is false, call exit_fail.
void check_exit(const LineInfo& line_info, bool expression);

Expand Down
7 changes: 7 additions & 0 deletions src/vcpkg/base/checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ namespace vcpkg
exit_fail(line_info);
}

[[noreturn]] void Checks::exit_with_message_and_line(const LineInfo& line_info, StringView error_message)
{
print2(Color::error,
Strings::format("%s(%d): %s\n", line_info.file_name, line_info.line_number, error_message));
exit_fail(line_info);
}

void Checks::check_exit(const LineInfo& line_info, bool expression)
{
if (!expression)
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/base/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ namespace
StringView call_name,
std::initializer_list<StringView> args)
{
Checks::exit_with_message(
li, Strings::concat(call_name, "(", Strings::join(", ", args.begin(), args.end()), "): ", ec.message()));
auto arguments = args.size() == 0 ? "()" : "(\"" + Strings::join("\", \"", args.begin(), args.end()) + "\")";
Checks::exit_with_message_and_line(li, Strings::concat(call_name, arguments, ": ", ec.message()));
}

#if defined(_WIN32)
Expand Down

0 comments on commit f95f306

Please sign in to comment.