Try to make the json ui more tolerant with the json input

Should improve the issues raised #714
This commit is contained in:
Maxime Coste 2016-06-29 21:08:16 +01:00
parent 511367f977
commit c8f5204202

View File

@ -1,5 +1,6 @@
#include "json_ui.hh" #include "json_ui.hh"
#include "containers.hh"
#include "display_buffer.hh" #include "display_buffer.hh"
#include "keys.hh" #include "keys.hh"
#include "file.hh" #include "file.hh"
@ -422,35 +423,33 @@ void JsonUI::parse_requests(EventMode mode)
} }
if (not m_requests.empty()) if (not m_requests.empty())
{
const char* pos = nullptr;
try
{ {
Value json; Value json;
const char* pos;
try
{
std::tie(json, pos) = parse_json(m_requests); std::tie(json, pos) = parse_json(m_requests);
}
catch (runtime_error& error)
{
write_stderr(format("error while parsing requests '{}': '{}'",
m_requests, error.what()));
}
if (json) if (json)
{
try
{
eval_json(json); eval_json(json);
} }
catch (runtime_error& error) catch (runtime_error& error)
{ {
write_stderr(format("error while executing request '{}': '{}'", write_stderr(format("error while handling requests '{}': '{}'",
StringView{m_requests.begin(), pos}, error.what())); m_requests, error.what()));
// try to salvage request by dropping its first line
auto eol = find(m_requests, '\n');
if (eol != m_requests.end())
m_requests = String{eol+1, m_requests.end()};
else
m_requests = String{};
} }
if (pos)
m_requests = String{pos, m_requests.end()}; m_requests = String{pos, m_requests.end()};
} }
}
while (not m_pending_keys.empty()) while (m_input_callback and not m_pending_keys.empty())
m_input_callback(mode); m_input_callback(mode);
} }