From dbd5ebcb4d49d572ef2eebc8dd138b92a036c7d2 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Fri, 8 Mar 2019 11:48:11 -0700 Subject: [PATCH] Fix: show actual errors on failed elements, handle null values from functions (#32600) Closes https://github.com/elastic/kibana/issues/32356 This PR fixes two issues. The first there was an issue filed, #32356: - Show non-Boom errors instead of asking users to look at server logs - Also write the error to the server when asking them to look there ### Before ![](https://user-images.githubusercontent.com/404731/53673728-9368b180-3c46-11e9-912e-7aaff25d3ddf.png) *If the function failed for some reason, this is all you'd ever see* ### After ![screenshot 2019-03-06 16 24 09](https://user-images.githubusercontent.com/404731/53921029-4d3b9580-402c-11e9-85bf-21ab31e952bc.png) *Errors are shown to the user* ![screenshot 2019-03-06 16 26 16](https://user-images.githubusercontent.com/404731/53921130-a0154d00-402c-11e9-9cb5-102d360a69f8.png) *Code errors bubble up correctly as well* --- The other I didn't bother opening an issue for: - Fixes issue where functions that return `null` produce an error message - `null` is a valid thing to return, it's only `undefined` that causes a problem - This was only a problem for server functions that return `null` (currently, none of them do) - Introduced in #31298 - Discovered when I ran into casting problems (see https://github.com/elastic/kibana/issues/32597) ### Before ![screenshot 2019-03-06 16 18 17](https://user-images.githubusercontent.com/404731/53921039-562c6700-402c-11e9-9650-fc51d1f91643.png) ### After ![screenshot 2019-03-06 16 19 01](https://user-images.githubusercontent.com/404731/53921044-5cbade80-402c-11e9-9cde-fdb49334dcd0.png) --- .../interpreter/server/routes/server_functions.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/legacy/core_plugins/interpreter/server/routes/server_functions.js b/src/legacy/core_plugins/interpreter/server/routes/server_functions.js index cdd552e258ca9..c8a8f366a32c8 100644 --- a/src/legacy/core_plugins/interpreter/server/routes/server_functions.js +++ b/src/legacy/core_plugins/interpreter/server/routes/server_functions.js @@ -90,15 +90,19 @@ function runServerFunctions(server) { try { const result = await runFunction(server, handlers, fnCall); - if (result != null) { - return { id, statusCode: 200, result }; + if (typeof result === 'undefined') { + return batchError(id, `Function ${fnCall.functionName} did not return anything.`); } - return batchError(id, `Function ${fnCall.functionName} did not return anything.`); + return { id, statusCode: 200, result }; } catch (err) { if (Boom.isBoom(err)) { return batchError(id, err.output.payload, err.statusCode); + } else if (err instanceof Error) { + return batchError(id, err.message); } + + server.log(['interpreter', 'error'], err); return batchError(id, 'See server logs for details.'); } };