Skip to content

Commit

Permalink
fix: use external aggregate-error package to get better messages
Browse files Browse the repository at this point in the history
  • Loading branch information
swain committed Apr 23, 2024
1 parent df69a28 commit 6f6763c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"dependencies": {
"@aws-sdk/util-dynamodb": "^3.369.0",
"@types/aws-lambda": "^8.10.92",
"aggregate-error": "^3.0.0",
"lodash": "^4.17.21",
"p-map": "^4.0.0",
"uuid": "^8.3.2"
Expand Down
7 changes: 2 additions & 5 deletions src/dynamo-streams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,8 @@ describe('DynamoStreamHandler', () => {
{} as any,
);
} catch (e: any) {
expect(e).toBeInstanceOf(AggregateError);
expect(e.errors).toEqual([
new Error('Failed to process new-insert-2'),
new Error('Failed to process new-insert-3'),
]);
expect(e.message).toContain('Failed to process new-insert-2');
expect(e.message).toContain('Failed to process new-insert-3');
}

expect(dataSources.doSomething).toHaveBeenCalledTimes(1);
Expand Down
7 changes: 2 additions & 5 deletions src/kinesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,8 @@ describe('KinesisEventHandler', () => {
{} as any,
);
} catch (e: any) {
expect(e).toBeInstanceOf(AggregateError);
expect(e.errors).toEqual([
new Error('Failed to process test-event-2'),
new Error('Failed to process test-event-3'),
]);
expect(e.message).toContain('Failed to process test-event-2');
expect(e.message).toContain('Failed to process test-event-3');
}
});

Expand Down
11 changes: 6 additions & 5 deletions src/sqs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,12 @@ describe('SQSMessageHandler', () => {
{} as any,
);
} catch (e: any) {
expect(e).toBeInstanceOf(AggregateError);
expect(e.errors).toEqual([
new Error('Failed to process message test-event-3'),
new Error('Failed to process message test-event-7'),
]);
expect(e.message).toContain(
'Error: Failed to process message test-event-3',
);
expect(e.message).toContain(
'Error: Failed to process message test-event-7',
);
}
});

Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LoggerInterface } from '@lifeomic/logging';
import { Context } from 'aws-lambda';
import pMap from 'p-map';
import groupBy from 'lodash/groupBy';
import AggregateError from 'aggregate-error';

export type BaseContext = {
logger: LoggerInterface;
Expand Down

0 comments on commit 6f6763c

Please sign in to comment.