@@ -11,6 +11,7 @@ import { setTimeout } from 'node:timers/promises'
1111import stringHelpers from '@adonisjs/core/helpers/string'
1212import { BaseCheck , Result } from '@adonisjs/core/health'
1313import type { HealthCheckResult } from '@adonisjs/core/types/health'
14+ import * as errors from '../errors.js'
1415
1516import type { Connection } from '../types.js'
1617
@@ -48,12 +49,12 @@ export class RedisMemoryUsageCheck extends BaseCheck {
4849 /**
4950 * Memory consumption threshold after which a warning will be created
5051 */
51- #warnThreshold: number = stringHelpers . bytes . parse ( '100 mb' )
52+ #warnThreshold: number = stringHelpers . bytes . parse ( '100 mb' ) !
5253
5354 /**
5455 * Memory consumption threshold after which an error will be created
5556 */
56- #failThreshold: number = stringHelpers . bytes . parse ( '120 mb' )
57+ #failThreshold: number = stringHelpers . bytes . parse ( '120 mb' ) !
5758
5859 /**
5960 * Health check public name
@@ -142,7 +143,13 @@ export class RedisMemoryUsageCheck extends BaseCheck {
142143 * ```
143144 */
144145 warnWhenExceeds ( value : string | number ) {
145- this . #warnThreshold = stringHelpers . bytes . parse ( value )
146+ const bytes = stringHelpers . bytes . parse ( value )
147+
148+ if ( bytes === null ) {
149+ throw new errors . E_INVALID_BYTES_VALUE ( [ value ] )
150+ }
151+
152+ this . #warnThreshold = bytes
146153 return this
147154 }
148155
@@ -158,7 +165,13 @@ export class RedisMemoryUsageCheck extends BaseCheck {
158165 * ```
159166 */
160167 failWhenExceeds ( value : string | number ) {
161- this . #failThreshold = stringHelpers . bytes . parse ( value )
168+ const bytes = stringHelpers . bytes . parse ( value )
169+
170+ if ( bytes === null ) {
171+ throw new errors . E_INVALID_BYTES_VALUE ( [ value ] )
172+ }
173+
174+ this . #failThreshold = bytes
162175 return this
163176 }
164177
0 commit comments