Skip to content

Commit 883cd6b

Browse files
committed
Refactor error types, make backwards compatible
1 parent 7d8150f commit 883cd6b

3 files changed

Lines changed: 33 additions & 47 deletions

File tree

packages/mrt-utilities/src/data-store/development.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,9 @@
44
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
55
*/
66

7-
export class DataStoreNotFoundError extends Error {
8-
constructor(message: string) {
9-
super(message);
10-
this.name = 'DataStoreNotFoundError';
11-
Object.setPrototypeOf(this, DataStoreNotFoundError.prototype);
12-
}
13-
}
7+
import {DataStoreNotFoundError} from './errors.js';
148

15-
export class DataStoreServiceError extends Error {
16-
constructor(message: string) {
17-
super(message);
18-
this.name = 'DataStoreServiceError';
19-
Object.setPrototypeOf(this, DataStoreServiceError.prototype);
20-
}
21-
}
22-
23-
export class DataStoreUnavailableError extends Error {
24-
constructor(message: string) {
25-
super(message);
26-
this.name = 'DataStoreUnavailableError';
27-
Object.setPrototypeOf(this, DataStoreUnavailableError.prototype);
28-
}
29-
}
9+
export {DataStoreNotFoundError, DataStoreServiceError, DataStoreUnavailableError} from './errors.js';
3010

3111
/**
3212
* Development-only pseudo data store backed by environment variables.
@@ -87,7 +67,6 @@ export class DataStore {
8767

8868
if (this.warnOnMissing && !this.warnedKeys.has(key)) {
8969
this.warnedKeys.add(key);
90-
// eslint-disable-next-line no-console
9170
console.warn(`Local data-store provider did not find '${key}'.`);
9271
}
9372

@@ -107,7 +86,6 @@ function readDefaultsFromEnv(): Record<string, Record<string, unknown>> {
10786
return parsed as Record<string, Record<string, unknown>>;
10887
}
10988
} catch (error) {
110-
// eslint-disable-next-line no-console
11189
console.warn('Failed to parse SFNEXT_DATA_STORE_DEFAULTS JSON.', error);
11290
}
11391

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025, Salesforce, Inc.
3+
* SPDX-License-Identifier: Apache-2
4+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
7+
export class DataStoreNotFoundError extends Error {
8+
constructor(message: string) {
9+
super(message);
10+
this.name = 'DataStoreNotFoundError';
11+
Object.setPrototypeOf(this, DataStoreNotFoundError.prototype);
12+
}
13+
}
14+
15+
export class DataStoreServiceError extends Error {
16+
constructor(message: string) {
17+
super(message);
18+
this.name = 'DataStoreServiceError';
19+
Object.setPrototypeOf(this, DataStoreServiceError.prototype);
20+
}
21+
}
22+
23+
export class DataStoreUnavailableError extends Error {
24+
constructor(message: string) {
25+
super(message);
26+
this.name = 'DataStoreUnavailableError';
27+
Object.setPrototypeOf(this, DataStoreUnavailableError.prototype);
28+
}
29+
}

packages/mrt-utilities/src/data-store/production.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,10 @@
77
import {DynamoDBClient} from '@aws-sdk/client-dynamodb';
88
import {DynamoDBDocumentClient, GetCommand, type GetCommandOutput} from '@aws-sdk/lib-dynamodb';
99

10+
import {DataStoreNotFoundError, DataStoreServiceError, DataStoreUnavailableError} from './errors.js';
1011
import {logMRTError} from '../utils/utils.js';
1112

12-
export class DataStoreNotFoundError extends Error {
13-
constructor(message: string) {
14-
super(message);
15-
this.name = 'DataStoreNotFoundError';
16-
Object.setPrototypeOf(this, DataStoreNotFoundError.prototype);
17-
}
18-
}
19-
20-
export class DataStoreServiceError extends Error {
21-
constructor(message: string) {
22-
super(message);
23-
this.name = 'DataStoreServiceError';
24-
Object.setPrototypeOf(this, DataStoreServiceError.prototype);
25-
}
26-
}
27-
28-
export class DataStoreUnavailableError extends Error {
29-
constructor(message: string) {
30-
super(message);
31-
this.name = 'DataStoreUnavailableError';
32-
Object.setPrototypeOf(this, DataStoreUnavailableError.prototype);
33-
}
34-
}
13+
export {DataStoreNotFoundError, DataStoreServiceError, DataStoreUnavailableError} from './errors.js';
3514

3615
/**
3716
* A class for reading entries from the data store.

0 commit comments

Comments
 (0)