@mastra/dynamodb 0.11.1-alpha.0 → 0.11.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import { DynamoDBClient, DescribeTableCommand } from '@aws-sdk/client-dynamodb';
2
2
  import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
3
3
  import type { MastraMessageContentV2 } from '@mastra/core/agent';
4
4
  import { MessageList } from '@mastra/core/agent';
5
+ import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
5
6
  import type { StorageThreadType, MastraMessageV2, MastraMessageV1 } from '@mastra/core/memory';
6
7
 
7
8
  import {
@@ -21,6 +22,7 @@ import type {
21
22
  StorageGetTracesArg,
22
23
  PaginationInfo,
23
24
  StorageColumn,
25
+ TABLE_RESOURCES,
24
26
  } from '@mastra/core/storage';
25
27
  import type { Trace } from '@mastra/core/telemetry';
26
28
  import type { WorkflowRunState } from '@mastra/core/workflows';
@@ -37,6 +39,8 @@ export interface DynamoDBStoreConfig {
37
39
  };
38
40
  }
39
41
 
42
+ type SUPPORTED_TABLE_NAMES = Exclude<TABLE_NAMES, typeof TABLE_RESOURCES>;
43
+
40
44
  // Define a type for our service that allows string indexing
41
45
  type MastraService = Service<Record<string, any>> & {
42
46
  [key: string]: any;
@@ -63,25 +67,36 @@ export class DynamoDBStore extends MastraStorage {
63
67
  super({ name });
64
68
 
65
69
  // Validate required config
66
- if (!config.tableName || typeof config.tableName !== 'string' || config.tableName.trim() === '') {
67
- throw new Error('DynamoDBStore: config.tableName must be provided and cannot be empty.');
68
- }
69
- // Validate tableName characters (basic check)
70
- if (!/^[a-zA-Z0-9_.-]{3,255}$/.test(config.tableName)) {
71
- throw new Error(
72
- `DynamoDBStore: config.tableName "${config.tableName}" contains invalid characters or is not between 3 and 255 characters long.`,
73
- );
74
- }
70
+ try {
71
+ if (!config.tableName || typeof config.tableName !== 'string' || config.tableName.trim() === '') {
72
+ throw new Error('DynamoDBStore: config.tableName must be provided and cannot be empty.');
73
+ }
74
+ // Validate tableName characters (basic check)
75
+ if (!/^[a-zA-Z0-9_.-]{3,255}$/.test(config.tableName)) {
76
+ throw new Error(
77
+ `DynamoDBStore: config.tableName "${config.tableName}" contains invalid characters or is not between 3 and 255 characters long.`,
78
+ );
79
+ }
75
80
 
76
- const dynamoClient = new DynamoDBClient({
77
- region: config.region || 'us-east-1',
78
- endpoint: config.endpoint,
79
- credentials: config.credentials,
80
- });
81
+ const dynamoClient = new DynamoDBClient({
82
+ region: config.region || 'us-east-1',
83
+ endpoint: config.endpoint,
84
+ credentials: config.credentials,
85
+ });
81
86
 
82
- this.tableName = config.tableName;
83
- this.client = DynamoDBDocumentClient.from(dynamoClient);
84
- this.service = getElectroDbService(this.client, this.tableName) as MastraService;
87
+ this.tableName = config.tableName;
88
+ this.client = DynamoDBDocumentClient.from(dynamoClient);
89
+ this.service = getElectroDbService(this.client, this.tableName) as MastraService;
90
+ } catch (error) {
91
+ throw new MastraError(
92
+ {
93
+ id: 'STORAGE_DYNAMODB_STORE_CONSTRUCTOR_FAILED',
94
+ domain: ErrorDomain.STORAGE,
95
+ category: ErrorCategory.USER,
96
+ },
97
+ error,
98
+ );
99
+ }
85
100
 
86
101
  // We're using a single table design with ElectroDB,
87
102
  // so we don't need to create multiple tables
@@ -113,7 +128,15 @@ export class DynamoDBStore extends MastraStorage {
113
128
  this.logger.debug(`Table ${this.tableName} exists and is accessible`);
114
129
  } catch (error) {
115
130
  this.logger.error('Error validating table access', { tableName: this.tableName, error });
116
- throw error;
131
+ throw new MastraError(
132
+ {
133
+ id: 'STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_ACCESS_FAILED',
134
+ domain: ErrorDomain.STORAGE,
135
+ category: ErrorCategory.THIRD_PARTY,
136
+ details: { tableName: this.tableName },
137
+ },
138
+ error,
139
+ );
117
140
  }
118
141
  }
119
142
 
@@ -139,7 +162,15 @@ export class DynamoDBStore extends MastraStorage {
139
162
  }
140
163
 
141
164
  // For other errors (like permissions issues), we should throw
142
- throw error;
165
+ throw new MastraError(
166
+ {
167
+ id: 'STORAGE_DYNAMODB_STORE_VALIDATE_TABLE_EXISTS_FAILED',
168
+ domain: ErrorDomain.STORAGE,
169
+ category: ErrorCategory.THIRD_PARTY,
170
+ details: { tableName: this.tableName },
171
+ },
172
+ error,
173
+ );
143
174
  }
