Skip to content

Incorporating xlang error handling into cppxlang#489

Merged
manodasanW merged 12 commits into
masterfrom
manodasanw/cppxlangerror
Jul 17, 2019
Merged

Incorporating xlang error handling into cppxlang#489
manodasanW merged 12 commits into
masterfrom
manodasanw/cppxlangerror

Conversation

@manodasanW

Copy link
Copy Markdown
Member
  • Updating the cppxlang projection to represent the state of error handling in xlang
  • Addressing some PR feedback from the previous PR for error handling in xlang with how to represent HRESULT errors from functions whose interface can't change like QueryInterface by introducing com_interop_result

Comment thread src/platform/error_abi.cpp Outdated
void GetProjectionIdentifier(xlang_string* projection_identifier) noexcept override
{
*projection_identifier = m_projection_identifier;
*projection_identifier = nullptr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can/should safely assume that copy_to_abi will clear the out param. If that's not the case then we should make it so.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

agreed. Since it has no failure mode, it must always set its out parameter to a stable value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

copy_to_abi seems to taken in a reference and asserts that the passed reference == nullptr.

pointer = static_cast<int32_t>(0x80004003)
};
#else
enum com_interop_result

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This sounds like a very long-winded way of saying "HRESULT" 😉

@@ -218,18 +234,18 @@ extern "C"
#else
enum xlang_result

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems confusing that there both com_results and xlang_results.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To be clear, I'm not saying there's no merit for this just that we may want to bury the HRESULT in the ABI and just stick with a handful of int32_t values where absolutely necessary (e.g. QI).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a side effect of the long conversation we had about reducing & simplifying the xlang error codes to a new set of values that don't align with the COM values. It's useful to note, then that the ABI for the first three methods is actually COM-compatible including failure values. It's a little verbose but nicely explicit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The reason for this change was to avoid confusion on what error is returned here. We have an xlang error for no interface and an COM error for no interface, both of which have different values. To keep compat with COM for IUnknown, we made the choice to keep this as a COM error. If we were to represent that as an int32, it can introduce confusion to a developer on what to return here as the first instinct would be to return / check for the xlang version of no interface as we are in xlang. But, they have to actually return the COM version of the error. To make that clear, the int32 was changed to com_interop_result. I do agree that it is a little verbose, but this should really only affect QueryInterface and related functions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, I just think that if anyone is actually implementing QueryInterface and thus having to figure this out they're either one of us or we've failed because nobody should be dealing with the ABI directly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree no one else should probably be dealing with the ABI directly. This change also makes sure we ourselves don't accidentally use the wrong error value when we return from the com interop functions by essentially having a compile time safety check. In addition, in cross platform scenarios, it ensures that we don't introduce a new com error without explicitly being aware we are adding a new error for interop scenarios and providing a mapping to an xlang error for it.

In theory, we can make returning success less verbose by having a define S_OK or something similar as com_interop_result::success and returning that instead. What do you think about that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Macros are evil. Let's leave it as is. :shipit:


AddRef();
return 0;
return com_interop_result::success;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This wouldn't be necessary if the return type was simply int32_t. Seems overly verbose for an ABI.

Comment thread src/tool/cppxlang/code_writers.h
Comment thread src/tool/cppxlang/strings/base_composable.h Outdated
Comment thread src/tool/cppxlang/strings/base_meta.h Outdated
value{};
guid iid{};
if (XLANG_IIDFromString(iid_str, &iid) == error_ok)
if (XLANG_IIDFromString(iid_str, &iid) == 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Zero here and bla::success below. Zero is so much more concise.

@manodasanW

Copy link
Copy Markdown
Member Author

Build status not being reflected, but it passed.

@manodasanW manodasanW merged commit e89c90b into master Jul 17, 2019
@Scottj1s Scottj1s deleted the manodasanw/cppxlangerror branch July 31, 2019 17:41
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.

4 participants