Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[grpc-js] Fix error messages in serviceConfig validation #2782

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/grpc-js/src/service-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 (
Expand Down Expand Up @@ -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'
);
}
}
Expand Down
12 changes: 6 additions & 6 deletions packages/grpc-js/test/test-retry-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down