Skip to content
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

[Reporting] Add searchSourceStart.create error handling #197238

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/kbn-generate-csv/src/generate_csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -235,6 +237,21 @@ export class CsvGenerator {

public async generateData(): Promise<TaskRunResult> {
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 err;
}
};

const [settings, searchSource] = await Promise.all([
getExportSettings(
this.clients.uiSettings,
Expand All @@ -243,7 +260,7 @@ export class CsvGenerator {
this.job.browserTimezone,
logger
),
this.dependencies.searchSourceStart.create(this.job.searchSource),
createSearchSource(),
]);

const { startedAt, retryAt } = this.taskInstanceFields;
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-generate-csv/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
"@kbn/es-types",
"@kbn/data-views-plugin",
"@kbn/search-types",
"@kbn/task-manager-plugin",
]
}
7 changes: 7 additions & 0 deletions packages/kbn-reporting/common/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,10 @@ export class VisualReportingSoftDisabledError extends ReportingError {
});
}
}

export class ReportingSavedObjectNotFoundError extends ReportingError {
static code = 'reporting_saved_object_not_found_error' as const;
public get code(): string {
return ReportingSavedObjectNotFoundError.code;
}
}