forked from lix-project/lix
repl: log errors writing to history file
These errors are now logged and explicitly ignored, rather than
implicitly ignored.
Change-Id: Ia26015466a17f2b11952df5317a4d150d79dc184
This commit is contained in:
parent
20981461d4
commit
3f9e7107d1
|
@ -1,6 +1,8 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <cerrno>
|
||||||
|
|
||||||
#ifdef READLINE
|
#ifdef READLINE
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
|
@ -176,15 +178,27 @@ bool ReadlineLikeInteracter::getLine(std::string & input, ReplPromptType promptT
|
||||||
if (!s)
|
if (!s)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
write_history(historyFile.c_str());
|
this->writeHistory();
|
||||||
input += s;
|
input += s;
|
||||||
input += '\n';
|
input += '\n';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadlineLikeInteracter::writeHistory()
|
||||||
|
{
|
||||||
|
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.
|
||||||
|
int const fcloseErr = errno;
|
||||||
|
std::string_view const errMsg(std::strerror(fcloseErr));
|
||||||
|
warn("ignoring error writing repl history to %s: %s", this->historyFile, errMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ReadlineLikeInteracter::~ReadlineLikeInteracter()
|
ReadlineLikeInteracter::~ReadlineLikeInteracter()
|
||||||
{
|
{
|
||||||
write_history(historyFile.c_str());
|
this->writeHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
AutomationInteracter::Guard AutomationInteracter::init(detail::ReplCompleterMixin *)
|
AutomationInteracter::Guard AutomationInteracter::init(detail::ReplCompleterMixin *)
|
||||||
|
|
|
@ -42,6 +42,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual Guard init(detail::ReplCompleterMixin * repl) override;
|
virtual Guard init(detail::ReplCompleterMixin * repl) override;
|
||||||
virtual bool getLine(std::string & input, ReplPromptType promptType) override;
|
virtual bool getLine(std::string & input, ReplPromptType promptType) override;
|
||||||
|
/** Writes the current history to the history file.
|
||||||
|
*
|
||||||
|
* This function logs but ignores errors from readline's write_history().
|
||||||
|
*/
|
||||||
|
virtual void writeHistory();
|
||||||
virtual ~ReadlineLikeInteracter() override;
|
virtual ~ReadlineLikeInteracter() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue