Catch exceptions when completing
If an exception is thrown inside of the completion callback, the program
just exits with no error message. This is because replxx' .input method
is wrapped in a big try-catch block. replxx just discards the exception.
(I would think the reason is that replxx doesn't want the terminal to be
messed up because of an uncaught exception)
The new code catches exceptions thrown by .completeCommand and prints
out the error message.
Change-Id: Ie6bd7800449f48ac455e6240aedbca9d08abcb05
diff --git a/src/cli.cpp b/src/cli.cpp
index 0635c28..efa9f7c 100644
--- a/src/cli.cpp
+++ b/src/cli.cpp
@@ -227,7 +227,12 @@
lineEditor.set_completion_callback([&parser](const std::string& input, int& context) {
std::stringstream stream;
- auto completions = parser.completeCommand(input, stream);
+ Completions completions;
+ try {
+ completions = parser.completeCommand(input, stream);
+ } catch (std::exception& ex) {
+ std::cerr << "Error while completing: " << ex.what() << "\n";
+ }
std::vector<replxx::Replxx::Completion> res;
std::copy(completions.m_completions.begin(), completions.m_completions.end(), std::back_inserter(res));