144
175
  }
145
176
 
@@ -166,7 +197,15 @@ export class DynamoDBStore extends MastraStorage {
166
197
  // The error has already been handled by _performInitializationAndStore
167
198
  // (i.e., this.hasInitialized was reset). Re-throwing here ensures
168
199
  // the caller of init() is aware of the failure.
169
- throw error;
200
+ throw new MastraError(
201
+ {
202
+ id: 'STORAGE_DYNAMODB_STORE_INIT_FAILED',
203
+ domain: ErrorDomain.STORAGE,
204
+ category: ErrorCategory.THIRD_PARTY,
205
+ details: { tableName: this.tableName },
206
+ },
207
+ error,
208
+ );
170
209
  }
171
210
  }
172
211
 
@@ -227,12 +266,18 @@ export class DynamoDBStore extends MastraStorage {
227
266
  /**
228
267
  * Clear all items from a logical "table" (entity type)
229
268
  */
230
- async clearTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
269
+ async clearTable({ tableName }: { tableName: SUPPORTED_TABLE_NAMES }): Promise<void> {
231
270
  this.logger.debug('DynamoDB clearTable called', { tableName });
232
271
 
233
272
  const entityName = this.getEntityNameForTable(tableName);
234
273
  if (!entityName || !this.service.entities[entityName]) {
235
- throw new Error(`No entity defined for ${tableName}`);
274
+ throw new MastraError({
275
+ id: 'STORAGE_DYNAMODB_STORE_CLEAR_TABLE_INVALID_ARGS',
276
+ domain: ErrorDomain.STORAGE,
277
+ category: ErrorCategory.USER,
278
+ text: 'No entity defined for tableName',
279
+ details: { tableName },
280
+ });
236
281
  }
237
282
 
238
283
  try {
@@ -302,20 +347,39 @@ export class DynamoDBStore extends MastraStorage {
302
347
 
303
348
  this.logger.debug(`Successfully cleared all records for ${tableName}`);
304
349
  } catch (error) {
305
- this.logger.error('Failed to clear table', { tableName, error });
306
- throw error;
350
+ throw new MastraError(
351
+ {
352
+ id: 'STORAGE_DYNAMODB_STORE_CLEAR_TABLE_FAILED',
353
+ domain: ErrorDomain.STORAGE,
354
+ category: ErrorCategory.THIRD_PARTY,
355
+ details: { tableName },
356
+ },
357
+ error,
358
+ );
307
359
  }
308
360
  }
309
361
 
310
362
  /**
311
363
  * Insert a record into the specified "table" (entity)
312
364
  */
313
- async insert({ tableName, record }: { tableName: TABLE_NAMES; record: Record<string, any> }): Promise<void> {
365
+ async insert({
366
+ tableName,
367
+ record,
368
+ }: {
369
+ tableName: SUPPORTED_TABLE_NAMES;
370
+ record: Record<string, any>;
371
+ }): Promise<void> {
314
372
  this.logger.debug('DynamoDB insert called', { tableName });
315
373
 
316
374
  const entityName = this.getEntityNameForTable(tableName);
317
375
  if (!entityName || !this.service.entities[entityName]) {
318
- throw new Error(`No entity defined for ${tableName}`);
376
+ throw new MastraError({
377
+ id: 'STORAGE_DYNAMODB_STORE_INSERT_INVALID_ARGS',
378
+ domain: ErrorDomain.STORAGE,
379
+ category: ErrorCategory.USER,
380
+ text: 'No entity defined for tableName',
381
+ details: { tableName },
382
+ });
319
383
  }
320
384
 
321
385
  try {
@@ -323,20 +387,39 @@ export class DynamoDBStore extends MastraStorage {
323
387
  const dataToSave = { entity: entityName, ...this.preprocessRecord(record) };
324
388
  await this.service.entities[entityName].create(dataToSave).go();
325
389
  } catch (error) {
326
- this.logger.error('Failed to insert record', { tableName, error });
327
- throw error;
390
+ throw new MastraError(
391
+ {
392
+ id: 'STORAGE_DYNAMODB_STORE_INSERT_FAILED',
393
+ domain: ErrorDomain.STORAGE,
394
+ category: ErrorCategory.THIRD_PARTY,
395
+ details: { tableName },
396
+ },
397
+ error,
398
+ );
328
399
  }
329
400
  }
330
401
 
331
402
  /**
332
403
  * Insert multiple records as a batch
333
404
  */
334
- async batchInsert({ tableName, records }: { tableName: TABLE_NAMES; records: Record<string, any>[] }): Promise<void> {
405
+ async batchInsert({
406
+ tableName,
407
+ records,
408
+ }: {
409
+ tableName: SUPPORTED_TABLE_NAMES;
410
+ records: Record<string, any>[];
411
+ }): Promise<void> {
335
412
  this.logger.debug('DynamoDB batchInsert called', { tableName, count: records.length });
336
413
 
337
414
  const entityName = this.getEntityNameForTable(tableName);
338
415
  if (!entityName || !this.service.entities[entityName]) {
339
- throw new Error(`No entity defined for ${tableName}`);
416
+ throw new MastraError({
417
+ id: 'STORAGE_DYNAMODB_STORE_BATCH_INSERT_INVALID_ARGS',
418
+ domain: ErrorDomain.STORAGE,
419
+ category: ErrorCategory.USER,
420
+ text: 'No entity defined for tableName',
421
+ details: { tableName },
422
+ });
340
423
  }
341
424
 
342
425
  // Add entity type and preprocess each record
@@ -366,20 +449,39 @@ export class DynamoDBStore extends MastraStorage {
366
449
  // Original batch call: await this.service.entities[entityName].create(batch).go();
367
450
  }
368
451
  } catch (error) {
369
- this.logger.error('Failed to batch insert records', { tableName, error });
370
- throw error;
452
+ throw new MastraError(
453
+ {
454
+ id: 'STORAGE_DYNAMODB_STORE_BATCH_INSERT_FAILED',
455
+ domain: ErrorDomain.STORAGE,
456
+ category: ErrorCategory.THIRD_PARTY,
457
+ details: { tableName },
458
+ },
459
+ error,
460
+ );
371
461
  }
372
462
  }
373
463
 
374
464
  /**
375
465
  * Load a record by its keys
376
466
  */
377
- async load<R>({ tableName, keys }: { tableName: TABLE_NAMES; keys: Record<string, string> }): Promise<R | null> {
467
+ async load<R>({
468
+ tableName,
469
+ keys,
470
+ }: {
471
+ tableName: SUPPORTED_TABLE_NAMES;
472
+ keys: Record<string, string>;
473
+ }): Promise<R | null> {
378
474
  this.logger.debug('DynamoDB load called', { tableName, keys });
379
475
 
380
476
  const entityName = this.getEntityNameForTable(tableName);
381
477
  if (!entityName || !this.service.entities[entityName]) {
382
- throw new Error(`No entity defined for ${tableName}`);
478
+ throw new MastraError({
479
+ id: 'STORAGE_DYNAMODB_STORE_LOAD_INVALID_ARGS',
480
+ domain: ErrorDomain.STORAGE,
481
+ category: ErrorCategory.USER,
482
+ text: 'No entity defined for tableName',
483
+ details: { tableName },
484
+ });
383
485
  }
384
486
 
385
487
  try {
@@ -404,8 +506,15 @@ export class DynamoDBStore extends MastraStorage {
404
506
 
405
507
  return data as R;
406
508
  } catch (error) {
407
- this.logger.error('Failed to load record', { tableName, keys, error });
408
- throw error;
509
+ throw new MastraError(
510
+ {
511
+ id: 'STORAGE_DYNAMODB_STORE_LOAD_FAILED',
512
+ domain: ErrorDomain.STORAGE,
513
+ category: ErrorCategory.THIRD_PARTY,
514
+ details: { tableName },
515
+ },
516
+ error,
517
+ );
409
518
  }
410
519
  }
411
520
 
@@ -430,8 +539,15 @@ export class DynamoDBStore extends MastraStorage {
430
539
  // metadata is already transformed by the entity's getter
431
540
  } as StorageThreadType;
432
541
  } catch (error) {
433
- this.logger.error('Failed to get thread by ID', { threadId, error });
434
- throw error;
542
+ throw new MastraError(
543
+ {
544
+ id: 'STORAGE_DYNAMODB_STORE_GET_THREAD_BY_ID_FAILED',
545
+ domain: ErrorDomain.STORAGE,
546
+ category: ErrorCategory.THIRD_PARTY,
547
+ details: { threadId },
548
+ },
549
+ error,
550
+ );
435
551
  }
436
552
  }
437
553
 
@@ -454,8 +570,15 @@ export class DynamoDBStore extends MastraStorage {
454
570
  // metadata is already transformed by the entity's getter
455
571
  })) as StorageThreadType[];
456
572
  } catch (error) {
457
- this.logger.error('Failed to get threads by resource ID', { resourceId, error });
458
- throw error;
573
+ throw new MastraError(
574
+ {
575
+ id: 'STORAGE_DYNAMODB_STORE_GET_THREADS_BY_RESOURCE_ID_FAILED',
576
+ domain: ErrorDomain.STORAGE,
577
+ category: ErrorCategory.THIRD_PARTY,
578
+ details: { resourceId },
579
+ },
580
+ error,
581
+ );
459
582
  }
460
583
  }
