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

[BUG] Equality failures due to implicit cast on RequestFailedException.ErrorCode #44213

Closed
Arithmomaniac opened this issue May 23, 2024 · 4 comments · Fixed by #45881
Closed
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)

Comments

@Arithmomaniac
Copy link
Contributor

Arithmomaniac commented May 23, 2024

Library name and version

Azure.Storage.Blobs 12.19.1.0

Describe the bug

In several places in the SDK, comparing RequestFailedException.ErrorCode to a strongly typed *ErrorCode type (e.g. BlobErrorCode) can throw an exception.

This is because:

  • RequestFailedException.ErrorCode is nullable
  • strings can be implicitly converted in == comparisons to *ErrorCode 
  • The constructor of *ErrorCode throws if a null is received

This goes against the guideline of

Predefined C# implicit conversions always succeed and never throw an exception. User-defined implicit conversions should behave in that way as well.

Expected behavior

No exception is thrown; in the Reproduction Steps case below, isContainerError is false if inspected.

Actual behavior

An ArgumentNullException is thrown.

Reproduction Steps

try
{
    throw new RequestFailedException(status: 404, message: "Some error.", errorCode: null, innerException: null);
}
catch (RequestFailedException ex)
{
    var isContainerError = ex.ErrorCode == BlobErrorCode.ContainerNotFound;
}

Environment

No response

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files) labels May 23, 2024
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

@Arithmomaniac
Copy link
Contributor Author

Thanks!
What about the non storage APIs? Should I open separate bugs?

@nickliu-msft
Copy link
Member

Hi @Arithmomaniac for non-storage APIs, yes please open another GitHub issue without the "Storage" tag and the appropriate team will assist you

@Arithmomaniac
Copy link
Contributor Author

Arithmomaniac commented Sep 16, 2024

@nickliu-msft Thanks. I kicked the issue up to the AutoRest repo, which I should have done originally (but thanks for providing the recommended solution 😉)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants