From 4bae6038cc320327bc0d056769baaab8a20c8d4d Mon Sep 17 00:00:00 2001 From: Christiane Heiligers Date: Tue, 18 May 2021 17:10:14 -0700 Subject: [PATCH] Removes unused properties from TransformSavedObjectDocumentError --- .../migrations/core/document_migrator.ts | 2 +- .../migrations/core/migrate_raw_docs.test.ts | 6 +---- ...nsform_saved_object_document_error.test.ts | 23 +------------------ .../transform_saved_object_document_error.ts | 13 +---------- .../saved_objects/migrationsv2/model.test.ts | 12 ++-------- 5 files changed, 6 insertions(+), 50 deletions(-) diff --git a/src/core/server/saved_objects/migrations/core/document_migrator.ts b/src/core/server/saved_objects/migrations/core/document_migrator.ts index f6bc0b901f793..d7b6059c55441 100644 --- a/src/core/server/saved_objects/migrations/core/document_migrator.ts +++ b/src/core/server/saved_objects/migrations/core/document_migrator.ts @@ -684,7 +684,7 @@ function wrapWithTry( log.error(error); // To make debugging failed migrations easier, we add items needed to convert the // saved object id to the full raw id (the id only contains the uuid part) and the full error itself - throw new TransformSavedObjectDocumentError(failedTransform, failedDoc, error); + throw new TransformSavedObjectDocumentError(error); } }; } diff --git a/src/core/server/saved_objects/migrations/core/migrate_raw_docs.test.ts b/src/core/server/saved_objects/migrations/core/migrate_raw_docs.test.ts index 8400c7e2d373c..7a6f72a881cd6 100644 --- a/src/core/server/saved_objects/migrations/core/migrate_raw_docs.test.ts +++ b/src/core/server/saved_objects/migrations/core/migrate_raw_docs.test.ts @@ -233,11 +233,7 @@ describe('migrateRawDocsSafely', () => { test('instance of Either.left containing transform errors when the transform function throws a TransformSavedObjectDocument error', async () => { const transform = jest.fn((doc: any) => { - throw new TransformSavedObjectDocumentError( - `${doc.type}1.2.3`, - JSON.stringify(doc), - new Error('error during transform') - ); + throw new TransformSavedObjectDocumentError(new Error('error during transform')); }); const task = migrateRawDocsSafely( new SavedObjectsSerializer(new SavedObjectTypeRegistry()), diff --git a/src/core/server/saved_objects/migrations/core/transform_saved_object_document_error.test.ts b/src/core/server/saved_objects/migrations/core/transform_saved_object_document_error.test.ts index e63926b4bc95e..1efb1bd726216 100644 --- a/src/core/server/saved_objects/migrations/core/transform_saved_object_document_error.test.ts +++ b/src/core/server/saved_objects/migrations/core/transform_saved_object_document_error.test.ts @@ -10,31 +10,10 @@ import { TransformSavedObjectDocumentError } from './transform_saved_object_docu describe('TransformSavedObjectDocumentError', () => { it('is a special error', () => { const originalError = new Error('Dang diggity!'); - const err = new TransformSavedObjectDocumentError( - 'failedTransform', - 'failedDoc', - originalError - ); + const err = new TransformSavedObjectDocumentError(originalError); expect(err).toBeInstanceOf(TransformSavedObjectDocumentError); expect(err.stack).not.toBeNull(); expect(err.originalError).toBe(originalError); - }); - it('constructs an special error message', () => { - const originalError = new Error('Dang diggity!'); - const err = new TransformSavedObjectDocumentError( - 'failedTransform', - 'failedDoc', - originalError - ); expect(err.message).toMatchInlineSnapshot(`"Dang diggity!"`); }); - it('handles undefined namespace', () => { - const originalError = new Error('Dang diggity!'); - const err = new TransformSavedObjectDocumentError( - 'failedTransform', - 'failedDoc', - originalError - ); - expect(err.failedTransform).toMatchInlineSnapshot(`"failedTransform"`); - }); }); diff --git a/src/core/server/saved_objects/migrations/core/transform_saved_object_document_error.ts b/src/core/server/saved_objects/migrations/core/transform_saved_object_document_error.ts index 553ffa7a3c878..2dc553545a08d 100644 --- a/src/core/server/saved_objects/migrations/core/transform_saved_object_document_error.ts +++ b/src/core/server/saved_objects/migrations/core/transform_saved_object_document_error.ts @@ -9,21 +9,10 @@ /** * Error thrown when saved object migrations encounter a transformation error. * Transformation errors happen when a transform function throws an error for an unsanitized saved object - * The id (doc.id) reported in this error class is just the uuid part and doesn't tell users what the full elasticsearch id is. - * in order to convert the id to the serialized version further upstream using serializer.generateRawId, we need to provide the following items: - * - namespace: doc.namespace, - * - type: doc.type, - * - id: doc.id, - * The new error class helps with v2 migrations. - * For backward compatibility with v1 migrations, the error message is the same as what was previously thrown as a plain error */ export class TransformSavedObjectDocumentError extends Error { - constructor( - public readonly failedTransform: string, // created by document_migrator wrapWithTry as `${type.name}:${version}`; - public readonly failedDoc: string, - public readonly originalError: Error - ) { + constructor(public readonly originalError: Error) { super(`${originalError.message}`); } } diff --git a/src/core/server/saved_objects/migrationsv2/model.test.ts b/src/core/server/saved_objects/migrationsv2/model.test.ts index 191d152c2430a..186cb24b4a34a 100644 --- a/src/core/server/saved_objects/migrationsv2/model.test.ts +++ b/src/core/server/saved_objects/migrationsv2/model.test.ts @@ -1158,11 +1158,7 @@ describe('migrations v2 model', () => { it('OUTDATED_DOCUMENTS_SEARCH_READ -> FATAL if no outdated documents to transform and we have failed document migrations', () => { const corruptDocumentIdsCarriedOver = ['a:somethingelse']; const originalTransformError = new Error('something went wrong'); - const transFormErr = new TransformSavedObjectDocumentError( - 'a: 7.12.0', - 'failedDoc', - originalTransformError - ); + const transFormErr = new TransformSavedObjectDocumentError(originalTransformError); const transformationErrors = [ { rawId: 'bob:tail', err: transFormErr }, ] as TransformErrorObjects[]; @@ -1226,11 +1222,7 @@ describe('migrations v2 model', () => { const outdatedDocuments = [{ _id: '1', _source: { type: 'vis' } }]; const corruptDocumentIds = ['a:somethingelse']; const originalTransformError = new Error('Dang diggity!'); - const transFormErr = new TransformSavedObjectDocumentError( - 'failedTransform', - 'failedDoc', - originalTransformError - ); + const transFormErr = new TransformSavedObjectDocumentError(originalTransformError); const transformationErrors = [ { rawId: 'bob:tail', err: transFormErr }, ] as TransformErrorObjects[];