461
584
 
@@ -486,8 +609,15 @@ export class DynamoDBStore extends MastraStorage {
486
609
  metadata: thread.metadata,
487
610
  };
488
611
  } catch (error) {
489
- this.logger.error('Failed to save thread', { threadId: thread.id, error });
490
- throw error;
612
+ throw new MastraError(
613
+ {
614
+ id: 'STORAGE_DYNAMODB_STORE_SAVE_THREAD_FAILED',
615
+ domain: ErrorDomain.STORAGE,
616
+ category: ErrorCategory.THIRD_PARTY,
617
+ details: { threadId: thread.id },
618
+ },
619
+ error,
620
+ );
491
621
  }
492
622
  }
493
623
 
@@ -542,8 +672,15 @@ export class DynamoDBStore extends MastraStorage {
542
672
  updatedAt: now,
543
673
  };
544
674
  } catch (error) {
545
- this.logger.error('Failed to update thread', { threadId: id, error });
546
- throw error;
675
+ throw new MastraError(
676
+ {
677
+ id: 'STORAGE_DYNAMODB_STORE_UPDATE_THREAD_FAILED',
678
+ domain: ErrorDomain.STORAGE,
679
+ category: ErrorCategory.THIRD_PARTY,
680
+ details: { threadId: id },
681
+ },
682
+ error,
683
+ );
547
684
  }
