Skip to content

Commit

Permalink
Removes unused properties from TransformSavedObjectDocumentError
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed May 19, 2021
1 parent 8d81a96 commit 4bae603
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any>((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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
12 changes: 2 additions & 10 deletions src/core/server/saved_objects/migrationsv2/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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[];
Expand Down

0 comments on commit 4bae603

Please sign in to comment.