From 69ccd5bbf5d6c923293495033e83655190575b67 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 5 Jan 2017 20:35:02 +0000 Subject: [PATCH] Fix init error message(s) formatting --- src/gui/html/js/initialise.js | 19 +++++++++++++------ src/gui/query/get_init_errors_query.h | 6 +----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/gui/html/js/initialise.js b/src/gui/html/js/initialise.js index 7762a202..e3fcebf8 100644 --- a/src/gui/html/js/initialise.js +++ b/src/gui/html/js/initialise.js @@ -131,18 +131,25 @@ function getInitErrors() { return query('getInitErrors').then((result) => { - if (JSON.parse(result)) { + const errors = JSON.parse(result); + if (errors.length > 0) { throw new Error(result); } }); } - function handleInitErrors(error) { - if (error.constructor === Array) { - dom.listInitErrors(JSON.parse(error.message)); - } else { - dom.listInitErrors([error.message]); + function getErrorMessages(string) { + /* error.message could be a message string or JSON encoding a list of + message strings. */ + try { + return JSON.parse(string); + } catch (error) { + return [string]; } + } + + function handleInitErrors(error) { + dom.listInitErrors(getErrorMessages(error.message)); Dialog.closeProgress(); dom.openDialog('settingsDialog'); } diff --git a/src/gui/query/get_init_errors_query.h b/src/gui/query/get_init_errors_query.h index d2d36b75..1af76afd 100644 --- a/src/gui/query/get_init_errors_query.h +++ b/src/gui/query/get_init_errors_query.h @@ -35,11 +35,7 @@ public: GetInitErrorsQuery(LootState& state) : state_(state) {} std::string executeLogic() { - YAML::Node node(state_.getInitErrors()); - if (node.size() > 0) - return JSON::stringify(node); - - return "null"; + return JSON::stringify(YAML::Node(state_.getInitErrors())); } private: