Skip to content

Commit

Permalink
Display top-level error reason if no shard info is available
Browse files Browse the repository at this point in the history
For EQL queries, error responses do not contain `failed_shards`
information, and so our error toasts contained only a stack trace.

With this addition, we'll fall back to the top-level `error.reason` if
those fields are not present, giving the user better indication of
what's going on without having to inspect the actual network response.
  • Loading branch information
rylnd committed Oct 28, 2020
1 parent 2a4337e commit 649fe56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/plugins/data/public/search/errors/es_error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { EuiCodeBlock, EuiSpacer } from '@elastic/eui';
import { ApplicationStart } from 'kibana/public';
import { KbnError } from '../../../../kibana_utils/common';
import { IEsError } from './types';
import { getRootCause } from './utils';
import { getRootCause, getTopLevelCause } from './utils';

export class EsError extends KbnError {
constructor(protected readonly err: IEsError) {
Expand All @@ -31,13 +31,15 @@ export class EsError extends KbnError {

public getErrorMessage(application: ApplicationStart) {
const rootCause = getRootCause(this.err)?.reason;
const topLevelCause = getTopLevelCause(this.err)?.reason;
const cause = rootCause ?? topLevelCause;

return (
<>
<EuiSpacer size="s" />
{rootCause ? (
{cause ? (
<EuiCodeBlock data-test-subj="errMessage" isCopyable={true} paddingSize="s">
{rootCause}
{cause}
</EuiCodeBlock>
) : null}
</>
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/data/public/search/errors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function getFailedShards(err: IEsError) {
return failedShards ? failedShards[0] : undefined;
}

export function getTopLevelCause(err: IEsError) {
return err.body?.attributes?.error;
}

export function getRootCause(err: IEsError) {
return getFailedShards(err)?.reason;
}

0 comments on commit 649fe56

Please sign in to comment.