From 4902271ee74b301593b70f8b894ee33a10bbf48f Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 31 May 2016 14:57:45 -0700 Subject: [PATCH 1/3] If there is an error, return an empty object for user settings Otherwise the promise never settles and can block a response from the Kibana server. --- src/ui/settings/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui/settings/index.js b/src/ui/settings/index.js index c56acaf6cc52d..28f05b80cbc7b 100644 --- a/src/ui/settings/index.js +++ b/src/ui/settings/index.js @@ -29,7 +29,8 @@ export default function setupSettings(kbnServer, server, config) { return client .get({ ...clientSettings }) .then(res => res._source) - .then(user => hydrateUserSettings(user)); + .then(user => hydrateUserSettings(user)) + .catch(e => { return {}; }); } function setMany(changes) { From 357e3911950b501524c99434a14daa8721c51bd8 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 1 Jun 2016 16:07:12 -0700 Subject: [PATCH 2/3] Turn Kibana plugin red if user settings cannot be found --- src/ui/settings/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ui/settings/index.js b/src/ui/settings/index.js index 28f05b80cbc7b..b28f64bb28b5a 100644 --- a/src/ui/settings/index.js +++ b/src/ui/settings/index.js @@ -23,14 +23,20 @@ export default function setupSettings(kbnServer, server, config) { return Promise.resolve(defaultsProvider()); } + function userSettingsNotFound(kibanaVersion) { + const message = 'Could not find user-provided settings for this version of Kibana (' + kibanaVersion + ')'; + server.plugins.kibana.status.red(message); + return {}; + } + function getUserProvided() { const { client } = server.plugins.elasticsearch; const clientSettings = getClientSettings(config); return client .get({ ...clientSettings }) .then(res => res._source) - .then(user => hydrateUserSettings(user)) - .catch(e => { return {}; }); + .catch(userSettingsNotFound.bind(null, clientSettings.id)) + .then(user => hydrateUserSettings(user)); } function setMany(changes) { From 484e45f96d66bb5dbbc79f938ea5fcf28bbb3239 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Wed, 1 Jun 2016 17:26:26 -0700 Subject: [PATCH 3/3] Using _.partial() instead of bind() This is because bind() is typically used to change the value of this. As we aren't actually changing the value of this here, using _.partial() explains the intent more clearly, IMO. --- src/ui/settings/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/settings/index.js b/src/ui/settings/index.js index b28f64bb28b5a..bb6ced2edfe78 100644 --- a/src/ui/settings/index.js +++ b/src/ui/settings/index.js @@ -1,4 +1,4 @@ -import { defaultsDeep } from 'lodash'; +import { defaultsDeep, partial } from 'lodash'; import defaultsProvider from './defaults'; export default function setupSettings(kbnServer, server, config) { @@ -35,7 +35,7 @@ export default function setupSettings(kbnServer, server, config) { return client .get({ ...clientSettings }) .then(res => res._source) - .catch(userSettingsNotFound.bind(null, clientSettings.id)) + .catch(partial(userSettingsNotFound, clientSettings.id)) .then(user => hydrateUserSettings(user)); }