Skip to content

Commit

Permalink
Continue 6424
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Feb 1, 2025
1 parent 4bbecc2 commit 4ae63dd
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 2025-02-01 11:59:59+00:00 - build 6427

1. Continue 6424.

--------------------------------------------------------------------------------
drkns 2025-02-01 02:49:37+00:00 - build 6426

Expand Down
20 changes: 14 additions & 6 deletions far/exception_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ static bool HandleCppExceptions = true;
static bool HandleSehExceptions = true;
static bool ForceStderrExceptionUI = false;

static bool s_ReportToStdErr = false;

// On CI we can't access the filesystem, so just drop everything to stderr.
void report_to_stderr()
{
s_ReportToStdErr = true;
}

static wchar_t s_ReportLocation[MAX_PATH];

// We can crash in the cleanup phase when profile paths are already destroyed.
Expand Down Expand Up @@ -1811,7 +1819,7 @@ static handler_result handle_generic_exception(

SCOPED_ACTION(tracer_detail::tracer::with_symbols)(PluginModule? ModuleName : L""sv);

const auto ReportLocation = get_report_location();
const auto ReportLocation = s_ReportToStdErr? L"below"s : get_report_location();

LOGERROR(L"Unhandled exception, see {} for details"sv, ReportLocation);

Expand Down Expand Up @@ -1839,12 +1847,12 @@ static handler_result handle_generic_exception(
MiniDumpIgnoreInaccessibleMemory
);

const auto MinidumpNormal = write_minidump(Context, path::join(ReportLocation, WIDE_SV(MINIDUMP_NAME)), MinidumpFlags);
const auto MinidumpFull = write_minidump(Context, path::join(ReportLocation, WIDE_SV(FULLDUMP_NAME)), FulldumpFlags);
const auto MinidumpNormal = !s_ReportToStdErr && write_minidump(Context, path::join(ReportLocation, WIDE_SV(MINIDUMP_NAME)), MinidumpFlags);
const auto MinidumpFull = !s_ReportToStdErr && write_minidump(Context, path::join(ReportLocation, WIDE_SV(FULLDUMP_NAME)), FulldumpFlags);
const auto BugReport = collect_information(Context, Location, PluginInfo, ModuleName, Type, Message, ErrorState, NestedStack);
const auto ReportOnDisk = write_report(BugReport, path::join(ReportLocation, WIDE_SV(BUGREPORT_NAME)));
const auto ReportInClipboard = !ReportOnDisk && SetClipboardText(BugReport);
const auto ReadmeOnDisk = write_readme(path::join(ReportLocation, L"README.txt"sv));
const auto ReportOnDisk = !s_ReportToStdErr && write_report(BugReport, path::join(ReportLocation, WIDE_SV(BUGREPORT_NAME)));
const auto ReportInClipboard = !s_ReportToStdErr && !ReportOnDisk && SetClipboardText(BugReport);
const auto ReadmeOnDisk = !s_ReportToStdErr && write_readme(path::join(ReportLocation, L"README.txt"sv));
const auto AnythingOnDisk = ReportOnDisk || MinidumpNormal || MinidumpFull || ReadmeOnDisk;

if (AnythingOnDisk && os::is_interactive_user_session())
Expand Down
1 change: 1 addition & 0 deletions far/exception_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

//----------------------------------------------------------------------------

void report_to_stderr();
void set_report_location(string_view Directory);

void disable_exception_handling();
Expand Down
17 changes: 10 additions & 7 deletions far/interf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,15 +1698,15 @@ point GetNonMaximisedBufferSize()
return NonMaximisedBufferSize();
}

size_t ConsoleChoice(string_view const Message, string_view const Choices, size_t const Default, function_ref<void()> const MessagePrinter)
static bool s_SuppressConsoleConfirmations;

void suppress_console_confirmations()
{
{
// The output can be redirected
DWORD Mode;
if (!console.GetMode(console.GetOutputHandle(), Mode))
return Default;
}
s_SuppressConsoleConfirmations = true;
}

size_t ConsoleChoice(string_view const Message, string_view const Choices, size_t const Default, function_ref<void()> const MessagePrinter)
{
if (InitialConsoleMode)
{
ChangeConsoleMode(console.GetInputHandle(), InitialConsoleMode->Input);
Expand All @@ -1722,6 +1722,9 @@ size_t ConsoleChoice(string_view const Message, string_view const Choices, size_
{
std::wcout << far::format(L"\n{} ({})? "sv, Message, join(L"/"sv, Choices)) << std::flush;

if (s_SuppressConsoleConfirmations)
return Default;

wchar_t Input;
std::wcin.clear();
std::wcin.get(Input).ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
Expand Down
1 change: 1 addition & 0 deletions far/interf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class consoleicons: public singleton<consoleicons>
icon m_Small{false};
};

void suppress_console_confirmations();
size_t ConsoleChoice(string_view Message, string_view Choices, size_t Default, function_ref<void()> MessagePrinter);
bool ConsoleYesNo(string_view Message, bool Default, function_ref<void()> MessagePrinter);

Expand Down
2 changes: 2 additions & 0 deletions far/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// Internal:
// console must outlive logger
#include "console.hpp"

// Platform:

Expand Down
2 changes: 2 additions & 0 deletions far/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,8 @@ static void configure_exception_handling(std::span<wchar_t const* const> const A
if (equal_icase(i + 1, L"service"sv))
{
os::debug::crt_report_to_stderr();
report_to_stderr();
suppress_console_confirmations();
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6426
6427

0 comments on commit 4ae63dd

Please sign in to comment.