-
Notifications
You must be signed in to change notification settings - Fork 91
Better error handling using absl::StatusOr #646
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
049e9ee
migrating getJsonStringFromMessageOrDie to getJsonStringFromMessageOr…
Razdeep 5baabbb
using absl::StatusOr<std::string> return type for formatProto
Razdeep 41dc3e4
More method signatures converted to absl::StatusOr
Razdeep 9796ace
Fixed imports compilation error
Razdeep 4660033
Fixed more imports
Razdeep f7aa579
Fixed formatting issue
Razdeep 598288c
converted ProtobufUtil::StatusOr to absl::StatusOr
Razdeep eb8583c
Fixed ProtobufUtil::StatusOr to absl::StatusOr compilation error
Razdeep 7ee3a8b
Fixed ProtobufUtil::StatusOr to absl::StatusOr compilation error
Razdeep 6cf180c
Fixed ProtobufUtil::StatusOr to absl::StatusOr compilation error
Razdeep b9c1d40
ProtobufUtil::StatusOr to absl::StatusOr compilation error
Razdeep d86e68b
Force-casting
Razdeep 10ad995
Force-casting attempt
Razdeep fa1b865
forcecasting attempt
Razdeep 415056b
Forcecasting attempt 3
Razdeep fd9d767
Fixed actual duration status with pointer referencing
Razdeep 55819e3
Fixed minor mistake
Razdeep d1c0c78
reverted method definition of getGlobalResult
Razdeep e2b197c
Updated output_formatter_test
Razdeep aae0482
absl::Status mechanism added to FortioOutputFormatterImpl::getGlobalR…
Razdeep cf1120f
Fixed formatting
Razdeep 86f43f5
Merge branch 'main' into protobuf_safe_parsing
Razdeep a8d5fde
Lowered code-coverage threshold
Razdeep 22cb4d7
Code refactored & typos fixed
Razdeep 8cecd88
Removed unreachable code to increase test coverage
Razdeep 812fbdf
Added tests for better code-coverage
Razdeep 3ca4685
Fixed formatting
Razdeep 6ab1a36
Revert "Lowered code-coverage threshold"
Razdeep 690bbd5
Client process shutdown called even after error on formatProto
Razdeep 5d202eb
Change return type of getGlobalResult to absl::optional
Razdeep 46fd859
Merge branch 'main' into protobuf_safe_parsing
Razdeep f72c199
Merge branch 'main' of github.com:envoyproxy/nighthawk into protobuf_…
Razdeep 5a01e07
fixed //test:python_test failure
Razdeep e00e449
Lowering test converage threshold to 94.1
Razdeep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,9 @@ | |
| #include "client/process_impl.h" | ||
| #include "client/remote_process_impl.h" | ||
|
|
||
| #include "absl/status/status.h" | ||
| #include "absl/status/statusor.h" | ||
|
|
||
| using namespace std::chrono_literals; | ||
|
|
||
| namespace Nighthawk { | ||
|
|
@@ -81,7 +84,13 @@ bool Main::run() { | |
| result = process->run(output_collector); | ||
| } | ||
| auto formatter = output_formatter_factory.create(options_->outputFormat()); | ||
| std::cout << formatter->formatProto(output_collector.toProto()); | ||
| absl::StatusOr<std::string> formatted_proto = formatter->formatProto(output_collector.toProto()); | ||
| if (!formatted_proto.ok()) { | ||
| ENVOY_LOG(error, "An error occured while formatting proto"); | ||
| result = false; | ||
| } else { | ||
| std::cout << *formatted_proto; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I think we need: if (!formatted_proto.ok()) {
// .... <snip> looks ok to me as-is.
} else {
// only when formatted_proto.ok() == true
std::cout << *formatted_proto;
}I'm sorry if my earlier comment here was off or caused confusion. |
||
| process->shutdown(); | ||
| if (!result) { | ||
| ENVOY_LOG(error, "An error ocurred."); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
should we force result to false here? if this code line get hit, that probably means we should indicate failure.
alternatively, we could consider propagating
absl::status_oreven further up (so we return that instead of the boolean we use return right now) if you'd be up for it, but feel free to not do this, I don't intend to bloat this 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.
What shall be the status code for [1]?
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.
Consider setting result to false and fall trough, to have the
if(!result) {...clause handle the logging/error handling. Minimizing the control logic helps keeping coverage up. If we want to specialise the message that gets logged we can declare/set that separately.