@adobe/spacecat-shared-data-access 3.6.1 → 3.6.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [@adobe/spacecat-shared-data-access-v3.6.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.6.1...@adobe/spacecat-shared-data-access-v3.6.2) (2026-03-04)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **data-access:** surface PG error details in logs ([#1401](https://github.com/adobe/spacecat-shared/issues/1401)) ([ddd3041](https://github.com/adobe/spacecat-shared/commit/ddd3041322a1468ee911f49f06c240a6697b8e66))
6
+
1
7
  ## [@adobe/spacecat-shared-data-access-v3.6.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.6.0...@adobe/spacecat-shared-data-access-v3.6.1) (2026-03-03)
2
8
 
3
9
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "3.6.1",
3
+ "version": "3.6.2",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -104,21 +104,29 @@ class BaseCollection {
104
104
  #isInvalidInputError(error) {
105
105
  let current = error;
106
106
  while (current) {
107
- if (current?.code === '22P02') {
108
- return true;
109
- }
107
+ if (current?.code === '22P02') return true;
110
108
  current = current.cause;
111
109
  }
112
110
  return false;
113
111
  }
114
112
 
115
113
  #logAndThrowError(message, cause) {
116
- const error = new DataAccessError(message, this, cause);
117
- this.log.error(`Base Collection Error [${this.entityName}]`, error);
118
- if (isNonEmptyArray(error.cause?.fields)) {
119
- this.log.error(`Validation errors: ${JSON.stringify(error.cause.fields)}`);
114
+ const parts = [message];
115
+ if (cause?.code) parts.push(`[${cause.code}] ${cause.message}`);
116
+ if (cause?.details) parts.push(cause.details);
117
+ if (cause?.hint) parts.push(`hint: ${cause.hint}`);
118
+
119
+ this.log.error(`[${this.entityName}] ${parts.join(' - ')}`);
120
+
121
+ if (isNonEmptyArray(cause?.fields)) {
122
+ this.log.error(`Validation errors: ${JSON.stringify(cause.fields)}`);
120
123
  }
121
- throw error;
124
+
125
+ throw new DataAccessError(
126
+ message,
127
+ { entityName: this.entityName, tableName: this.tableName },
128
+ cause,
129
+ );
122
130
  }
123
131
 
124
132
  #initializeCollectionMethods() {
@@ -547,7 +555,7 @@ class BaseCollection {
547
555
  const instances = this.#createInstances(allRows);
548
556
  return shouldReturnCursor ? { data: instances, cursor } : instances;
549
557
  } catch (error) {
550
- if (error instanceof DataAccessError) {
558
+ if (error.constructor === DataAccessError) {
551
559
  throw error;
552
560
  }
553
561
  return this.#logAndThrowError('Failed to query', error);
@@ -601,6 +609,7 @@ class BaseCollection {
601
609
  return isNonEmptyObject(item);
602
610
  }
603
611
 
612
+ // eslint-disable-next-line consistent-return
604
613
  async batchGetByKeys(keys, options = {}) {
605
614
  guardArray('keys', keys, this.entityName, 'any');
606
615
 
@@ -677,8 +686,11 @@ class BaseCollection {
677
686
  unprocessed: [],
678
687
  };
679
688
  } catch (error) {
680
- this.log.error(`Failed to batch get by keys [${this.entityName}]`, error);
681
- throw new DataAccessError('Failed to batch get by keys', this, error);
689
+ /* c8 ignore next 3 -- re-throw guard (exact match; excludes ValidationError subclass) */
690
+ if (error.constructor === DataAccessError) {
691
+ throw error;
692
+ }
693
+ this.#logAndThrowError('Failed to batch get by keys', error);
682
694
  }
683
695
  }
684
696
 
@@ -721,6 +733,8 @@ class BaseCollection {
721
733
  await this.#onCreate(instance);
722
734
  return instance;
723
735
  } catch (error) {
736
+ /* c8 ignore next -- re-throw guard (exact match; excludes ValidationError subclass) */
737
+ if (error.constructor === DataAccessError) throw error;
724
738
  return this.#logAndThrowError('Failed to create', error);
725
739
  }
726
740
  }
@@ -833,6 +847,8 @@ class BaseCollection {
833
847
  await this.#onCreateMany({ createdItems, errorItems });
834
848
  return { createdItems, errorItems };
835
849
  } catch (error) {
850
+ /* c8 ignore next -- re-throw guard (exact match; excludes ValidationError subclass) */
851
+ if (error.constructor === DataAccessError) throw error;
836
852
  return this.#logAndThrowError('Failed to create many', error);
837
853
  }
838
854
  }
@@ -856,7 +872,7 @@ class BaseCollection {
856
872
 
857
873
  const { error } = await query.select().maybeSingle();
858
874
  if (error) {
859
- throw new DataAccessError('Failed to update entity', this, error);
875
+ this.#logAndThrowError('Failed to update entity', error);
860
876
  }
861
877
  }
862
878
 
@@ -917,6 +933,8 @@ class BaseCollection {
917
933
  this.#invalidateCache();
918
934
  return undefined;
919
935
  } catch (error) {
936
+ /* c8 ignore next -- re-throw guard (exact match; excludes ValidationError subclass) */
937
+ if (error.constructor === DataAccessError) throw error;
920
938
  return this.#logAndThrowError('Failed to save many', error);
921
939
  }
922
940
  }
@@ -947,6 +965,8 @@ class BaseCollection {
947
965
  this.#invalidateCache();
948
966
  return undefined;
949
967
  } catch (error) {
968
+ /* c8 ignore next -- re-throw guard (exact match; excludes ValidationError subclass) */
969
+ if (error.constructor === DataAccessError) throw error;
950
970
  return this.#logAndThrowError('Failed to remove by IDs', error);
951
971
  }
952
972
  }