Skip to content

Conversation

@jimson-msft
Copy link
Contributor

  • 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.

@jimson-msft jimson-msft requested a review from a team as a code owner October 2, 2021 20:31
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)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

DO_ENABLE_EXCEPTIONS

Since this applies to the sdk only, how about moving all changes in this file to the sdk cmakelists.txt? #Resolved

Copy link
Collaborator

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)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

OFF

I would default this to ON and let Edge disable it. #Closed

Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

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.

Copy link
Contributor Author

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

*/
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);
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

void

This should return the value instead, no? #Closed

Copy link
Contributor Author

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);
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

download_property_value

Return this instead in all the throwing make methods. #Closed

void as(status_callback_t& val) const;
#endif

static int32_t make_nothrow(download_property_value& out, const std::string& val);
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

out

Out params come after the In. #Closed


} // namespace deliveryoptimization
} // namespace microsoft
#endif
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

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

#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))
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

0xD0

FACILITY_DELIVERY_OPTIMIZATION #Closed

#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))
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

DO_ERROR_FROM_SYSTEM_ERROR

Suggest turning both the error translations into inline methods. #Closed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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

@@ -4,10 +4,13 @@
#ifndef _DELIVERY_OPTIMIZATION_DO_EXCEPTIONS_H
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

_DELIVERY_OPTIMIZATION_DO_EXCEPTIONS_H

Considering renaming this file now that exceptions can be turned off, to not confuse users. do_errors.h? #Closed

@shishirb-MSFT
Copy link
Collaborator

shishirb-MSFT commented Oct 6, 2021

#ifndef FAILED

Remove. Defined in do_error_macros.h.


In reply to: 936179229


In reply to: 936179229


In reply to: 936179229


In reply to: 936179229


In reply to: 936179229


Refers to: sdk-cpp/include/do_exceptions.h:20 in 57adb40. [](commit_id = 57adb40, deletion_comment = False)

void get_property(download_property key, download_property_value& value);
#endif

int32_t start_nothrow() noexcept;
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

int32_t

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

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

else
{
throw_if_fail(_download->SetProperty(prop, val));
}
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

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);
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

When we return std::error_code instead, we don't have to perform these conversions. Tests will be happy too.

RETURN_IF_FAILED(temp._val->Init(val));

out = temp;
return S_OK;;
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

;;

nit: double semi-colons #Closed

@@ -1,5 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

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

@@ -1,5 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#if (DO_ENABLE_EXCEPTIONS)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

#if

Use #if defined(DO_ENABLE_EXCEPTIONS). We do not intend to depend on the value of the DO_ENABLE_EXCEPTIONS macro. #Closed

Copy link
Collaborator

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?

Copy link
Contributor Author

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
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

_DELIVERY_OPTIMIZATION_DNONCOPYABLE_H

revert #Resolved

Copy link
Collaborator

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>
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

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)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

wstr

Move wstr to end of params list. #Closed

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;
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

V_VT(&_var) = VT_EMPTY;

Why not use VariantInit? Standard/conventional way. #Resolved

Copy link
Collaborator

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.

Copy link
Contributor Author

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);
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

void

Silently ignores errors. I suggest calling std::terminate instead when this fails (memory alloc failure). #Resolved

Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

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
}

Copy link
Contributor Author

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)
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

msdo::exception

All invoked methods here throw only this exception type? #Resolved

Copy link
Contributor Author

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

Copy link
Contributor Author

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>();
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

make_unique

Why allocate and then call make() again? #Closed

ASSERT_TRUE(false);
}

// For some reason, custom headers are getting rejected and returning E_INVALIDARG now, disabling test
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

disabling

Use the gtest way of disabling tests: prefix method name with DISABLED_ #Closed

{
_download = std::make_shared<msdod::CDownloadImpl>(uri, downloadFilePath);
_download = std::make_shared<msdod::CDownloadImpl>();
_download->Init(uri, downloadFilePath);
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 6, 2021

Choose a reason for hiding this comment

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

Init

Ignores errors from the Init method. Do you intend to handle it in a separate PR? #Resolved

Copy link
Contributor Author

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

Copy link
Contributor Author

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"])
Copy link
Collaborator

@shishirb-MSFT shishirb-MSFT Oct 7, 2021

Choose a reason for hiding this comment

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

OFF

This should be ON but since that is the default, I'd remove --enable-exceptions arg entirely. #Resolved

Copy link
Contributor Author

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

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 90e4718 into develop Oct 7, 2021
@jimson-msft jimson-msft deleted the user/jimson/error_code_interface branch October 7, 2021 23:00
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.

2 participants