Skip to content

Commit 649adb8

Browse files
committed
fix: update onlyOn handling (it didn't exist before)
1 parent 2e26f2a commit 649adb8

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

packages/cli/src/constructs/check.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
FixedRetryStrategy,
1515
LinearRetryStrategy,
1616
NoRetriesRetryStrategy,
17+
RetryStrategy,
1718
SingleRetryRetryStrategy,
1819
} from './retry-strategy'
1920
import { AlertEscalation } from './alert-escalation-policy'
@@ -293,8 +294,9 @@ export abstract class Check extends Construct {
293294

294295
// eslint-disable-next-line require-await
295296
protected async validateRetryStrategyOnlyOn (diagnostics: Diagnostics): Promise<void> {
296-
if (this.retryStrategy?.onlyOn) {
297-
if (this.retryStrategy.onlyOn === 'NETWORK_ERROR') {
297+
if (this.retryStrategy) {
298+
const retryStrategy = this.retryStrategy as RetryStrategy
299+
if (retryStrategy.onlyOn === 'NETWORK_ERROR') {
298300
if (!this.supportsOnlyOnNetworkErrorRetryStrategy()) {
299301
diagnostics.add(new InvalidPropertyValueDiagnostic(
300302
'retryStrategy',
@@ -308,7 +310,7 @@ export abstract class Check extends Construct {
308310
diagnostics.add(new InvalidPropertyValueDiagnostic(
309311
'retryStrategy',
310312
new Error(
311-
`Unsupported value "${this.retryStrategy.onlyOn}" for "onlyOn".`,
313+
`Unsupported value "${retryStrategy.onlyOn}" for "onlyOn".`,
312314
),
313315
))
314316
}

packages/cli/src/constructs/retry-strategy-codegen.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ export function valueForRetryStrategy (genfile: GeneratedFile, strategy?: RetryS
4040
if (options.sameRegion !== undefined) {
4141
builder.boolean('sameRegion', options.sameRegion)
4242
}
43+
}
4344

45+
function buildOnlyOnOption (
46+
options: RetryStrategyOptions,
47+
builder: ObjectValueBuilder,
48+
): void {
4449
if (options.onlyOn !== undefined) {
4550
const onlyOn = Array.isArray(options.onlyOn) ? options.onlyOn : [options.onlyOn]
4651
if (onlyOn.length === 1) {
@@ -63,6 +68,7 @@ export function valueForRetryStrategy (genfile: GeneratedFile, strategy?: RetryS
6368
buildMaxRetriesOption(options, builder)
6469
buildMaxDurationSecondsOption(options, builder)
6570
buildSameRegionOption(options, builder)
71+
buildOnlyOnOption(options, builder)
6672
}
6773

6874
if (strategy === null || strategy === undefined) {
@@ -109,6 +115,7 @@ export function valueForRetryStrategy (genfile: GeneratedFile, strategy?: RetryS
109115
builder.object(builder => {
110116
buildBaseBackoffSecondsOption(strategy, builder)
111117
buildSameRegionOption(strategy, builder)
118+
buildOnlyOnOption(strategy, builder)
112119
})
113120
})
114121
})

packages/cli/src/constructs/retry-strategy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ export type FixedRetryStrategyOptions = RetryStrategyOptions
127127
/**
128128
* Configuration for single retry retry strategies.
129129
*/
130-
export interface SingleRetryRetryStrategy extends Pick<RetryStrategy, 'type' | 'baseBackoffSeconds' | 'sameRegion'> {
130+
export interface SingleRetryRetryStrategy extends Pick<RetryStrategy, 'type' | 'baseBackoffSeconds' | 'sameRegion' | 'onlyOn'> {
131131
type: 'SINGLE_RETRY'
132132
}
133133

134134
/**
135135
* Options for configuring single retry retry strategy behavior.
136136
*/
137-
export type SingleRetryRetryStrategyOptions = Pick<RetryStrategyOptions, 'baseBackoffSeconds' | 'sameRegion'>
137+
export type SingleRetryRetryStrategyOptions = Pick<RetryStrategyOptions, 'baseBackoffSeconds' | 'sameRegion' | 'onlyOn'>
138138

139139
/**
140140
* Configuration for no retry retry strategies.
@@ -230,11 +230,12 @@ export class RetryStrategyBuilder {
230230
* A single retry will be performed.
231231
*/
232232
static singleRetry (options?: SingleRetryRetryStrategyOptions): SingleRetryRetryStrategy {
233-
const { baseBackoffSeconds, sameRegion } = RetryStrategyBuilder.defaults(options)
233+
const { baseBackoffSeconds, sameRegion, onlyOn } = RetryStrategyBuilder.defaults(options)
234234
return {
235235
type: 'SINGLE_RETRY',
236236
baseBackoffSeconds,
237237
sameRegion,
238+
onlyOn,
238239
}
239240
}
240241

0 commit comments

Comments
 (0)