-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Service Bus] Update to use latest core-amqp #6861
[Service Bus] Update to use latest core-amqp #6861
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test code needs to be updated to use code
instead of name
on the MessagingError when checking the error types.
See the changes made to the Event Hubs library in #6673 for reference.
@@ -92,7 +92,7 @@ export class BatchingReceiver extends MessageReceiver { | |||
const sessionError = context.session && context.session.error; | |||
let error = new MessagingError("An error occurred while receiving messages."); | |||
if (sessionError) { | |||
error = translate(sessionError); | |||
error = translate(sessionError) as MessagingError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting this way is useful if down the line we want to access properties on the error
object that we know are available only on the MessagingError
and not Error
.
But the case here is not so. We are adding this cast as a means to get away from the error TS gives that Error | MessagingError
is not assignable to MessagingError
.
The right approach here would be to type the error object during declaration as Error | MessagingError
.
Same applies to a few other cases in this PR.
cc @chradek for any additional thoughts here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All changes here are because we want to access code
and retryable
properties which appear on MessagingError
, so the reasoning seems fair.
The typing union would't work because the properties are not common to both (iirc while working on this locally).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's more correct for error
should be declared as Error | MessagingError
since that's what translate
will actually return.
Related to that somewhat, you could also instantiate the default MessagingError
later on if the error
doesn't exist to avoid creating an error that will likely not be used (I'm assuming the sessionError
will be available more often than not in the onSessionError
handler).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramya0820 Sorry, when I wrote my response your comment wasn't showing yet.
It doesn't look like either code
or retryable
are used in the onSessionError
handler, so there's no need to cast to MessagingError
inside the handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on local - in general declaring type as Error | MessagingError
wouldn't suffice, and we'll still need the as MessagingError
casting to work with TypeScript and current code.
Only changes to be updated seems to be the 2 declarations in this file - all other places we access code and/or retryable properties and require casting.
About setting default error instance later - agree, updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I had noticed that about these 2 instances - I meant in general all of the changes in this PR were for accessing the properties, so agree with updates to these 2 instances to be more focused on getting around TypeScript only~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, would be have been nicer if we didn't have to require the casting to access the properties if possible. Was there a reason why Error had to be a possible return value?
(Looks like the docs may need to be updated on the utility as well - I mean on the translate
utility in @azure/core-amqp
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a reason why Error had to be a possible return value?
Yes, the PR #6673 has all the relevant discussions around the changes to the MessagingError class as well as for the translate()
function.
Looks like the docs may need to be updated on the utility as well - I mean on the translate utility in @azure/core-amqp
They were updated as part of #6673 already to the below:
Translates the AQMP error received at the protocol layer or a SystemError into a MessagingError. All other errors are returned unaltered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.
About the docs, I was looking at the line below that
* @returns {MessagingError} MessagingError object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's a good catch. Please feel free to send a PR to update the return section of the docs in the master branch.
/azp run js - servicebus - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
The Please wait until the live/integration test run triggered from this PR to complete before merging this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a total of 9 live test failures. Please take a look and address them.
- 7 test failures are regarding unexpected error name. These were found in Event Hubs as well. The errors in these test cases are expected to be different in node vs browser. The test cases need to be updated appropriately. You can refer to the corresponding test cases in Event Hubs for reference.
- 2 are regarding the createQueue() operation.
5f7b75e
to
b10dfa7
Compare
/azp run js - servicebus - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run js - servicebus - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
* Pin core-amqp version to preview.1 * Update lock file * Fix merge conflicts * [Service Bus] Update to use core-amqp (#5324) * Use core-amqp in atom management client, comment tests that use token provider * [Service Bus] Update to use latest core-amqp (#6861) * [Service Bus] Update constructors to add overloads and use Azure Identity (#5436) * sync-versions: rhea-promise and @azure/core-amqp for service-bus * resolve merge conflicts appropriately * API Report File for "@Azure/service-bus" * Address feedback * SERVICEBUS_CONNECTION_STRING_BROWSER remove from karma.conf * update pnpm-lock file * update API Report File for "@Azure/service-bus" * remove rhea and rhea-promise dependencies * add "rhea-promise" back Co-authored-by: Ramya Rao <ramya.rao.a@outlook.com> Co-authored-by: ramya0820 <45977823+ramya0820@users.noreply.github.com>
For more context refer to #5127