From c8f5204202229eb98df386bff347f0ad942c5482 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 29 Jun 2016 21:08:16 +0100 Subject: [PATCH] Try to make the json ui more tolerant with the json input Should improve the issues raised #714 --- src/json_ui.cc | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/json_ui.cc b/src/json_ui.cc index fd234154..c7829b1b 100644 --- a/src/json_ui.cc +++ b/src/json_ui.cc @@ -1,5 +1,6 @@ #include "json_ui.hh" +#include "containers.hh" #include "display_buffer.hh" #include "keys.hh" #include "file.hh" @@ -423,34 +424,32 @@ void JsonUI::parse_requests(EventMode mode) if (not m_requests.empty()) { - Value json; - const char* pos; + const char* pos = nullptr; try { + Value json; std::tie(json, pos) = parse_json(m_requests); + if (json) + eval_json(json); } catch (runtime_error& error) { - write_stderr(format("error while parsing requests '{}': '{}'", + write_stderr(format("error while handling requests '{}': '{}'", m_requests, error.what())); - } - if (json) - { - try - { - eval_json(json); - } - catch (runtime_error& error) - { - write_stderr(format("error while executing request '{}': '{}'", - StringView{m_requests.begin(), pos}, error.what())); - } - m_requests = String{pos, m_requests.end()}; + // 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()}; } - while (not m_pending_keys.empty()) + while (m_input_callback and not m_pending_keys.empty()) m_input_callback(mode); }