548
685
  }
549
686
 
@@ -559,8 +696,15 @@ export class DynamoDBStore extends MastraStorage {
559
696
  // 2. Delete any vector embeddings related to this thread
560
697
  // These would be additional operations
561
698
  } catch (error) {
562
- this.logger.error('Failed to delete thread', { threadId, error });
563
- throw error;
699
+ throw new MastraError(
700
+ {
701
+ id: 'STORAGE_DYNAMODB_STORE_DELETE_THREAD_FAILED',
702
+ domain: ErrorDomain.STORAGE,
703
+ category: ErrorCategory.THIRD_PARTY,
704
+ details: { threadId },
705
+ },
706
+ error,
707
+ );
564
708
  }
565
709
  }
566
710
 
@@ -580,12 +724,13 @@ export class DynamoDBStore extends MastraStorage {
580
724
  // Provide *all* composite key components for the 'byThread' index ('entity', 'threadId')
581
725
  const query = this.service.entities.message.query.byThread({ entity: 'message', threadId });
582
726
 
727
+ const limit = this.resolveMessageLimit({ last: selectBy?.last, defaultLimit: Number.MAX_SAFE_INTEGER });
583
728
  // Apply the 'last' limit if provided
584
- if (selectBy?.last && typeof selectBy.last === 'number') {
729
+ if (limit !== Number.MAX_SAFE_INTEGER) {
585
730
  // Use ElectroDB's limit parameter
586
731
  // DDB GSIs are sorted in ascending order
587
732
  // Use ElectroDB's order parameter to sort in descending order to retrieve 'latest' messages
588
- const results = await query.go({ limit: selectBy.last, order: 'desc' });
733
+ const results = await query.go({ limit, order: 'desc' });
589
734
  // Use arrow function in map to preserve 'this' context for parseMessageData
590
735
  const list = new MessageList({ threadId, resourceId }).add(
591
736
  results.data.map((data: any) => this.parseMessageData(data)),
@@ -605,8 +750,15 @@ export class DynamoDBStore extends MastraStorage {
605
750
  if (format === `v2`) return list.get.all.v2();
606
751
  return list.get.all.v1();
607
752
  } catch (error) {
608
- this.logger.error('Failed to get messages', { threadId, error });
609
- throw error;
753
+ throw new MastraError(
754
+ {
755
+ id: 'STORAGE_DYNAMODB_STORE_GET_MESSAGES_FAILED',
756
+ domain: ErrorDomain.STORAGE,
757
+ category: ErrorCategory.THIRD_PARTY,
758
+ details: { threadId },
759
+ },
760
+ error,
761
+ );
610
762
  }
611
763
  }
612
764
  async saveMessages(args: { messages: MastraMessageV1[]; format?: undefined | 'v1' }): Promise<MastraMessageV1[]>;
@@ -666,7 +818,7 @@ export class DynamoDBStore extends MastraStorage {
666
818
  this.logger.error('Missing entity property in message data for create', { messageData });
667
819
  throw new Error('Internal error: Missing entity property during saveMessages');
668
820
  }
669
- await this.service.entities.message.create(messageData).go();
821
+ await this.service.entities.message.put(messageData).go();
670
822
  }
671
823
  }),
672
824
  // Update thread's updatedAt timestamp
@@ -682,8 +834,15 @@ export class DynamoDBStore extends MastraStorage {
682
834
  if (format === `v1`) return list.get.all.v1();
683
835
  return list.get.all.v2();
684
836
  } catch (error) {
685
- this.logger.error('Failed to save messages', { error });
686
- throw error;
837
+ throw new MastraError(
838
+ {
839
+ id: 'STORAGE_DYNAMODB_STORE_SAVE_MESSAGES_FAILED',
840
+ domain: ErrorDomain.STORAGE,
841
+ category: ErrorCategory.THIRD_PARTY,
842
+ details: { count: messages.length },
843
+ },
844
+ error,
845
+ );
687
846
  }
688
847
  }
689
848
 
@@ -747,8 +906,14 @@ export class DynamoDBStore extends MastraStorage {
747
906
 
748
907
  return items;
749
908
  } catch (error) {
750
- this.logger.error('Failed to get traces', { error });
751
- throw error;
909
+ throw new MastraError(
910
+ {
911
+ id: 'STORAGE_DYNAMODB_STORE_GET_TRACES_FAILED',
912
+ domain: ErrorDomain.STORAGE,
913
+ category: ErrorCategory.THIRD_PARTY,
914
+ },
915
+ error,
916
+ );
752
917
  }
753
918
  }
754
919
 
@@ -767,8 +932,15 @@ export class DynamoDBStore extends MastraStorage {
767
932
  records: recordsToSave, // Pass records with 'entity' included
768
933
  });
