From cae62046c510e5b05f99877f384c95b42657dee6 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Tue, 22 Oct 2024 13:07:22 +0200 Subject: [PATCH 1/4] Add searchSourceStart.create error handling --- packages/kbn-generate-csv/src/generate_csv.ts | 19 ++++++++++++++++++- packages/kbn-reporting/common/errors.ts | 7 +++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/kbn-generate-csv/src/generate_csv.ts b/packages/kbn-generate-csv/src/generate_csv.ts index cafc6600f51a3..3c3d2e9abef05 100644 --- a/packages/kbn-generate-csv/src/generate_csv.ts +++ b/packages/kbn-generate-csv/src/generate_csv.ts @@ -26,10 +26,12 @@ import { byteSizeValueToNumber, CancellationToken, ReportingError, + ReportingSavedObjectNotFoundError, } from '@kbn/reporting-common'; import type { TaskInstanceFields, TaskRunResult } from '@kbn/reporting-common/types'; import type { ReportingConfigType } from '@kbn/reporting-server'; +import { TaskErrorSource, createTaskRunError } from '@kbn/task-manager-plugin/server'; import { CONTENT_TYPE_CSV } from '../constants'; import type { JobParamsCSV } from '../types'; import { getExportSettings, type CsvExportSettings } from './lib/get_export_settings'; @@ -235,6 +237,21 @@ export class CsvGenerator { public async generateData(): Promise { const logger = this.logger; + + const createSearchSource = async () => { + try { + const source = await this.dependencies.searchSourceStart.create(this.job.searchSource); + return source; + } catch (err) { + // Saved object not found + if (err?.output?.statusCode === 404) { + const reportingError = new ReportingSavedObjectNotFoundError(err); + throw createTaskRunError(reportingError, TaskErrorSource.USER); + } + throw new Error(err); + } + }; + const [settings, searchSource] = await Promise.all([ getExportSettings( this.clients.uiSettings, @@ -243,7 +260,7 @@ export class CsvGenerator { this.job.browserTimezone, logger ), - this.dependencies.searchSourceStart.create(this.job.searchSource), + createSearchSource(), ]); const { startedAt, retryAt } = this.taskInstanceFields; diff --git a/packages/kbn-reporting/common/errors.ts b/packages/kbn-reporting/common/errors.ts index 9f45a1b6ae1d5..e32dd31bf52eb 100644 --- a/packages/kbn-reporting/common/errors.ts +++ b/packages/kbn-reporting/common/errors.ts @@ -152,3 +152,10 @@ export class VisualReportingSoftDisabledError extends ReportingError { }); } } + +export class ReportingSavedObjectNotFoundError extends ReportingError { + static code = 'reporting_saved_object_not_found' as const; + public get code(): string { + return ReportingSavedObjectNotFoundError.code; + } +} From e829cb6640c9617f8de531cd805fe3646d4d2f07 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Tue, 22 Oct 2024 15:24:08 +0200 Subject: [PATCH 2/4] Remove redundant new Error call --- packages/kbn-generate-csv/src/generate_csv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-generate-csv/src/generate_csv.ts b/packages/kbn-generate-csv/src/generate_csv.ts index 3c3d2e9abef05..5ed92df84c581 100644 --- a/packages/kbn-generate-csv/src/generate_csv.ts +++ b/packages/kbn-generate-csv/src/generate_csv.ts @@ -248,7 +248,7 @@ export class CsvGenerator { const reportingError = new ReportingSavedObjectNotFoundError(err); throw createTaskRunError(reportingError, TaskErrorSource.USER); } - throw new Error(err); + throw err; } }; From a40ed7610157584a1f1f741b7749c703bfd48a74 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:36:42 +0000 Subject: [PATCH 3/4] [CI] Auto-commit changed files from 'node scripts/yarn_deduplicate' --- packages/kbn-generate-csv/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kbn-generate-csv/tsconfig.json b/packages/kbn-generate-csv/tsconfig.json index b57990c20eb4a..4216438b6689a 100644 --- a/packages/kbn-generate-csv/tsconfig.json +++ b/packages/kbn-generate-csv/tsconfig.json @@ -30,5 +30,6 @@ "@kbn/es-types", "@kbn/data-views-plugin", "@kbn/search-types", + "@kbn/task-manager-plugin", ] } From 1ca392956669056b2b92f2ced6f0128cd488cf47 Mon Sep 17 00:00:00 2001 From: Krzysztof Date: Tue, 22 Oct 2024 16:46:37 +0200 Subject: [PATCH 4/4] Update test --- packages/kbn-reporting/common/errors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-reporting/common/errors.ts b/packages/kbn-reporting/common/errors.ts index e32dd31bf52eb..45a299115bf1b 100644 --- a/packages/kbn-reporting/common/errors.ts +++ b/packages/kbn-reporting/common/errors.ts @@ -154,7 +154,7 @@ export class VisualReportingSoftDisabledError extends ReportingError { } export class ReportingSavedObjectNotFoundError extends ReportingError { - static code = 'reporting_saved_object_not_found' as const; + static code = 'reporting_saved_object_not_found_error' as const; public get code(): string { return ReportingSavedObjectNotFoundError.code; }