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

Added stack trace to CosmosException, ResponseMessage.ErrorMessage includes full exception info. #1213

Merged
merged 27 commits into from
Feb 28, 2020

Conversation

j82w
Copy link
Contributor

@j82w j82w commented Feb 14, 2020

Pull Request Template

Description

The current CosmosException looses the original call stack. This causes a lot of confusion when user are inspecting the exception. This PR preserves the original call stack when it is passed in. Else it uses the default call stack logic.

  1. Removed error since it is not being used any more.
  2. Added stack trace to CosmosException. This allows the original stack trace to be shown even if the exception is stored and later thrown higher in the call stack.
  3. ResponseMessage.ErrorMessage now always includes the full CosmosException info. This means if the user only logs the ErrorMessage all the information needed to debug it including the stack trace will be included.
  4. ResponseMessage for error scenarios will always convert the payload to ErrorMessage. This fixes some scenarios where the user would have to parse the stream to get the error message.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Jake Willey added 4 commits February 11, 2020 06:23
… string. Returning only the error message makes it not possible to debug.

CosmosException now stores the stack trace. This fixes the issues where the error information is stored and later thrown causing the exception to show the incorrect error location.

Created new CosmosExceptionFactory. This helps produce a CosmosException from the various types.
@j82w j82w added bug Something isn't working feature-request New feature or request Diagnostics Issues around diagnostics and troubleshooting labels Feb 14, 2020
bchong95
bchong95 previously approved these changes Feb 14, 2020
Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Matias - let's chat about this change offline first. I have some concerns around the general approach - so would like to get consensus there before reviewing the actual changes.

My concerns:
Creating a StackTrace is an expensive operation - while I understand your desire to prevent users from shooting themselves in the foot and not exposing proper stack traces - I don't think it is reasonable to enforce a stack trace even in scenarios where exceptions are effectively used to express "normal" behavior - like 404 or 409 - even 429. In all these cases exceptions can occur rather frequently - and the stacktrace doesn't provide much value.
--> https://github.com/dotnet/coreclr/blob/master/src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs and dotnet/coreclr#27004 with some additional information why the implementation of the StackTrace property might be insufficient or at least inconsistent with the base class's implementation

I also have concerns around pulling the stacktrace into the message - there are customers treating callstacks as something worth protecting (I have never fully understood why - but could see at least reasons to not "leak" callstacks across the wire for example). So changing the semantics of the CosmosException to include callstacks in the message is a problem.

Bottom-line: I would refrain from overloading semantics of Exceptions in .Net in the CosmosException. Instead we should add guidance in best practices as well as our own logging/diagnostics-integration on how to ensure proper callstacks are logged along with exceptions.

ealsur
ealsur previously approved these changes Feb 27, 2020
Copy link
Member

@kirankumarkolli kirankumarkolli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@j82w j82w dismissed stale reviews from kirankumarkolli and ealsur via cad13c7 February 28, 2020 13:52

internal static class Extensions
{
private static readonly char[] NewLineCharacters = new[] { '\r', '\n' };

internal static bool IsSuccess(this HttpStatusCode httpStatusCode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goodie

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wonder if this will cause any issue when integrated internally, unless noone else created such an extension with that name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't since it's in the SDK namespace.

@j82w j82w merged commit 1a999ff into master Feb 28, 2020
@j82w j82w deleted the users/jawilley/diagnostics/exception branch February 28, 2020 14:53
@Azure Azure deleted a comment Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Diagnostics Issues around diagnostics and troubleshooting feature-request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants