diff --git a/src/libcmd/repl-interacter.cc b/src/libcmd/repl-interacter.cc index d3567e021..843ebbbd2 100644 --- a/src/libcmd/repl-interacter.cc +++ b/src/libcmd/repl-interacter.cc @@ -1,6 +1,8 @@ #include #include #include +#include +#include #ifdef READLINE #include @@ -176,7 +178,14 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT if (!s) return false; - write_history(historyFile.c_str()); + if (write_history(historyFile.c_str()) != 0) { + // write_history returns the result of fclose() (which also flushes). + // We should explicitly ignore these errors, but log them so the user + // isn't confused why their history is getting eaten. + error_t const fcloseErr = errno; + std::string_view const errMsg(strerror(fcloseErr)); + warn("ignoring error writing repl history to %s: %s", historyFile, errMsg); + } input += s; input += '\n'; return true; @@ -184,7 +193,13 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT ReadlineLikeInteracter::~ReadlineLikeInteracter() { - write_history(historyFile.c_str()); + if (write_history(historyFile.c_str()) != 0) { + // write_history returns the result of fclose() (which also flushes). + // We should explicitly ignore these errors, but log them. + error_t const fcloseErr = errno; + std::string_view const errMsg(strerror(fcloseErr)); + warn("ignoring error writing repl history to %s: %s", historyFile, errMsg); + } } AutomationInteracter::Guard AutomationInteracter::init(detail::ReplCompleterMixin *)