769
934
  } catch (error) {
770
- this.logger.error('Failed to batch insert traces', { error });
771
- throw error;
935
+ throw new MastraError(
936
+ {
937
+ id: 'STORAGE_DYNAMODB_STORE_BATCH_TRACE_INSERT_FAILED',
938
+ domain: ErrorDomain.STORAGE,
939
+ category: ErrorCategory.THIRD_PARTY,
940
+ details: { count: records.length },
941
+ },
942
+ error,
943
+ );
772
944
  }
773
945
  }
774
946
 
@@ -800,8 +972,15 @@ export class DynamoDBStore extends MastraStorage {
800
972
  // Use upsert instead of create to handle both create and update cases
801
973
  await this.service.entities.workflowSnapshot.upsert(data).go();
802
974
  } catch (error) {
803
- this.logger.error('Failed to persist workflow snapshot', { workflowName, runId, error });
804
- throw error;
975
+ throw new MastraError(
976
+ {
977
+ id: 'STORAGE_DYNAMODB_STORE_PERSIST_WORKFLOW_SNAPSHOT_FAILED',
978
+ domain: ErrorDomain.STORAGE,
979
+ category: ErrorCategory.THIRD_PARTY,
980
+ details: { workflowName, runId },
981
+ },
982
+ error,
983
+ );
805
984
  }
806
985
  }
807
986
 
@@ -832,8 +1011,15 @@ export class DynamoDBStore extends MastraStorage {
832
1011
  // Parse the snapshot string
833
1012
  return result.data.snapshot as WorkflowRunState;
834
1013
  } catch (error) {
835
- this.logger.error('Failed to load workflow snapshot', { workflowName, runId, error });
836
- throw error;
1014
+ throw new MastraError(
1015
+ {
1016
+ id: 'STORAGE_DYNAMODB_STORE_LOAD_WORKFLOW_SNAPSHOT_FAILED',
1017
+ domain: ErrorDomain.STORAGE,
1018
+ category: ErrorCategory.THIRD_PARTY,
1019
+ details: { workflowName, runId },
1020
+ },
1021
+ error,
1022
+ );
837
1023
  }
838
1024
  }
839
1025
 
@@ -923,8 +1109,15 @@ export class DynamoDBStore extends MastraStorage {
923
1109
  total,
924
1110
  };
925
1111
  } catch (error) {
926
- this.logger.error('Failed to get workflow runs', { error });
927
- throw error;
1112
+ throw new MastraError(
1113
+ {
1114
+ id: 'STORAGE_DYNAMODB_STORE_GET_WORKFLOW_RUNS_FAILED',
1115
+ domain: ErrorDomain.STORAGE,
1116
+ category: ErrorCategory.THIRD_PARTY,
1117
+ details: { workflowName: args?.workflowName || '', resourceId: args?.resourceId || '' },
1118
+ },
1119
+ error,
1120
+ );
928
1121
  }
929
1122
  }
930
1123
 
@@ -995,8 +1188,15 @@ export class DynamoDBStore extends MastraStorage {
995
1188
  resourceId: matchingRunDbItem.resourceId,
996
1189
  };
997
1190
  } catch (error) {
998
- this.logger.error('Failed to get workflow run by ID', { runId, workflowName, error });
999
- throw error;
1191
+ throw new MastraError(
1192
+ {
1193
+ id: 'STORAGE_DYNAMODB_STORE_GET_WORKFLOW_RUN_BY_ID_FAILED',
1194
+ domain: ErrorDomain.STORAGE,
1195
+ category: ErrorCategory.THIRD_PARTY,
1196
+ details: { runId, workflowName: args?.workflowName || '' },
1197
+ },
1198
+ error,
1199
+ );
1000
1200
  }
1001
1201
  }
1002
1202
 
@@ -1013,8 +1213,8 @@ export class DynamoDBStore extends MastraStorage {
1013
1213
  }
1014
1214
 
1015
1215
  // Helper methods for entity/table mapping
