mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# Backport This will backport the following commits from `main` to `8.8`: - [[ML] Reverting use of isPopulatedObject in error utils (#159913)](https://github.com/elastic/kibana/pull/159913) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"James Gowdy","email":"jgowdy@elastic.co"},"sourceCommit":{"committedDate":"2023-06-19T12:52:11Z","message":"[ML] Reverting use of isPopulatedObject in error utils (#159913)\n\nPR https://github.com/elastic/kibana/pull/155372 moved our error utils\r\nto a package and also made a few small code changes, one of which added\r\n`isPopulatedObject` to the error object type guards.\r\n`isPopulatedObject` uses `Object.keys` under the hood which cannot be\r\nused to access the non-enumerable properties of an object, like Error's\r\n`message`.\r\n\r\n\r\n\r\n\r\nThis PR reverts all of these functions back to their original versions\r\nwhich had existed in ML for a while without issue.\r\n\r\nThis was change had been causing error messages to not display\r\ncorrectly.\r\n\r\n\r\n","sha":"8ca1789faa899f2e0a7abcf58fac50fa4d552af6","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","v8.9.0","v8.8.2"],"number":159913,"url":"https://github.com/elastic/kibana/pull/159913","mergeCommit":{"message":"[ML] Reverting use of isPopulatedObject in error utils (#159913)\n\nPR https://github.com/elastic/kibana/pull/155372 moved our error utils\r\nto a package and also made a few small code changes, one of which added\r\n`isPopulatedObject` to the error object type guards.\r\n`isPopulatedObject` uses `Object.keys` under the hood which cannot be\r\nused to access the non-enumerable properties of an object, like Error's\r\n`message`.\r\n\r\n\r\n\r\n\r\nThis PR reverts all of these functions back to their original versions\r\nwhich had existed in ML for a while without issue.\r\n\r\nThis was change had been causing error messages to not display\r\ncorrectly.\r\n\r\n\r\n","sha":"8ca1789faa899f2e0a7abcf58fac50fa4d552af6"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/159913","number":159913,"mergeCommit":{"message":"[ML] Reverting use of isPopulatedObject in error utils (#159913)\n\nPR https://github.com/elastic/kibana/pull/155372 moved our error utils\r\nto a package and also made a few small code changes, one of which added\r\n`isPopulatedObject` to the error object type guards.\r\n`isPopulatedObject` uses `Object.keys` under the hood which cannot be\r\nused to access the non-enumerable properties of an object, like Error's\r\n`message`.\r\n\r\n\r\n\r\n\r\nThis PR reverts all of these functions back to their original versions\r\nwhich had existed in ML for a while without issue.\r\n\r\nThis was change had been causing error messages to not display\r\ncorrectly.\r\n\r\n\r\n","sha":"8ca1789faa899f2e0a7abcf58fac50fa4d552af6"}},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: James Gowdy <jgowdy@elastic.co>
This commit is contained in:
parent
a7a6425553
commit
1147d386fb
1 changed files with 14 additions and 19 deletions
|
@ -10,7 +10,6 @@ import type Boom from '@hapi/boom';
|
|||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
|
||||
import type { IHttpFetchError } from '@kbn/core-http-browser';
|
||||
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
|
||||
|
||||
/**
|
||||
* Short hand type of estypes.ErrorCause.
|
||||
|
@ -144,53 +143,49 @@ export type ErrorType = MLHttpFetchError | EsErrorBody | Boom.Boom | string | un
|
|||
/**
|
||||
* Type guard to check if error is of type EsErrorBody
|
||||
* @export
|
||||
* @param {unknown} error
|
||||
* @param {any} error
|
||||
* @returns {error is EsErrorBody}
|
||||
*/
|
||||
export function isEsErrorBody(error: unknown): error is EsErrorBody {
|
||||
return isPopulatedObject(error, ['error']) && isPopulatedObject(error.error, ['reason']);
|
||||
export function isEsErrorBody(error: any): error is EsErrorBody {
|
||||
return error && error.error?.reason !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if error is a string.
|
||||
* @export
|
||||
* @param {unknown} error
|
||||
* @param {any} error
|
||||
* @returns {error is string}
|
||||
*/
|
||||
export function isErrorString(error: unknown): error is string {
|
||||
export function isErrorString(error: any): error is string {
|
||||
return typeof error === 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if error is of type ErrorMessage.
|
||||
* @export
|
||||
* @param {unknown} error
|
||||
* @param {any} error
|
||||
* @returns {error is ErrorMessage}
|
||||
*/
|
||||
export function isErrorMessage(error: unknown): error is ErrorMessage {
|
||||
return isPopulatedObject(error, ['message']) && typeof error.message === 'string';
|
||||
export function isErrorMessage(error: any): error is ErrorMessage {
|
||||
return error && error.message !== undefined && typeof error.message === 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if error is of type MLResponseError.
|
||||
* @export
|
||||
* @param {unknown} error
|
||||
* @param {any} error
|
||||
* @returns {error is MLResponseError}
|
||||
*/
|
||||
export function isMLResponseError(error: unknown): error is MLResponseError {
|
||||
return (
|
||||
isPopulatedObject(error, ['body']) &&
|
||||
isPopulatedObject(error.body, ['message']) &&
|
||||
'message' in error.body
|
||||
);
|
||||
export function isMLResponseError(error: any): error is MLResponseError {
|
||||
return typeof error.body === 'object' && 'message' in error.body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if error is of type Boom.
|
||||
* @export
|
||||
* @param {unknown} error
|
||||
* @param {any} error
|
||||
* @returns {error is Boom.Boom}
|
||||
*/
|
||||
export function isBoomError(error: unknown): error is Boom.Boom {
|
||||
return isPopulatedObject(error, ['isBoom']) && error.isBoom === true;
|
||||
export function isBoomError(error: any): error is Boom.Boom {
|
||||
return error?.isBoom === true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue