Skip to content

Commit a5ba074

Browse files
authored
[core-amqp][service-bus] Prunes core-amqp public API and move ServiceBusError.reason to ServiceBusError.code (Azure#12499)
This change updates the `ServiceBusError.code` field to match what was the `ServiceBusError.reason` field. This allows us to remove the `MessagingErrorCodes` from the public interface, which we don't see as providing value above and beyond what the `ServiceBusCodes` provides.
1 parent 3d7ae46 commit a5ba074

File tree

18 files changed

+53
-273
lines changed

18 files changed

+53
-273
lines changed

sdk/core/core-amqp/CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Release History
22

3-
## 2.0.0 (2020-11-10)
3+
## 2.0.0 (2020-11-12)
44

55
- This release marks the general availability of the `@azure/core-amqp` version 2 package.
66

77
### Breaking changes
88

9-
- Continuing our work to clean the public API surface that we started in 2.0.0-beta.1, `DataTransformer` and `DefaultDataTransformer` are no longer exported.
10-
`dataTransformer` has been removed from `ConnectionContextBase` and `ConnectionContextBaseParameters`.
11-
This allows us to consider other forms of implementing serializers in the future.
9+
- Continuing our work to clean the public API surface that we started in 2.0.0-beta.1 we no longer export
10+
11+
- `DataTransformer` and `DefaultDataTransformer`.
12+
`dataTransformer` has been removed from `ConnectionContextBase` and `ConnectionContextBaseParameters`.
13+
This allows us to consider other forms of implementing serializers in the future.
14+
- `ConditionStatusMapper` and `MessagingErrorCodes` as these are only used internally by this package.
15+
1216
- Previously, `ConnectionConfig.validate()` overridden entityPath if `undefined` with `String(undefined) = "undefined"`. This has been updated to retain `undefined` in the validation.
1317
[PR 12321](https://github.com/Azure/azure-sdk-for-js/pull/12321)
1418

sdk/core/core-amqp/review/core-amqp.api.md

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -157,50 +157,6 @@ export enum ConditionErrorNameMapper {
157157
"system:error" = "SystemError"
158158
}
159159

160-
// @public
161-
export enum ConditionStatusMapper {
162-
// (undocumented)
163-
"amqp:link:message-size-exceeded" = 403,
164-
// (undocumented)
165-
"amqp:link:stolen" = 410,
166-
// (undocumented)
167-
"amqp:not-allowed" = 400,
168-
// (undocumented)
169-
"amqp:not-found" = 404,
170-
// (undocumented)
171-
"amqp:not-implemented" = 501,
172-
// (undocumented)
173-
"amqp:resource-limit-exceeded" = 403,
174-
// (undocumented)
175-
"amqp:unauthorized-access" = 401,
176-
// (undocumented)
177-
"com.microsoft:argument-error" = 400,
178-
// (undocumented)
179-
"com.microsoft:argument-out-of-range" = 400,
180-
// (undocumented)
181-
"com.microsoft:entity-already-exists" = 409,
182-
// (undocumented)
183-
"com.microsoft:entity-disabled" = 400,
184-
// (undocumented)
185-
"com.microsoft:message-lock-lost" = 410,
186-
// (undocumented)
187-
"com.microsoft:no-matching-subscription" = 500,
188-
// (undocumented)
189-
"com.microsoft:partition-not-owned" = 410,
190-
// (undocumented)
191-
"com.microsoft:publisher-revoked" = 401,
192-
// (undocumented)
193-
"com.microsoft:server-busy" = 503,
194-
// (undocumented)
195-
"com.microsoft:session-cannot-be-locked" = 410,
196-
// (undocumented)
197-
"com.microsoft:session-lock-lost" = 410,
198-
// (undocumented)
199-
"com.microsoft:store-lock-lost" = 410,
200-
// (undocumented)
201-
"com.microsoft:timeout" = 408
202-
}
203-
204160
// @public
205161
export interface ConnectionConfig {
206162
connectionString: string;
@@ -444,7 +400,7 @@ export const logger: import("@azure/logger").AzureLogger;
444400
export class MessagingError extends Error {
445401
constructor(message: string, originalError?: Error);
446402
address?: string;
447-
code?: MessagingErrorCodes | string;
403+
code?: string;
448404
errno?: number | string;
449405
info?: any;
450406
name: string;
@@ -453,9 +409,6 @@ export class MessagingError extends Error {
453409
syscall?: string;
454410
}
455411

456-
// @public
457-
export type MessagingErrorCodes = "AddressAlreadyInUseError" | "ArgumentError" | "ArgumentOutOfRangeError" | "ConnectionForcedError" | "ConnectionRedirectError" | "DecodeError" | "DetachForcedError" | "ErrantLinkError" | "FrameSizeTooSmallError" | "FramingError" | "HandleInUseError" | "IllegalStateError" | "InternalServerError" | "InvalidFieldError" | "InvalidOperationError" | "LinkRedirectError" | "MessageLockLostError" | "MessageNotFoundError" | "MessageTooLargeError" | "MessageWaitTimeout" | "MessagingEntityAlreadyExistsError" | "MessagingEntityDisabledError" | "MessagingEntityNotFoundError" | "NoMatchingSubscriptionError" | "NotImplementedError" | "OperationCancelledError" | "OperationTimeoutError" | "PartitionNotOwnedError" | "PreconditionFailedError" | "PublisherRevokedError" | "QuotaExceededError" | "ReceiverDisconnectedError" | "RelayNotFoundError" | "ResourceDeletedError" | "ResourceLockedError" | "SenderBusyError" | "ServerBusyError" | "ServiceCommunicationError" | "ServiceUnavailableError" | "SessionCannotBeLockedError" | "SessionLockLostError" | "SessionWindowViolationError" | "StoreLockLostError" | "SystemError" | "TransferLimitExceededError" | "UnattachedHandleError" | "UnauthorizedError";
458-
459412
// @public
460413
export interface NetworkSystemError {
461414
// (undocumented)

sdk/core/core-amqp/src/errors.ts

Lines changed: 3 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { isNode, isNumber, isString } from "../src/util/utils";
88
/**
99
* Maps the conditions to the numeric AMQP Response status codes.
1010
* @enum {ConditionStatusMapper}
11+
* @internal
12+
* @ignore
1113
*/
1214
export enum ConditionStatusMapper {
1315
"com.microsoft:timeout" = AmqpResponseStatusCode.RequestTimeout,
@@ -467,164 +469,6 @@ const systemErrorFieldsToCopy: (keyof Omit<NetworkSystemError, "name" | "message
467469
"syscall"
468470
];
469471

470-
/**
471-
* AMQP messaging error codes
472-
*
473-
* AddressAlreadyInUseError: the address is already in use.
474-
* ArgumentError: an incorrect argument was received.
475-
* ArgumentOutOfRangeError: an argument has a value that is out of the admissible range.
476-
* ConnectionForcedError: an operator intervened to close the connection for some reason.
477-
* ConnectionRedirectError: the container is no longer available on the current connection.
478-
* DecodeError: data could not be decoded.
479-
* DetachForcedError: an operator intervened to detach for some reason.
480-
* ErrantLinkError: input was received for a link that was detached with an error.
481-
* FrameSizeTooSmallError: the peer cannot send a frame because the smallest encoding of the performative with the currently valid values would be too large to fit within a frame of the agreed maximum frame size.
482-
* FramingError: a valid frame header cannot be formed from the incoming byte stream.
483-
* HandleInUseError: an attach was received using a handle that is already in use for an attached link a frame (other than attach) was received referencing a handle which is not
484-
* IllegalStateError: the peer sent a frame that is not permitted in the current state.
485-
* InternalServerError: an internal server error occurred. You may have found a bug?
486-
* InvalidFieldError: an invalid field was passed in a frame body, and the operation could not proceed.
487-
* InvalidOperationError: an operation is attempted but is not allowed.
488-
* LinkRedirectError: the address provided cannot be resolved to a terminus at the current container.
489-
* MessageLockLostError: the lock on the message is lost.
490-
* MessageNotFoundError: message is not found.
491-
* MessageTooLargeError: the message sent is too large: the maximum size is 256Kb.
492-
* MessageWaitTimeout: no new messages are received for the specified time.
493-
* MessagingEntityAlreadyExistsError: an attempt is made to create an entity that already exists.
494-
* MessagingEntityDisabledError: trying to access/connect to a disabled messaging entity.
495-
* MessagingEntityNotFoundError: the messaging entity does not exist.
496-
* NoMatchingSubscriptionError: a matching subscription is not found.
497-
* NotImplementedError: a feature is not implemented yet but the placeholder is present.
498-
* OperationCancelledError: server cancels the operation due to an internal issue.
499-
* OperationTimeoutError: the service fails to respond within a given timeframe.
500-
* PartitionNotOwnedError: an attempt is made to access a partition that is not owned by the requesting entity.
501-
* PreconditionFailedError: a condition that should have been met in order to execute an operation was not.
502-
* PublisherRevokedError: access to publisher has been revoked.
503-
* QuotaExceededError: The the Azure EventHub/ServiceBus quota has been exceeded.
504-
* ReceiverDisconnectedError: two or more instances connect to the same partition with different epoch values.
505-
* RelayNotFoundError: relay is not found.
506-
* ResourceDeletedError: a server entity the client is working with has been deleted.
507-
* ResourceLockedError: the client attempted to work with a server entity to which it has no access because another client is working with it.
508-
* SenderBusyError: the client sender does not have enough link credits to send the message.
509-
* ServerBusyError: the server is busy. Callers should wait a while and retry the operation.
510-
* ServiceCommunicationError: Error for signaling general communication errors related to messaging operations.
511-
* ServiceUnavailableError: the service is unavailable. The operation should be retried.
512-
* SessionCannotBeLockedError: the Azure ServiceBus session cannot be locked.
513-
* SessionLockLostError: the lock on the Azure ServiceBus session is lost.
514-
* SessionWindowViolationError: the peer violated incoming window for the session.
515-
* StoreLockLostError: the store lock is lost.
516-
* SystemError: a low level system error is thrown by node.js. See {@link https://nodejs.org/api/errors.html#errors_class_systemerror}.
517-
* TransferLimitExceededError: the peer sent more message transfers than currently allowed on the link.
518-
* UnattachedHandleError: currently in use of an attached link.
519-
* UnauthorizedError: the connection parameters are wrong and the server refused the connection.
520-
*/
521-
export type MessagingErrorCodes =
522-
// Error is thrown when the address is already in use.
523-
| "AddressAlreadyInUseError"
524-
// Error is thrown when an incorrect argument was received.
525-
| "ArgumentError"
526-
// Error is thrown when an argument has a value that is out of the admissible range.
527-
| "ArgumentOutOfRangeError"
528-
// Error is thrown when an operator intervened to close the connection for some reason.
529-
| "ConnectionForcedError"
530-
// Error is thrown when the container is no longer available on the current connection.
531-
| "ConnectionRedirectError"
532-
// Error is thrown when data could not be decoded.
533-
| "DecodeError"
534-
// Error is thrown when an operator intervened to detach for some reason.
535-
| "DetachForcedError"
536-
// Error is thrown when input was received for a link that was detached with an error.
537-
| "ErrantLinkError"
538-
// Error is thrown when the peer cannot send a frame because the smallest encoding of
539-
// the performative with the currently valid values would be too large to fit within
540-
// a frame of the agreed maximum frame size.
541-
| "FrameSizeTooSmallError"
542-
// Error is thrown when a valid frame header cannot be formed from the incoming byte stream.
543-
| "FramingError"
544-
// Error is thrown when an attach was received using a handle that is already in use for an attached link.
545-
| "HandleInUseError"
546-
// Error is thrown when the peer sent a frame that is not permitted in the current state.
547-
| "IllegalStateError"
548-
// Error is thrown when an internal server error occurred. You may have found a bug?
549-
| "InternalServerError"
550-
// Error is thrown when an invalid field was passed in a frame body, and the operation could not proceed.
551-
| "InvalidFieldError"
552-
// Error is thrown when an operation is attempted but is not allowed.
553-
| "InvalidOperationError"
554-
// Error is thrown when the address provided cannot be resolved to a terminus at the current container.
555-
| "LinkRedirectError"
556-
// Error is thrown when the lock on the message is lost.
557-
| "MessageLockLostError"
558-
// Error is thrown when message is not found.
559-
| "MessageNotFoundError"
560-
// Error is thrown when the message sent is too large: the maximum size is 256Kb.
561-
| "MessageTooLargeError"
562-
// Error is thrown when no new messages are received for the specified time.
563-
| "MessageWaitTimeout"
564-
// Error is thrown when an attempt is made to create an entity that already exists.
565-
| "MessagingEntityAlreadyExistsError"
566-
// Error is thrown when trying to access/connect to a disabled messaging entity.
567-
| "MessagingEntityDisabledError"
568-
// the messaging entity does not exist.
569-
| "MessagingEntityNotFoundError"
570-
// Error is thrown when a matching subscription is not found.
571-
| "NoMatchingSubscriptionError"
572-
// Error is thrown when a feature is not implemented yet but the placeholder is present.
573-
| "NotImplementedError"
574-
// Error is thrown when server cancels the operation due to an internal issue.
575-
| "OperationCancelledError"
576-
// the service fails to respond within a given timeframe.
577-
| "OperationTimeoutError"
578-
// Error is thrown when an attempt is made to access a partition that is not owned by the
579-
// requesting entity.
580-
| "PartitionNotOwnedError"
581-
// Error is thrown when a condition that should have been met in order to execute an operation was not.
582-
| "PreconditionFailedError"
583-
// Error is thrown when access to publisher has been revoked.
584-
| "PublisherRevokedError"
585-
// Error is thrown the the Azure EventHub/ServiceBus quota has been exceeded.
586-
// Quotas are reset periodically, this operation will have to wait until then.
587-
// The messaging entity has reached its maximum allowable size.
588-
// This can happen if the maximum number of receivers (which is 5) has already
589-
// been opened on a per-consumer group level.
590-
| "QuotaExceededError"
591-
// Error is thrown when two or more instances connect to the same partition
592-
// with different epoch values.
593-
| "ReceiverDisconnectedError"
594-
// Error is thrown when relay is not found.
595-
| "RelayNotFoundError"
596-
// Error is thrown when a server entity the client is working with has been deleted.
597-
| "ResourceDeletedError"
598-
// Error is thrown when the client attempted to work with a server entity to which it
599-
// has no access because another client is working with it.
600-
| "ResourceLockedError"
601-
// Error is thrown when the client sender does not have enough link credits to send the message.
602-
| "SenderBusyError"
603-
// Error is thrown when the server is busy. Callers should wait a while and retry the operation.
604-
| "ServerBusyError"
605-
// Error for signaling general communication errors related to messaging operations.
606-
| "ServiceCommunicationError"
607-
// Error is thrown when the service is unavailable. The operation should be retried.
608-
| "ServiceUnavailableError"
609-
// Error is thrown when the Azure ServiceBus session cannot be locked.
610-
| "SessionCannotBeLockedError"
611-
// Error is thrown when the lock on the Azure ServiceBus session is lost.
612-
| "SessionLockLostError"
613-
// Error is thrown when the peer violated incoming window for the session.
614-
| "SessionWindowViolationError"
615-
// Error is thrown when the store lock is lost.
616-
| "StoreLockLostError"
617-
// Error is thrown when a low level system error is thrown by node.js.
618-
// {@link https://nodejs.org/api/errors.html#errors_class_systemerror}
619-
| "SystemError"
620-
// Error is thrown when the peer sent more message transfers than currently allowed on the link.
621-
| "TransferLimitExceededError"
622-
// Error is thrown when a frame (other than attach) was received referencing a handle which is not
623-
// currently in use of an attached link.
624-
| "UnattachedHandleError"
625-
// Error is thrown when the connection parameters are wrong and the server refused the connection.
626-
| "UnauthorizedError";
627-
628472
/**
629473
* Determines if an error is a MessagingError.
630474
*
@@ -648,7 +492,7 @@ export class MessagingError extends Error {
648492
/**
649493
* A string label that identifies the error.
650494
*/
651-
code?: MessagingErrorCodes | string;
495+
code?: string;
652496
/**
653497
* System-provided error number.
654498
* Only present if the `MessagingError` was instantiated with a Node.js `SystemError`.

sdk/core/core-amqp/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ export {
2020
} from "./ConnectionContextBase";
2121
export {
2222
MessagingError,
23-
MessagingErrorCodes,
2423
isMessagingError,
2524
ErrorNameConditionMapper,
26-
ConditionStatusMapper,
2725
ConditionErrorNameMapper,
2826
translate,
2927
retryableErrors,

sdk/servicebus/service-bus/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 7.0.0 (Unreleased)
44

5+
### Breaking changes
6+
7+
- The `ServiceBusError.reason` field has been renamed `ServiceBusError.code`.
8+
The `code` field can be used to differentiate what caused a `ServiceBusError` to be thrown.
59
- Numbers passed in `applicationProperties` of the correlation rule filter and `sqlParameters` under SQLRuleFilter will now be serialized as "double"(used to be "int") while sending the requests. The "double" and "int" values in the response will now be deserialized as "number"("double" wasn't supported before).
610
[PR 12349](https://github.com/Azure/azure-sdk-for-js/pull/12349)
711

sdk/servicebus/service-bus/review/service-bus.api.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Delivery } from 'rhea-promise';
1010
import { HttpResponse } from '@azure/core-http';
1111
import Long from 'long';
1212
import { MessagingError } from '@azure/core-amqp';
13-
import { MessagingErrorCodes } from '@azure/core-amqp';
1413
import { OperationOptions } from '@azure/core-http';
1514
import { PagedAsyncIterableIterator } from '@azure/core-paging';
1615
import { PageSettings } from '@azure/core-paging';
@@ -145,8 +144,6 @@ export interface MessageHandlers {
145144

146145
export { MessagingError }
147146

148-
export { MessagingErrorCodes }
149-
150147
// @public
151148
export interface NamespaceProperties {
152149
createdAt: Date;
@@ -305,11 +302,11 @@ export interface ServiceBusConnectionStringProperties {
305302
// @public
306303
export class ServiceBusError extends MessagingError {
307304
constructor(messagingError: MessagingError);
308-
reason: ServiceBusErrorReason;
309-
}
305+
code: ServiceBusErrorCode;
306+
}
310307

311308
// @public
312-
export type ServiceBusErrorReason =
309+
export type ServiceBusErrorCode =
313310
/**
314311
* The exception was the result of a general error within the client library.
315312
*/

sdk/servicebus/service-bus/samples/javascript/advanced/sessionRoundRobin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function receiveFromNextSession(serviceBusClient) {
8383
} catch (err) {
8484
if (
8585
isServiceBusError(err) &&
86-
(err.reason === "SessionCannotBeLocked" || err.reason === "ServiceTimeout")
86+
(err.code === "SessionCannotBeLocked" || err.code === "ServiceTimeout")
8787
) {
8888
console.log(`INFO: no available sessions, sleeping for ${delayOnErrorMs}`);
8989
} else {

sdk/servicebus/service-bus/samples/javascript/receiveMessagesStreaming.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ async function main() {
4747

4848
// the `subscribe() call will not stop trying to receive messages without explicit intervention from you.
4949
if (isServiceBusError(args.error)) {
50-
switch (args.error.reason) {
50+
switch (args.error.code) {
5151
case "MessagingEntityDisabled":
5252
case "MessagingEntityNotFound":
5353
case "Unauthorized":
5454
// It's possible you have a temporary infrastructure change (for instance, the entity being
5555
// temporarily disabled). The handler will continue to retry if `close()` is not called on the subscription - it is completely up to you
5656
// what is considered fatal for your program.
5757
console.log(
58-
`An unrecoverable error occurred. Stopping processing. ${args.error.reason}`,
58+
`An unrecoverable error occurred. Stopping processing. ${args.error.code}`,
5959
args.error
6060
);
6161
await subscription.close();

sdk/servicebus/service-bus/samples/typescript/src/advanced/sessionRoundRobin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function receiveFromNextSession(serviceBusClient: ServiceBusClient): Promi
8989
} catch (err) {
9090
if (
9191
isServiceBusError(err) &&
92-
(err.reason === "SessionCannotBeLocked" || err.reason === "ServiceTimeout")
92+
(err.code === "SessionCannotBeLocked" || err.code === "ServiceTimeout")
9393
) {
9494
console.log(`INFO: no available sessions, sleeping for ${delayOnErrorMs}`);
9595
} else {

sdk/servicebus/service-bus/samples/typescript/src/receiveMessagesStreaming.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ export async function main() {
5555

5656
// the `subscribe() call will not stop trying to receive messages without explicit intervention from you.
5757
if (isServiceBusError(args.error)) {
58-
switch (args.error.reason) {
58+
switch (args.error.code) {
5959
case "MessagingEntityDisabled":
6060
case "MessagingEntityNotFound":
6161
case "Unauthorized":
6262
// It's possible you have a temporary infrastructure change (for instance, the entity being
6363
// temporarily disabled). The handler will continue to retry if `close()` is not called on the subscription - it is completely up to you
6464
// what is considered fatal for your program.
6565
console.log(
66-
`An unrecoverable error occurred. Stopping processing. ${args.error.reason}`,
66+
`An unrecoverable error occurred. Stopping processing. ${args.error.code}`,
6767
args.error
6868
);
6969
await subscription.close();

0 commit comments

Comments
 (0)