Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

MessageReceiver.CompleteAsync with empty list throws ArgumentNullException #579

Closed
WhiteRabbit68 opened this issue Oct 3, 2018 · 3 comments

Comments

@WhiteRabbit68
Copy link

Actual Behavior

  1. CompleteAsync(new List<string>())
  2. throws ArgumentException with "Value cannot be null" ParamName=lockTokens

This is misleading because the parameter is NOT null. Why is it an error to supply an empty list? Just return without doing anything.

Expected Behavior

  1. CompleteAsync(new List<string>())
  2. No exception thrown

Versions

  • OS platform and version: Windows
  • .NET Version: Standard 2.0
  • NuGet package version: 3.1.0
@SeanFeldman
Copy link
Collaborator

@WhiteRabbit68 while I don't disagree, it could go the other way - why don't you avoid unnecessary method invocation if there are no messages to complete? Worse if it's on the hot path.

Or would you prefer to see an exception with a different message that is more meaningful?

@WhiteRabbit68
Copy link
Author

Sure, but avoiding unnecessary calls should be the responsibility of the client:
if (tokensToComplete.Any())
await receiver.CompleteAsync(tokensToComplete);

It seems strange that an API should throw exceptions just because it thinks it was called in vain, but I would rather have ArgumentException("Value cannot be empty list") that forces the check above if so.

In any case, erroneous error messages are very frustrating, just spent some time wondering how the list of tokens could be null.

SeanFeldman added a commit to SeanFeldman/azure-service-bus-dotnet that referenced this issue Oct 3, 2018
@SeanFeldman
Copy link
Collaborator

The exception message is indeed incorrect. Fixing that.

nemakam pushed a commit that referenced this issue Oct 4, 2018
Fixes #579
For an empty list do not throw argument null exception
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants