Skip to content

Commit 7a1302d

Browse files
committed
style: minor tweaks to ScaleError
Some small tweaks to the style of `ScaleError`, while we're working on it. `message` doesn't need to be a public property. `Error` already has it. Likewise with `stack` - we can use the parent's implementation. Instead of `getDetailedMessage` we can have a property getter which is very slightly nicer to read at callsites (`e.detailedMessage` vs. `e.getDetailedMessage()`).
1 parent 8a94963 commit 7a1302d

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ export async function scaleUpHandler(event: SQSEvent, context: Context): Promise
6767
itemIdentifier: sqsMessages[i].messageId,
6868
});
6969
}
70-
logger.warn(
71-
`ScaleError detected, ${e.failedInstanceCount} could not be created. A retry will be attempted via SQS.`,
72-
{ error: e },
73-
);
70+
logger.warn(`${e.detailedMessage} A retry will be attempted via SQS.`, { error: e });
7471
} else {
7572
logger.error(`Error processing batch (size: ${sqsMessages.length}): ${(e as Error).message}, ignoring batch`, {
7673
error: e,
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
class ScaleError extends Error {
22
constructor(
3-
public message: string,
4-
public failedInstanceCount: number = 1,
3+
message: string,
4+
public readonly failedInstanceCount: number = 1,
55
) {
66
super(message);
77
this.name = 'ScaleError';
8-
this.stack = new Error().stack;
98
}
109

1110
/**
1211
* Gets a formatted error message including the failed instance count
1312
*/
14-
public getDetailedMessage(): string {
13+
public get detailedMessage(): string {
1514
return `${this.message} (Failed to create ${this.failedInstanceCount} instance${this.failedInstanceCount !== 1 ? 's' : ''})`;
1615
}
1716
}
1817

19-
export default ScaleError;
18+
export default ScaleError;

0 commit comments

Comments
 (0)