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

.NET LRO error handling is inconsistent with guidelines, each other #41961

Open
heaths opened this issue Feb 14, 2024 · 0 comments
Open

.NET LRO error handling is inconsistent with guidelines, each other #41961

heaths opened this issue Feb 14, 2024 · 0 comments
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library. design-discussion An area of design currently under discussion and open to team and community feedback.
Milestone

Comments

@heaths
Copy link
Member

heaths commented Feb 14, 2024

While fixing(?) issue #41855 where we weren't throwing from an LRO for a failed status because the status monitor endpoint didn't return 200, I found that a lot of our hand-authored operations, our generation 1 (track 2) generated operations, and our generation 2 generated operations all seem to work a little differently and they don't seem to always follow our guidelines, which currently state:

✅ DO throw from methods on Operation subclasses in the following scenarios.

  • If an underlying service operation call from UpdateStatus, WaitForCompletion, or WaitForCompletionAsync throws, re-throw RequestFailedException or its subtype.
  • If the operation completes with a non-success result, throw RequestFailedException or its subtype from UpdateStatus, WaitForCompletion, or WaitForCompletionAsync.
    • Include any relevant error state information in the exception details.

We have a mix of some operations that only throw from the Value property - specifically the get_Value accessor - and some that throw but don't include the response or the HTTP status code, though the latter is a bit confusing because it should be 200 OK according to the REST API guidelines.

Examples of some differences:

  • public override KeyVaultCertificateWithPolicy Value
    {
    #pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
    get
    {
    if (Properties is null)
    {
    throw new InvalidOperationException("The operation was deleted so no value is available.");
    }
    if (Properties.Status == CancelledStatus)
    {
    throw new OperationCanceledException("The operation was canceled so no value is available.");
    }
    if (Properties.Error != null)
    {
    throw new InvalidOperationException($"The certificate operation failed: {Properties.Error.Message}");
    }
    return OperationHelpers.GetValue(ref _value);
    }
    #pragma warning restore CA1065 // Do not raise exceptions in unexpected locations
    }
    : this was discussed in depth with architects and approved; at the time, we didn't want UpdateStatus throwing.
  • async ValueTask<OperationState<T>> IOperation<T>.UpdateStateAsync(bool async, CancellationToken cancellationToken)
    {
    var state = await _nextLinkOperation.UpdateStateAsync(async, cancellationToken).ConfigureAwait(false);
    if (state.HasSucceeded)
    {
    return OperationState<T>.Success(state.RawResponse, _resultSelector(state.RawResponse));
    }
    if (state.HasCompleted)
    {
    return OperationState<T>.Failure(state.RawResponse, state.OperationFailedException);
    }
    return OperationState<T>.Pending(state.RawResponse);
    }
    : doesn't throw if the status operation indicates failure. Maybe higher up the stack?

I came across what seemed another 1 or 2 patterns, but having trouble remembering which they were / find them again.

@heaths heaths added Client This issue points to a problem in the data-plane of the library. design-discussion An area of design currently under discussion and open to team and community feedback. labels Feb 14, 2024
@annelo-msft annelo-msft added this to the Backlog milestone May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library. design-discussion An area of design currently under discussion and open to team and community feedback.
Projects
None yet
Development

No branches or pull requests

2 participants