Fix: show actual errors on failed elements, handle null values from functions (#32600) (#32797)

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

![](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*

![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)

![screenshot 2019-03-06 16 18 17](https://user-images.githubusercontent.com/404731/53921039-562c6700-402c-11e9-9650-fc51d1f91643.png)

![screenshot 2019-03-06 16 19 01](https://user-images.githubusercontent.com/404731/53921044-5cbade80-402c-11e9-9cde-fdb49334dcd0.png)
This commit is contained in:
Joe Fleming 2019-03-08 13:23:58 -07:00 committed by GitHub
parent 5254c40e69
commit c63da63c64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,11 +72,15 @@ function runServerFunctions(server) {
.catch(err => {
if (Boom.isBoom(err)) {
return { err, statusCode: err.statusCode, message: err.output.payload };
} else if (err instanceof Error) {
return { err, statusCode: 500, message: err.message };
}
server.log(['interpreter', 'error'], err);
return { err: 'Internal Server Error', statusCode: 500, message: 'See server logs for details.' };
});
if (result == null) {
if (typeof result === 'undefined') {
const { functionName } = fnCall;
return {
id,