Skip to content

header: getting rid of exception-throwing behaviors in header files [include/ and source/common/]#12502

Merged
mattklein123 merged 14 commits intoenvoyproxy:masterfrom
aimless404:noexcept
Aug 11, 2020
Merged

header: getting rid of exception-throwing behaviors in header files [include/ and source/common/]#12502
mattklein123 merged 14 commits intoenvoyproxy:masterfrom
aimless404:noexcept

Conversation

@aimless404
Copy link
Copy Markdown
Contributor

@aimless404 aimless404 commented Aug 5, 2020

Signed-off-by: Yifan Yang needyyang@google.com

This is a part of efforts to get rid of all the exception throwing semantics in envoy header files, as discussed here #12469. This PR deals with all instances that throw plain envoy exceptions in the described sub modules.

Commit Message:
Additional Description:
Risk Level: Low. No new mechanics except the additional status check is introduced.
Testing:
Docs Changes:
Release Notes:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]

Signed-off-by: Yifan Yang <needyyang@google.com>
* more than a single PR.
*/
template <typename T, ByteOrder Endianness = ByteOrder::Host, size_t Size = sizeof(T)>
StatusOr<T> peekIntNoExcept(uint64_t start = 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

drive by: instead of large changes like this can't you just throw the exception from the cc file? I don't see why these changes are necessary. Actually removing exceptions from control flow is orthogonal. Let's please keep the changes focused on just removing exceptions from header files which generally should be trivial.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Working with template functions is a little different as we will need to do explicit template instantiations to move the template function implementations into .cc files. That also means that we need to instantiate all the currently used type in .cc files as such:

template a_lot_of_types peekInt(uint64_t start);

But yeah, if you believe this way is better than what my current method is, I am certainly on board with it as it makes the change much narrower and cleaner (instead of going around changing all call sites).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't even think that is necessary. Just define a non-templated helper which throws the exception and implement it in a cc file. This will fix the immediate problem if no throwing from header files very quickly and get the linter up. Now, whether this fixes the real problem in the sense that you can't through through header files is a different issue, but I would cross that bridge when you come to it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that is a great way to do this! Wonder why that didn't become obvious to me. But I have just heard that @asraa is trying to get rid of the exception throwing behavior altogether in the dataplane pipeline. So maybe she has some input on this topic.

But this is definitely a much better way of doing this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But I have just heard that @asraa is trying to get rid of the exception throwing behavior altogether in the dataplane pipeline. So maybe she has some input on this topic.

As I said above, I think removing exceptions from certain code paths is orthogonal to this effort. My advice is to start by meeting your immediate goal in as simple a way as possible and then we can go from there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agreed.

@aimless404 aimless404 changed the title extension: migrating towards non-exception-throwing buffer::peekInt() header: getting rid of exception-throwing behaviors in header files [include/ and source/common/] Aug 6, 2020
Signed-off-by: Yifan Yang <needyyang@google.com>
@aimless404
Copy link
Copy Markdown
Contributor Author

@yanavlasov could you take a look?

yanavlasov
yanavlasov previously approved these changes Aug 7, 2020
@yanavlasov
Copy link
Copy Markdown
Contributor

LGTM, I'll re-approve once format is fixed.

Yifan Yang added 2 commits August 7, 2020 20:11
Yifan Yang added 4 commits August 7, 2020 20:34
Signed-off-by: Yifan Yang <needyyang@google.com>
Signed-off-by: Yifan Yang <needyyang@google.com>
…_format script

Signed-off-by: Yifan Yang <needyyang@google.com>
@aimless404
Copy link
Copy Markdown
Contributor Author

@yanavlasov do you mind taking a look? I believe the only test that fails here is a flaky one.

@aimless404
Copy link
Copy Markdown
Contributor Author

@yanavlasov @mattklein123

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM with one small comment, thanks!

/wait

ExceptionUtil::throwEnvoyException("ADS must be configured to support an ADS config source");
// it should never reach here but the compiler complains and the alternative will be to change
// the return type of the parent virtual function to absl::<optional<current_return_type>>
return nullptr;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use NOT_REACHED here. I think you may also be able to use some type of "never returns" annotation on throwEnvoyException

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

used noreturn keyword on function signature

Signed-off-by: Yifan Yang <needyyang@google.com>
Signed-off-by: Yifan Yang <needyyang@google.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

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