-
Notifications
You must be signed in to change notification settings - Fork 21
Error Code Interface & Partially Remove Internal Exceptions #88
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
Conversation
jimson-msft
commented
Oct 2, 2021
- Provide error code returning interface
- Strip internal exceptions for win10
- For rest, internal classes may call 3p libraries which have throwing methods, wrap these in try-catch. Will remove exceptions on REST side at a later point in time.
- Add a error macro header, eventually will move into shared header.
CMakeLists.txt
Outdated
| option (DO_INCLUDE_SDK "Build subproject sdk-cpp" OFF) | ||
|
|
||
| option (DO_BUILD_TESTS "Set DO_BUILD_TESTS to OFF to skip building tests." ON) | ||
| option (DO_ENABLE_EXCEPTIONS "Set DO_ENABLE_EXCEPTIONS to ON to disable compiling with exceptions" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is copied to sdk-cpp/cmakelists.txt. Delete from here?
CMakeLists.txt
Outdated
| option (DO_INCLUDE_SDK "Build subproject sdk-cpp" OFF) | ||
|
|
||
| option (DO_BUILD_TESTS "Set DO_BUILD_TESTS to OFF to skip building tests." ON) | ||
| option (DO_ENABLE_EXCEPTIONS "Set DO_ENABLE_EXCEPTIONS to ON to disable compiling with exceptions" OFF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They probably don't need to do anything since they don't use cmake and by default DO_ENABLE_EXCEPTIONS will not be defined in their build system. Win-win.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, yea +1 on this
sdk-cpp/include/do_download.h
Outdated
| */ | ||
| void set_property(download_property key, const download_property_value& value); | ||
| download_property_value get_property(download_property key); | ||
| void get_property(download_property key, download_property_value& value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'll have it as a return val instead of an out param here
| ~download_property_value() = default; | ||
|
|
||
| #if (DO_ENABLE_EXCEPTIONS) | ||
| static void make(download_property_value& out, const std::string& val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| void as(status_callback_t& val) const; | ||
| #endif | ||
|
|
||
| static int32_t make_nothrow(download_property_value& out, const std::string& val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdk-cpp/include/do_download_status.h
Outdated
|
|
||
| } // namespace deliveryoptimization | ||
| } // namespace microsoft | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// _DELIVERY_OPTIMIZATION_DO_DOWNLOAD_STATUS_H #Closed
sdk-cpp/include/do_error_macros.h
Outdated
| #endif | ||
|
|
||
| //TODO(jimson) Looks like these conversions are causing test issues with tests | ||
| #define DO_ERROR_FROM_SYSTEM_ERROR(x) (int32_t)(0xC0000000 | (0xD0 << 16) | ((int32_t)(x) & 0x0000FFFF)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdk-cpp/include/do_error_macros.h
Outdated
| #endif | ||
|
|
||
| //TODO(jimson) Looks like these conversions are causing test issues with tests | ||
| #define DO_ERROR_FROM_SYSTEM_ERROR(x) (int32_t)(0xC0000000 | (0xD0 << 16) | ((int32_t)(x) & 0x0000FFFF)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't fix here, will reserve that for when we move these macros into the shared error macro header
sdk-cpp/include/do_exceptions.h
Outdated
| @@ -4,10 +4,13 @@ | |||
| #ifndef _DELIVERY_OPTIMIZATION_DO_EXCEPTIONS_H | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| void get_property(download_property key, download_property_value& value); | ||
| #endif | ||
|
|
||
| int32_t start_nothrow() noexcept; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Highly recommend returning std::error_code with our existing error_category. I don't know all the details of reusing std::error_code correctly but we should get the API right.
Expose a new method in do_exceptions.h, in our details namespace, for use in all our methods:
std::error_code make_error_code(int32_t code); #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably need other make_*_error_code methods to differentiate errors from different sources (boost/libcurl/OS) but those can come later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan on adding a custom error class in the future PR and returning that custom error code, this was moreso to just get the code factored correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. Was gonna ask whether more PRs are coming.
sdk-cpp/src/do_download.cpp
Outdated
| else | ||
| { | ||
| throw_if_fail(_download->SetProperty(prop, val)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call the nothrow version for non-trivial methods. #Closed
| if (isCancelled) | ||
| { | ||
| msdod::ThrowException(std::errc::operation_canceled); | ||
| return DO_ERROR_FROM_STD_ERROR(std::errc::operation_canceled); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdk-cpp/src/do_download_property.cpp
Outdated
| RETURN_IF_FAILED(temp._val->Init(val)); | ||
|
|
||
| out = temp; | ||
| return S_OK;; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -1,5 +1,4 @@ | |||
| // Copyright (c) Microsoft Corporation. | |||
| // Licensed under the MIT License. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retain copyright. You'll also need to scope the #if when using std::error_code return type. #Resolved
sdk-cpp/src/do_exceptions.cpp
Outdated
| @@ -1,5 +1,4 @@ | |||
| // Copyright (c) Microsoft Corporation. | |||
| // Licensed under the MIT License. | |||
| #if (DO_ENABLE_EXCEPTIONS) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright header is removed in some other files too. Intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, issue with merge - will resolve
| // Licensed under the MIT License. | ||
|
|
||
| #ifndef _DELIVERY_OPTIMIZATION_DO_NONCOPYABLE_H | ||
| #ifndef _DELIVERY_OPTIMIZATION_DNONCOPYABLE_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi, not reverted yet
|
|
||
| #include "do_exceptions_internal.h" | ||
|
|
||
| #include <exception> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required. Header already includes it. #Closed
| using namespace microsoft::deliveryoptimization::details; | ||
|
|
||
| std::wstring UTF8toWstr(const char* str, size_t cch = 0) | ||
| int32_t UTF8toWstr(std::wstring& wstr, const char* str, size_t cch = 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CDownloadPropertyValueInternal::CDownloadPropertyValueInternal(const download_property_value::status_callback_t& val) | ||
| int32_t CDownloadPropertyValueInternal::Init(const download_property_value::status_callback_t& val) noexcept | ||
| { | ||
| V_VT(&_var) = VT_EMPTY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the std::vector one also requires this, I suggest implementing the default constructor and calling VariantInit there. The constructor on the rest side can use = default in its .cpp file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing in next PR
| #ifdef DEBUG | ||
| assert(SUCCEEDED(VariantCopy(&_var, &rhs._var))); | ||
| #else: | ||
| (void)VariantCopy(&_var, &rhs._var); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for other places where we only expect allocation failures.
if (FAILED(res))
{
#if defined(DO_ENABLE_EXCEPTIONS)
throw std::bad_alloc();
#else
std::terminate();
#endif
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, fixing in next PR
| } | ||
| return static_cast<int32_t>(msdo::errc::no_service); | ||
| } | ||
| catch (msdo::exception& e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, fixing rest side in next PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the uri builder invoked methods don't throw exceptions as far as I can tell.
| std::vector<int32_t> expectedErrors = { 0, static_cast<int32_t>(msdo::errc::do_e_unknown_property_id) }; | ||
|
|
||
| msdo::download_property_value integrityCheckMandatory(true); | ||
| std::unique_ptr<msdo::download_property_value> integrityCheckMandatory = std::make_unique<msdo::download_property_value>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ASSERT_TRUE(false); | ||
| } | ||
|
|
||
| // For some reason, custom headers are getting rejected and returning E_INVALIDARG now, disabling test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| { | ||
| _download = std::make_shared<msdod::CDownloadImpl>(uri, downloadFilePath); | ||
| _download = std::make_shared<msdod::CDownloadImpl>(); | ||
| _download->Init(uri, downloadFilePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should use the make methods convention here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing in next PR
| generate_options.extend(["-DDO_BUILD_TESTS=OFF"]) | ||
|
|
||
| if self.enable_exceptions: | ||
| generate_options.extend(["-DDO_ENABLE_EXCEPTIONS=OFF"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a way to disable without modifying source code, im flipping the flag back to disable
shishirb-MSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()