1016
- private getEntityNameForTable(tableName: TABLE_NAMES): string | null {
1017
- const mapping: Record<TABLE_NAMES, string> = {
1216
+ private getEntityNameForTable(tableName: SUPPORTED_TABLE_NAMES): string | null {
1217
+ const mapping: Record<SUPPORTED_TABLE_NAMES, string> = {
1018
1218
  [TABLE_THREADS]: 'thread',
1019
1219
  [TABLE_MESSAGES]: 'message',
1020
1220
  [TABLE_WORKFLOW_SNAPSHOT]: 'workflowSnapshot',
@@ -1098,13 +1298,27 @@ export class DynamoDBStore extends MastraStorage {
1098
1298
  }
1099
1299
  });
1100
1300
  } catch (error) {
1101
- this.logger.error('Failed to get evals by agent name', { agentName, type, error });
1102
- throw error;
1301
+ throw new MastraError(
1302
+ {
1303
+ id: 'STORAGE_DYNAMODB_STORE_GET_EVALS_BY_AGENT_NAME_FAILED',
1304
+ domain: ErrorDomain.STORAGE,
1305
+ category: ErrorCategory.THIRD_PARTY,
1306
+ details: { agentName },
1307
+ },
1308
+ error,
1309
+ );
1103
1310
  }
1104
1311
  }
1105
1312
 
1106
1313
  async getTracesPaginated(_args: StorageGetTracesArg): Promise<PaginationInfo & { traces: Trace[] }> {
1107
- throw new Error('Method not implemented.');
1314
+ throw new MastraError(
1315
+ {
1316
+ id: 'STORAGE_DYNAMODB_STORE_GET_TRACES_PAGINATED_FAILED',
1317
+ domain: ErrorDomain.STORAGE,
1318
+ category: ErrorCategory.THIRD_PARTY,
1319
+ },
1320
+ new Error('Method not implemented.'),
1321
+ );
1108
1322
  }
1109
1323
 
1110
1324
  async getThreadsByResourceIdPaginated(_args: {
@@ -1112,13 +1326,27 @@ export class DynamoDBStore extends MastraStorage {
1112
1326
  page?: number;
1113
1327
  perPage?: number;
1114
1328
  }): Promise<PaginationInfo & { threads: StorageThreadType[] }> {
1115
- throw new Error('Method not implemented.');
1329
+ throw new MastraError(
1330
+ {
1331
+ id: 'STORAGE_DYNAMODB_STORE_GET_THREADS_BY_RESOURCE_ID_PAGINATED_FAILED',
1332
+ domain: ErrorDomain.STORAGE,
1333
+ category: ErrorCategory.THIRD_PARTY,
1334
+ },
1335
+ new Error('Method not implemented.'),
1336
+ );
1116
1337
  }
1117
1338
 
1118
1339
  async getMessagesPaginated(
1119
1340
  _args: StorageGetMessagesArg,
1120
1341
  ): Promise<PaginationInfo & { messages: MastraMessageV1[] | MastraMessageV2[] }> {
1121
- throw new Error('Method not implemented.');
1342
+ throw new MastraError(
1343
+ {
1344
+ id: 'STORAGE_DYNAMODB_STORE_GET_MESSAGES_PAGINATED_FAILED',
1345
+ domain: ErrorDomain.STORAGE,
1346
+ category: ErrorCategory.THIRD_PARTY,
1347
+ },
1348
+ new Error('Method not implemented.'),
1349
+ );
1122
1350
  }
1123
1351
 
1124
1352
  /**
@@ -1131,9 +1359,14 @@ export class DynamoDBStore extends MastraStorage {
1131
1359
  this.client.destroy();
1132
1360
  this.logger.debug('DynamoDB client closed successfully for store:', { name: this.name });
1133
1361
  } catch (error) {
1134
- this.logger.error('Error closing DynamoDB client for store:', { name: this.name, error });
1135
- // Optionally re-throw or handle as appropriate for your application's error handling strategy
1136
- throw error;
1362
+ throw new MastraError(
1363
+ {
1364
+ id: 'STORAGE_DYNAMODB_STORE_CLOSE_FAILED',
1365
+ domain: ErrorDomain.STORAGE,
1366
+ category: ErrorCategory.THIRD_PARTY,
1367
+ },
1368
+ error,
1369
+ );
1137
1370
  }
1138
1371
  }
1139
1372