Do not abort the client if temporary file for query editor cannot be created

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2023-12-06 20:02:39 +01:00
parent 9cf87f4261
commit 028c01c458

View File

@ -504,13 +504,14 @@ void ReplxxLineReader::addToHistory(const String & line)
void ReplxxLineReader::openEditor()
{
TemporaryFile editor_file("clickhouse_client_editor_XXXXXX.sql");
editor_file.write(rx.get_state().text());
editor_file.close();
char * const argv[] = {editor.data(), editor_file.getPath().data(), nullptr};
try
{
TemporaryFile editor_file("clickhouse_client_editor_XXXXXX.sql");
editor_file.write(rx.get_state().text());
editor_file.close();
char * const argv[] = {editor.data(), editor_file.getPath().data(), nullptr};
if (executeCommand(argv) == 0)
{
const std::string & new_query = readFile(editor_file.getPath());
@ -520,6 +521,7 @@ void ReplxxLineReader::openEditor()
catch (const std::runtime_error & e)
{
rx.print(e.what());
rx.print("\n");
}
if (bracketed_paste_enabled)