From e360cf3a28d2f45c59d495f04abf87a2508e6b8e Mon Sep 17 00:00:00 2001 From: "git@71rd.net" Date: Mon, 26 May 2025 16:44:44 +0000 Subject: [PATCH] main: avoid crashing when aborting completions To print completions lix created a Finally object containing the actual function, so the function was executed by the destructor of the class. Unfortunately aborting autocomplete by sending a SIGINT signal (i.E. by pressing C-c) leads to an exception, that finally cant return or eat, when throwing its own exception. To avoid crashing when using auto complete let the function "mainWrapped" execute the autocomplete code directly before returning. This avoids creating the "Finally" object and instead moves the codeblock next to the check to return when "arg.completions" is called. Change-Id: Id333a60ad43c6095e8866f6953af78d51fd43b64 --- lix/nix/main.cc | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/lix/nix/main.cc b/lix/nix/main.cc index a47fb8eec..b054e4883 100644 --- a/lix/nix/main.cc +++ b/lix/nix/main.cc @@ -562,29 +562,25 @@ void mainWrapped(AsyncIoRoot & aio, int argc, char * * argv) return; } - Finally printCompletions([&]() - { - if (args.completions) { - switch (args.completions->type) { - case Completions::Type::Normal: - logger->cout("normal"); break; - case Completions::Type::Filenames: - logger->cout("filenames"); break; - case Completions::Type::Attrs: - logger->cout("attrs"); break; - } - for (auto & s : args.completions->completions) - logger->cout(s.completion + "\t" + trim(s.description)); - } - }); - try { args.parseCmdline({argv + 1, argv + argc}); } catch (UsageError &) { if (!args.helpRequested && !args.completions) throw; } - if (args.completions) return; + if (args.completions) { + switch (args.completions->type) { + case Completions::Type::Normal: + logger->cout("normal"); break; + case Completions::Type::Filenames: + logger->cout("filenames"); break; + case Completions::Type::Attrs: + logger->cout("attrs"); break; + } + for (auto & s : args.completions->completions) + logger->cout(s.completion + "\t" + trim(s.description)); + return; + } if (args.helpRequested) { std::vector subcommand;