Skip to content

Commit 83e644b

Browse files
committed
refactor: hardcode ScaleError message
We only construct this once in the production code - there's no need to have it be variable.
1 parent 022e40f commit 83e644b

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

lambdas/functions/control-plane/src/aws/runners.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ async function processFleetResult(
213213
if (failedCount > 0) {
214214
logger.warn('Create fleet failed, ScaleError will be thrown to trigger retry for ephemeral runners.');
215215
logger.debug('Create fleet failed.', { data: fleet.Errors });
216-
throw new ScaleError('Failed to create instance, create fleet failed.', failedCount);
216+
throw new ScaleError(failedCount);
217217
}
218218

219219
logger.warn('Create fleet failed, error not recognized as scaling error.', { data: fleet.Errors });

lambdas/functions/control-plane/src/lambda.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('Test scale up lambda wrapper.', () => {
110110
});
111111

112112
it('Scale should create a batch failure message', async () => {
113-
const error = new ScaleError('Scale should be rejected');
113+
const error = new ScaleError();
114114
const mock = vi.fn() as MockedFunction<typeof scaleUp>;
115115
mock.mockImplementation(() => {
116116
return Promise.reject(error);
@@ -242,7 +242,7 @@ describe('Test scale up lambda wrapper.', () => {
242242
const records = createMultipleRecords(2);
243243
const multiRecordEvent: SQSEvent = { Records: records };
244244

245-
const error = new ScaleError('Critical scaling error', 2);
245+
const error = new ScaleError(2);
246246
const mock = vi.fn(scaleUp);
247247
mock.mockImplementation(() => Promise.reject(error));
248248
vi.mocked(scaleUp).mockImplementation(mock);

lambdas/functions/control-plane/src/scale-runners/ScaleError.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import ScaleError from './ScaleError';
55
describe('ScaleError', () => {
66
describe('detailedMessage', () => {
77
it('should format message for single instance failure', () => {
8-
const error = new ScaleError('Failed to create fleet', 1);
8+
const error = new ScaleError(1);
99

10-
expect(error.detailedMessage).toBe('Failed to create fleet (Failed to create 1 instance)');
10+
expect(error.detailedMessage).toBe(
11+
'Failed to create instance, create fleet failed. (Failed to create 1 instance)',
12+
);
1113
});
1214

1315
it('should format message for multiple instance failures', () => {
14-
const error = new ScaleError('Failed to create fleet', 3);
16+
const error = new ScaleError(3);
1517

16-
expect(error.detailedMessage).toBe('Failed to create fleet (Failed to create 3 instances)');
18+
expect(error.detailedMessage).toBe(
19+
'Failed to create instance, create fleet failed. (Failed to create 3 instances)',
20+
);
1721
});
1822
});
1923

@@ -56,14 +60,14 @@ describe('ScaleError', () => {
5660
{ failedCount: -1, expected: [], description: 'negative failed instances' },
5761
{ failedCount: -10, expected: [], description: 'large negative failed instances' },
5862
])('should handle $description (failedCount=$failedCount)', ({ failedCount, expected }) => {
59-
const error = new ScaleError('Test error', failedCount);
63+
const error = new ScaleError(failedCount);
6064
const failures = error.toBatchItemFailures(mockMessages);
6165

6266
expect(failures).toEqual(expected);
6367
});
6468

6569
it('should handle empty message array', () => {
66-
const error = new ScaleError('Test error', 3);
70+
const error = new ScaleError(3);
6771
const failures = error.toBatchItemFailures([]);
6872

6973
expect(failures).toEqual([]);

lambdas/functions/control-plane/src/scale-runners/ScaleError.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import type { SQSBatchItemFailure } from 'aws-lambda';
22
import type { ActionRequestMessageSQS } from './scale-up';
33

44
class ScaleError extends Error {
5-
constructor(
6-
message: string,
7-
public readonly failedInstanceCount: number = 1,
8-
) {
9-
super(message);
5+
constructor(public readonly failedInstanceCount: number = 1) {
6+
super('Failed to create instance, create fleet failed.');
107
this.name = 'ScaleError';
118
}
129

0 commit comments

Comments
 (0)