-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Vega] Better error explanation for EsErrors and inspector now showing error responses #112634
Conversation
Pinging @elastic/kibana-vis-editors (Team:VisEditors) |
@@ -17,7 +17,7 @@ export class EsError extends KbnError { | |||
readonly attributes: IEsError['attributes']; | |||
|
|||
constructor(protected readonly err: IEsError) { | |||
super('EsError'); | |||
super(`EsError: ${getRootCause(err)?.reason || err.attributes?.reason || 'unknown'}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just interesting is || err.attributes?.reason
needed? I see that case is handled in getRootCause -> getNestedCause.
requestResponders[requestId] | ||
); | ||
// now throw it again as the Vega parser will catch it and carry on with its flow | ||
return throwError(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: what if we continue to inspect search results as a side effects without modifying the main stream. I don't insist but I think the following code is more semantically right
tap(
(data) => this.inspectSearchResult(data, requestResponders[requestId]),
(err) =>
this.inspectSearchResult(
{
rawResponse: 'err' in err ? err.err : undefined,
},
requestResponders[requestId]
)
)
// catch the error and log it into the inspector | ||
this.inspectSearchResult( | ||
{ | ||
rawResponse: 'err' in err ? err.err : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: what if we replace it to err?.err
@@ -15,6 +15,15 @@ export function getFailedShards(err: KibanaServerError<any>): FailedShard | unde | |||
return failedShards ? failedShards[0] : undefined; | |||
} | |||
|
|||
function getNestedCause(err: KibanaServerError<any>): Reason { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you call getNestedCause
from getRootCause
. In parent method I see KibanaServerError
instead of KibanaServerError<any>
. I think we can remove <any>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thought about that.
But removing the any
will set the generic T
to unknown
with types errors that need to be addressed. I think this is a major problem with EsErrors that should be addressed in another PR by providing better types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this PR! LGTM, works like a charm :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dej611 this is a great improvement that will definitely help a lot of users!
I have one suggestion about avoiding the use of any
that I'd like to get your thoughts on. Let me know what you think!
@@ -17,7 +17,7 @@ export class EsError extends KbnError { | |||
readonly attributes: IEsError['attributes']; | |||
|
|||
constructor(protected readonly err: IEsError) { | |||
super('EsError'); | |||
super(`EsError: ${getRootCause(err)?.reason || 'unknown'}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is user-facing, we should consider translation:
i18n.translate('...', { defaultMessage: 'unknown' })
function getNestedCause(err: KibanaServerError<any>): Reason { | ||
const { type, reason, caused_by: causedBy } = err.attributes || err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid introducing additional any
s. Here is a possible alternative:
import type { ErrorCause } from '@elastic/elasticsearch/api/types';
...
function getNestedCause(err: KibanaServerError | ErrorCause): Reason {
const attr = ((err as KibanaServerError).attributes || err) as ErrorCause;
const { type, reason, caused_by: causedBy } = attr;
if (causedBy) {
return getNestedCause(causedBy);
}
return { type, reason };
}
We could improve KibanaServerError
by defaulting the generic to ErrorCause
. I'll open up an issue so that we can discuss that change separately. We could also add a new isKibanaServerError
predicate to avoid using as
as an improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. There's some more type work to do, in Lens we did inspect quite a bit the EsError shape (for our use cases) but the type error source is not precise itself (I've discussed with @delvedor before about mapping all possible EsError in types but it's a big task to tackle right now).
It's definitely possible to patch this now and open a discussion about error types improvement later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing my feedback @dej611 !
Did not test this locally but code changes look good to me!
@elasticmachine merge upstream |
Let's give it another round of tests. |
jenkins, test this |
💚 Build SucceededMetrics [docs]Page load bundle
History
To update your PR or re-run it, just comment with: |
…g error responses (elastic#112634) * 🐛 Fix EsError not showing info * 🐛 Record error response in the inspector * 🏷️ Fix type issue * 👌 Integrate feedback * 👌 Integrated latest feedback * 👌 i18n unknwon message * 👌 Integrate feedback * 🐛 Fix syntax error * 🏷️ Fix type issue Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…g error responses (#112634) (#112932) * 🐛 Fix EsError not showing info * 🐛 Record error response in the inspector * 🏷️ Fix type issue * 👌 Integrate feedback * 👌 Integrated latest feedback * 👌 i18n unknwon message * 👌 Integrate feedback * 🐛 Fix syntax error * 🏷️ Fix type issue Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Summary
Fixes #106478
This PR addresses two main bugs in Vega:
EsError
it now produces a better explanation of what it gone wrongNote: part of the fix here comes from the Lens error formatter. It would be nice to port most of the Lens error helpers logic into the
data/search
plugin in order to provide better error feedback for all Kibana.Checklist
Delete any items that are not applicable to this PR.