@cumulus/errors 21.0.0 → 21.0.1

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/dist/index.d.ts CHANGED
@@ -348,5 +348,13 @@ export declare const UnmetRequirementsError: {
348
348
  stack?: string | undefined;
349
349
  };
350
350
  };
351
+ /**
352
+ * Safely serializes an error-like object to JSON, removing circular references
353
+ * and including only own properties.
354
+ *
355
+ * @param err - The error or object to serialize
356
+ * @returns A JSON string representation of the object
357
+ */
358
+ export declare const errorify: (err: any) => string;
351
359
  export {};
352
360
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
+ /* eslint-disable max-classes-per-file */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnmetRequirementsError = exports.IndexExistsError = exports.PostgresUpdateFailed = exports.PostgresValidationError = exports.ValidationError = exports.UnparsableFileLocationError = exports.UnmatchedRegexError = exports.UnexpectedFileSize = exports.RecordDoesNotExist = exports.RecordAlreadyMigrated = exports.ProviderNotFound = exports.PDRParsingError = exports.MissingS3FileError = exports.MissingRequiredEnvVarError = exports.MissingRequiredEnvVar = exports.MissingRequiredArgument = exports.MismatchPdrCollection = exports.InvalidRegexError = exports.InvalidChecksum = exports.InvalidArgument = exports.HostNotFound = exports.GranuleFileWriteError = exports.GranuleNotPublished = exports.FTPError = exports.FileNotFound = exports.EcsStartTaskError = exports.DuplicateFile = exports.DeletePublishedGranule = exports.CumulusMessageError = exports.ConnectionTimeout = exports.ApiCollisionError = exports.MissingBucketMap = exports.CMRInternalError = exports.CMRMetaFileNotFound = exports.XmlMetaFileNotFound = exports.RemoteResourceError = exports.ResourcesLockedError = exports.IncompleteError = exports.NotNeededError = exports.WorkflowError = exports.isConditionalCheckException = exports.isWorkflowError = exports.isThrottlingException = exports.ThrottlingException = exports.createErrorType = void 0;
4
+ exports.errorify = exports.UnmetRequirementsError = exports.IndexExistsError = exports.PostgresUpdateFailed = exports.PostgresValidationError = exports.ValidationError = exports.UnparsableFileLocationError = exports.UnmatchedRegexError = exports.UnexpectedFileSize = exports.RecordDoesNotExist = exports.RecordAlreadyMigrated = exports.ProviderNotFound = exports.PDRParsingError = exports.MissingS3FileError = exports.MissingRequiredEnvVarError = exports.MissingRequiredEnvVar = exports.MissingRequiredArgument = exports.MismatchPdrCollection = exports.InvalidRegexError = exports.InvalidChecksum = exports.InvalidArgument = exports.HostNotFound = exports.GranuleFileWriteError = exports.GranuleNotPublished = exports.FTPError = exports.FileNotFound = exports.EcsStartTaskError = exports.DuplicateFile = exports.DeletePublishedGranule = exports.CumulusMessageError = exports.ConnectionTimeout = exports.ApiCollisionError = exports.MissingBucketMap = exports.CMRInternalError = exports.CMRMetaFileNotFound = exports.XmlMetaFileNotFound = exports.RemoteResourceError = exports.ResourcesLockedError = exports.IncompleteError = exports.NotNeededError = exports.WorkflowError = exports.isConditionalCheckException = exports.isWorkflowError = exports.isThrottlingException = exports.ThrottlingException = exports.createErrorType = void 0;
5
+ const isObject = require('lodash/isObject');
6
+ const pick = require('lodash/pick');
4
7
  /**
5
8
  * Creates a new error type with the given name and parent class. Sets up
6
9
  * boilerplate necessary to successfully subclass Error and preserve stack trace
@@ -122,4 +125,35 @@ exports.PostgresValidationError = PostgresValidationError;
122
125
  exports.PostgresUpdateFailed = (0, exports.createErrorType)('PostgresUpdateFailed');
123
126
  exports.IndexExistsError = (0, exports.createErrorType)('IndexExistsError');
124
127
  exports.UnmetRequirementsError = (0, exports.createErrorType)('UnmetRequirementsError');
128
+ /**
129
+ * Creates a JSON replacer function that removes circular references and
130
+ * ensures only an object's own properties (not inherited ones) are serialized.
131
+ *
132
+ * @returns A JSON replacer function
133
+ */
134
+ const replacerFactory = () => {
135
+ const seen = new WeakSet();
136
+ const replacer = (_key, value) => {
137
+ if (isObject(value) && value !== null) {
138
+ if (seen.has(value)) {
139
+ return undefined; // Remove circular reference
140
+ }
141
+ seen.add(value);
142
+ }
143
+ if (!Array.isArray(value) && isObject(value)) {
144
+ return pick(value, Object.getOwnPropertyNames(value));
145
+ }
146
+ return value;
147
+ };
148
+ return replacer;
149
+ };
150
+ /**
151
+ * Safely serializes an error-like object to JSON, removing circular references
152
+ * and including only own properties.
153
+ *
154
+ * @param err - The error or object to serialize
155
+ * @returns A JSON string representation of the object
156
+ */
157
+ const errorify = (err) => JSON.stringify(err, replacerFactory());
158
+ exports.errorify = errorify;
125
159
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/errors",
3
- "version": "21.0.0",
3
+ "version": "21.0.1",
4
4
  "description": "Provides error classes for Cumulus",
5
5
  "keywords": [
6
6
  "GIBS",
@@ -26,11 +26,18 @@
26
26
  },
27
27
  "scripts": {
28
28
  "clean": "git clean -d -x -e node_modules -f",
29
+ "test": "../../node_modules/.bin/ava",
30
+ "test:ci": "../../scripts/run_package_ci_unit.sh",
31
+ "test:coverage": "../../node_modules/.bin/nyc npm test",
29
32
  "prepare": "npm run tsc",
30
33
  "tsc": "../../node_modules/.bin/tsc",
31
- "tsc:listEmittedFiles": "../../node_modules/.bin/tsc --listEmittedFiles"
34
+ "tsc:listEmittedFiles": "../../node_modules/.bin/tsc --listEmittedFiles",
35
+ "coverage": "python ../../scripts/coverage_handler/coverage.py"
32
36
  },
33
37
  "author": "Cumulus Authors",
34
38
  "license": "Apache-2.0",
35
- "gitHead": "19bb3477969662a9e0b300f10f6df23b6c0654db"
39
+ "dependencies": {
40
+ "lodash": "~4.17.21"
41
+ },
42
+ "gitHead": "d721b7f47e28b3ebb8a09d83422f5371f5641fba"
36
43
  }