Merge pull request #2782 from matthewbinshtok/binshtok/fix-validate-retry-config-error-msg

[grpc-js] Fix error messages in `serviceConfig` validation
This commit is contained in:
Michael Lumish 2024-06-27 09:48:15 -07:00 committed by GitHub
commit d83355ba1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 11 deletions

View File

@ -143,7 +143,7 @@ function validateRetryPolicy(obj: any): RetryPolicy {
!DURATION_REGEX.test(obj.initialBackoff)
) {
throw new Error(
'Invalid method config retry policy: initialBackoff must be a string consisting of a positive integer followed by s'
'Invalid method config retry policy: initialBackoff must be a string consisting of a positive integer or decimal followed by s'
);
}
if (
@ -152,7 +152,7 @@ function validateRetryPolicy(obj: any): RetryPolicy {
!DURATION_REGEX.test(obj.maxBackoff)
) {
throw new Error(
'Invalid method config retry policy: maxBackoff must be a string consisting of a positive integer followed by s'
'Invalid method config retry policy: maxBackoff must be a string consisting of a positive integer or decimal followed by s'
);
}
if (
@ -228,18 +228,18 @@ function validateHedgingPolicy(obj: any): HedgingPolicy {
if (typeof value === 'number') {
if (!Object.values(Status).includes(value)) {
throw new Error(
'Invlid method config hedging policy: nonFatalStatusCodes value not in status code range'
'Invalid method config hedging policy: nonFatalStatusCodes value not in status code range'
);
}
} else if (typeof value === 'string') {
if (!Object.values(Status).includes(value.toUpperCase())) {
throw new Error(
'Invlid method config hedging policy: nonFatalStatusCodes value not a status code name'
'Invalid method config hedging policy: nonFatalStatusCodes value not a status code name'
);
}
} else {
throw new Error(
'Invlid method config hedging policy: nonFatalStatusCodes value must be a string or number'
'Invalid method config hedging policy: nonFatalStatusCodes value must be a string or number'
);
}
}

View File

@ -101,19 +101,19 @@ const RETRY_TEST_CASES: TestCase[] = [
retryableStatusCodes: [14],
},
error:
/retry policy: initialBackoff must be a string consisting of a positive integer followed by s/,
/retry policy: initialBackoff must be a string consisting of a positive integer or decimal followed by s/,
},
{
description: 'a non-numeric initialBackoff',
config: { ...validRetryConfig, initialBackoff: 'abcs' },
error:
/retry policy: initialBackoff must be a string consisting of a positive integer followed by s/,
/retry policy: initialBackoff must be a string consisting of a positive integer or decimal followed by s/,
},
{
description: 'an initialBackoff without an s',
config: { ...validRetryConfig, initialBackoff: '123' },
error:
/retry policy: initialBackoff must be a string consisting of a positive integer followed by s/,
/retry policy: initialBackoff must be a string consisting of a positive integer or decimal followed by s/,
},
{
description: 'omitted maxBackoff',
@ -124,19 +124,19 @@ const RETRY_TEST_CASES: TestCase[] = [
retryableStatusCodes: [14],
},
error:
/retry policy: maxBackoff must be a string consisting of a positive integer followed by s/,
/retry policy: maxBackoff must be a string consisting of a positive integer or decimal followed by s/,
},
{
description: 'a non-numeric maxBackoff',
config: { ...validRetryConfig, maxBackoff: 'abcs' },
error:
/retry policy: maxBackoff must be a string consisting of a positive integer followed by s/,
/retry policy: maxBackoff must be a string consisting of a positive integer or decimal followed by s/,
},
{
description: 'an maxBackoff without an s',
config: { ...validRetryConfig, maxBackoff: '123' },
error:
/retry policy: maxBackoff must be a string consisting of a positive integer followed by s/,
/retry policy: maxBackoff must be a string consisting of a positive integer or decimal followed by s/,
},
{
description: 'omitted backoffMultiplier',