Skip to content

Conversation

@jimson-msft
Copy link
Contributor

No description provided.

@jimson-msft jimson-msft requested a review from a team as a code owner October 13, 2021 03:07

private:
int32_t _code;
//error_category _category;
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 13, 2021

Choose a reason for hiding this comment

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

error_category

IIRC, this should be a reference. Commonly, a reference to a static instance. See the constructor here: https://en.cppreference.com/w/cpp/error/error_code/error_code

and cpprest's category here:
https://github.com/microsoft/cpprestsdk/blob/master/Release/src/utilities/asyncrt_utils.cpp

#Resolved

Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 13, 2021

Choose a reason for hiding this comment

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

Now that we have a better understanding of this - I believe that all we need is our own error_category instances and not a new error_code class.

We should reuse the std::error_code class and provide our own error_category instance where relevant (i.e.,, when we store a DO/boost/libcurl error within).

We can have our own errc enum and still reuse std::error_code.

Let me know if you want to discuss this over a call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm agreed, rather than construct std::error_code with that extra param, what do you think of iter 15 where we use our own error_code class to supply the do_category via overloading category()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks. Been thinking some more about this -
DU actually adds their own 'facility' bits to the error code to identify that the error came from DO.

So as a c++ library author, we should not worry about how our callers identify the source of errors in their telemetry. Each caller might want a different method.

Considering that, and the fact that we are trying to follow c++ standards, I think we should use std::error_code with our own error_category instances (more than one if needed; for now keep what we have).

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can leave the insertion of DO facility bits into the error codes as-is for now. Just remove the custom error_code class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good to me

#endif
#define DO_OK error_code(0)

#define DO_SUCCEEDED(code) (((int32_t)(code.value())) < 0)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 13, 2021

Choose a reason for hiding this comment

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

((int32_t)(code.value())) < 0

Since we expect only error_code type here, we should use its operator bool instead. At which point, I question the utility of these two macros. #Resolved

Copy link
Collaborator

Choose a reason for hiding this comment

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

Read this comment after my other one in do_errors.h about using std::error_code.

#endif

//TODO(jimson) Looks like these conversions are causing test issues with tests
//TODO(jimson): Do we really need these after switching to error code class? The error_category should help us differentiate what type of error it is
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 13, 2021

Choose a reason for hiding this comment

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

need

Agree we don't need these anymore. #Resolved

Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 13, 2021

Choose a reason for hiding this comment

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

Actually, wait, we need to think about this because DU client can only report an integer error code so the error_category information gets lost there.

Copy link
Contributor Author

@jimson-msft jimson-msft Oct 14, 2021

Choose a reason for hiding this comment

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

Yeah that's a good point - so I'm not sure if using only the error_category is sufficient - unless we ask them to perform the bit operations to add our facility code based on the error category in returned error_code

Can't we expose error code with the facility bits already added to the internal value? Would this make the error category redundant if the error code itself contains the 'category' via the facility bits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's still apply the facility code where needed for DU purposes, and make use of error_category

@shishirb-MSFT
Copy link
Collaborator

shishirb-MSFT commented Oct 13, 2021

int32_t error_code() const;

IMO this is redundant since caller can get it from std::error_code. We should remove this and rename get_error_code() to error_code().


In reply to: 942778026


In reply to: 942778026


In reply to: 942778026


In reply to: 942778026


In reply to: 942778026


In reply to: 942778026


In reply to: 942778026


Refers to: sdk-cpp/include/do_errors.h:84 in efea6d9. [](commit_id = efea6d9, deletion_comment = False)

shishirb-MSFT
shishirb-MSFT previously approved these changes Oct 13, 2021
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT left a comment

Choose a reason for hiding this comment

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

:shipit:

@jimson-msft jimson-msft reopened this Oct 14, 2021
@jimson-msft
Copy link
Contributor Author

jimson-msft commented Oct 14, 2021

So weird, there's some issues with github/CF - replying to a comment closed the PR. I'll look into submitting a ticket to CF team


In reply to: 943756987


In reply to: 943756987

@jimson-msft jimson-msft changed the title Custom DO Error Class Use std::error_code with custom error category Oct 18, 2021
@jimson-msft
Copy link
Contributor Author

There are some failing tests with these changes, looking into fixing now

@shishirb-MSFT shishirb-MSFT dismissed their stale review October 18, 2021 20:01

revoking review

shishirb-MSFT
shishirb-MSFT previously approved these changes Oct 18, 2021
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT left a comment

Choose a reason for hiding this comment

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

:shipit:

@jimson-msft
Copy link
Contributor Author

There are some failing tests with these changes, looking into fixing now

Resolved


std::error_code make_error_code(std::errc e)
{
return std::error_code(DO_ERROR_FROM_STD_ERROR(e), do_category());
Copy link
Collaborator

Choose a reason for hiding this comment

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

DO_ERROR_FROM_STD_ERROR

Need to fix tests to avoid doing this but it's okay for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll sign off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I'm not sure I follow - I think we do need to do this in order to make use of the same error code macros/convention. the std::errc enum are a set of positive integer values, and so need to call DO_ERROR_FROM_STD_ERROR to make them hresult-like.

@shishirb-MSFT shishirb-MSFT dismissed their stale review October 18, 2021 23:18

revoking review

Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT left a comment

Choose a reason for hiding this comment

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

:shipit:

@jimson-msft jimson-msft merged commit 5556b6d into develop Oct 19, 2021
@jimson-msft jimson-msft deleted the user/jimson/error_class branch October 19, 2021 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants