Skip to content

Commit

Permalink
mobile: exceptionless java build
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
  • Loading branch information
alyssawilk committed Nov 1, 2023
1 parent 5d9b101 commit 4cb2523
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/mobile-compile_time_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ jobs:
--define=envoy_yaml=disabled \
--copt=-fno-unwind-tables \
--copt=-fno-exceptions \
//test/performance:test_binary_size
--define=google_grpc=disabled \
//test/performance:test_binary_size //library/cc/...
cc_test:
needs: env
Expand Down
3 changes: 2 additions & 1 deletion mobile/library/cc/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ std::string Engine::dumpStats() {

envoy_status_t Engine::terminate() {
if (terminated_) {
throw std::runtime_error("attempting to double terminate Engine");
IS_ENVOY_BUG("attempted to double terminate engine");
return ENVOY_FAILURE;
}
envoy_status_t ret = terminate_engine(engine_, /* release */ false);
terminated_ = true;
Expand Down
8 changes: 6 additions & 2 deletions mobile/library/cc/log_level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <stdexcept>

#include "source/common/common/assert.h"

namespace Envoy {
namespace Platform {

Expand All @@ -18,7 +20,8 @@ std::string logLevelToString(LogLevel method) {
}
}

throw std::out_of_range("unknown log level type");
IS_ENVOY_BUG("unknown log level, defaulting to off");
return LOG_LEVEL_LOOKUP[6].second;
}

LogLevel logLevelFromString(const std::string& str) {
Expand All @@ -28,7 +31,8 @@ LogLevel logLevelFromString(const std::string& str) {
}
}

throw std::out_of_range("unknown log level type");
IS_ENVOY_BUG("unknown log level, defaulting to off");
return LOG_LEVEL_LOOKUP[6].first;
}

} // namespace Platform
Expand Down
6 changes: 1 addition & 5 deletions mobile/library/cc/request_headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ const std::string& RequestHeaders::authority() const { return (*this)[":authorit
const std::string& RequestHeaders::path() const { return (*this)[":path"][0]; }

absl::optional<RetryPolicy> RequestHeaders::retryPolicy() const {
try {
return absl::optional<RetryPolicy>(RetryPolicy::fromRawHeaderMap(allHeaders()));
} catch (const std::exception&) {
return absl::optional<RetryPolicy>();
}
return absl::optional<RetryPolicy>(RetryPolicy::fromRawHeaderMap(allHeaders()));
}

RequestHeadersBuilder RequestHeaders::toRequestHeadersBuilder() const {
Expand Down
8 changes: 6 additions & 2 deletions mobile/library/cc/request_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <stdexcept>

#include "source/common/common/assert.h"

#include "absl/strings/string_view.h"

namespace Envoy {
Expand All @@ -25,7 +27,8 @@ absl::string_view requestMethodToString(RequestMethod method) {
}
}

throw std::out_of_range("unknown request method type");
IS_ENVOY_BUG("unknown method");
return "";
}

RequestMethod requestMethodFromString(absl::string_view str) {
Expand All @@ -35,7 +38,8 @@ RequestMethod requestMethodFromString(absl::string_view str) {
}
}

throw std::out_of_range("unknown request method type");
IS_ENVOY_BUG("unknown method");
return REQUEST_METHOD_LOOKUP[0].first;
}

} // namespace Platform
Expand Down
2 changes: 1 addition & 1 deletion mobile/library/cc/response_headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Platform {

int ResponseHeaders::httpStatus() const {
if (!contains(":status")) {
throw std::logic_error("ResponseHeaders does not contain :status");
return 0;
}
return stoi((*this)[":status"][0]);
}
Expand Down
32 changes: 2 additions & 30 deletions mobile/library/cc/retry_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,6 @@
namespace Envoy {
namespace Platform {

static const std::pair<RetryRule, std::string> RETRY_RULE_LOOKUP[]{
{RetryRule::Status5xx, "5xx"},
{RetryRule::GatewayError, "gateway-error"},
{RetryRule::ConnectFailure, "connect-failure"},
{RetryRule::RefusedStream, "refused-stream"},
{RetryRule::Retriable4xx, "retriable-4xx"},
{RetryRule::RetriableHeaders, "retriable-headers"},
{RetryRule::Reset, "reset"},
};

std::string retryRuleToString(RetryRule retry_rule) {
for (const auto& pair : RETRY_RULE_LOOKUP) {
if (pair.first == retry_rule) {
return pair.second;
}
}
throw std::invalid_argument("invalid retry rule");
}

RetryRule retryRuleFromString(const std::string& str) {
for (const auto& pair : RETRY_RULE_LOOKUP) {
if (pair.second == str) {
return pair.first;
}
}
throw std::invalid_argument("invalid retry rule");
}

RawHeaderMap RetryPolicy::asRawHeaderMap() const {
RawHeaderMap outbound_headers{
{"x-envoy-max-retries", {std::to_string(max_retry_count)}},
Expand All @@ -45,7 +17,7 @@ RawHeaderMap RetryPolicy::asRawHeaderMap() const {
std::vector<std::string> retry_on_copy;
retry_on_copy.reserve(retry_on.size());
for (const auto& retry_rule : retry_on) {
retry_on_copy.push_back(retryRuleToString(retry_rule));
retry_on_copy.push_back(retry_rule);
}

if (!retry_status_codes.empty()) {
Expand Down Expand Up @@ -89,7 +61,7 @@ RetryPolicy RetryPolicy::fromRawHeaderMap(const RawHeaderMap& headers) {
has_retriable_status_codes = true;
continue;
}
retry_policy.retry_on.push_back(retryRuleFromString(retry_rule_str));
retry_policy.retry_on.push_back(retry_rule_str);
}
}

Expand Down
15 changes: 1 addition & 14 deletions mobile/library/cc/retry_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,9 @@ namespace Platform {

class RequestHeaders;

enum RetryRule {
Status5xx,
GatewayError,
ConnectFailure,
RefusedStream,
Retriable4xx,
RetriableHeaders,
Reset,
};

std::string retryRuleToString(RetryRule retry_rule);
RetryRule retryRuleFromString(const std::string& str);

struct RetryPolicy {
int max_retry_count;
std::vector<RetryRule> retry_on;
std::vector<std::string> retry_on;
std::vector<int> retry_status_codes;
absl::optional<int> per_try_timeout_ms;
absl::optional<int> total_upstream_timeout_ms;
Expand Down

0 comments on commit 4cb2523

Please sign in to comment.