From 8a2cabc8afb2240198e3ba731e787b77675f2bd6 Mon Sep 17 00:00:00 2001 From: Alyssa Wilk Date: Tue, 13 Aug 2024 16:42:47 +0000 Subject: [PATCH] exceptions: cleaning up macros Signed-off-by: Alyssa Wilk --- .../filters/network/source/client_ssl_auth.cc | 2 +- .../filters/network/source/tra/tra_impl.cc | 2 +- envoy/common/exception.h | 13 +++---------- source/common/common/logger_delegates.cc | 2 +- source/common/formatter/http_specific_formatter.cc | 8 ++++---- source/common/listener_manager/listener_impl.cc | 6 +++--- source/common/protobuf/utility.cc | 2 +- source/common/secret/sds_api.cc | 2 +- source/common/upstream/cluster_manager_impl.cc | 2 +- .../common/upstream/health_checker_event_logger.h | 2 +- source/common/upstream/health_discovery_service.cc | 6 +++--- source/common/upstream/outlier_detection_impl.h | 2 +- source/common/upstream/upstream_impl.cc | 2 +- .../access_loggers/common/file_access_log_impl.cc | 2 +- .../access_loggers/grpc/grpc_access_log_impl.cc | 2 +- .../open_telemetry/grpc_access_log_impl.cc | 2 +- .../common/wasm/remote_async_datasource.cc | 2 +- .../compression/zstd/common/dictionary_manager.h | 2 +- .../grpc/grpc_collection_subscription_factory.cc | 6 +++--- .../config_subscription/grpc/grpc_mux_impl.cc | 6 +++--- .../config_subscription/grpc/grpc_mux_impl.h | 2 +- .../grpc/grpc_subscription_factory.cc | 12 ++++++------ .../config_subscription/grpc/new_grpc_mux_impl.cc | 4 ++-- .../config_subscription/grpc/watch_map.cc | 2 +- .../grpc/xds_mux/grpc_mux_impl.cc | 6 +++--- .../filters/common/ratelimit/ratelimit_impl.cc | 2 +- source/extensions/filters/http/composite/action.cc | 4 ++-- source/extensions/filters/http/ext_authz/config.cc | 2 +- .../extensions/filters/http/ext_proc/client_impl.cc | 2 +- .../grpc_json_transcoder/json_transcoder_filter.cc | 2 +- .../filters/http/rate_limit_quota/client_impl.cc | 2 +- .../extensions/filters/network/ext_authz/config.cc | 2 +- .../extensions/filters/network/mongo_proxy/proxy.cc | 2 +- .../filters/network/redis_proxy/config.cc | 2 +- .../sni_dynamic_forward_proxy/proxy_filter.cc | 2 +- .../dynamic_forward_proxy/proxy_filter.cc | 2 +- .../health_check/event_sinks/file/file_sink_impl.h | 2 +- .../health_checkers/http/health_checker_impl.cc | 2 +- .../health_checkers/tcp/health_checker_impl.cc | 4 ++-- source/extensions/key_value/file_based/config.cc | 2 +- .../injected_resource/injected_resource_monitor.cc | 2 +- .../extensions/stat_sinks/common/statsd/statsd.cc | 2 +- source/extensions/stat_sinks/dog_statsd/config.cc | 2 +- .../extensions/stat_sinks/graphite_statsd/config.cc | 2 +- .../extensions/stat_sinks/metrics_service/config.cc | 2 +- .../extensions/stat_sinks/open_telemetry/config.cc | 2 +- source/extensions/stat_sinks/statsd/config.cc | 2 +- source/extensions/tracers/datadog/tracer.cc | 6 +++--- .../opentelemetry/opentelemetry_tracer_impl.cc | 2 +- .../tracers/skywalking/skywalking_tracer_impl.cc | 2 +- .../extensions/tracers/zipkin/zipkin_tracer_impl.cc | 8 ++++---- source/server/config_validation/server.cc | 2 +- source/server/server.cc | 2 +- test/common/http/async_client_impl_test.cc | 4 ++-- test/common/router/header_formatter_test.cc | 2 +- test/common/upstream/upstream_impl_test.cc | 2 +- .../original_dst/original_dst_cluster_test.cc | 2 +- .../dynamic_forward_proxy/dns_cache_impl_test.cc | 2 +- .../filters/http/common/fuzz/uber_filter.cc | 2 +- test/fuzz/utility.h | 4 ++-- test/integration/admin_html/test_server.cc | 2 +- 61 files changed, 91 insertions(+), 98 deletions(-) diff --git a/contrib/client_ssl_auth/filters/network/source/client_ssl_auth.cc b/contrib/client_ssl_auth/filters/network/source/client_ssl_auth.cc index dc3415b4236f..305f2db8ed71 100644 --- a/contrib/client_ssl_auth/filters/network/source/client_ssl_auth.cc +++ b/contrib/client_ssl_auth/filters/network/source/client_ssl_auth.cc @@ -35,7 +35,7 @@ ClientSslAuthConfig::ClientSslAuthConfig( std::chrono::milliseconds(1000)), tls_(tls.allocateSlot()), stats_(generateStats(scope, config.stat_prefix())) { auto list_or_error = Network::Address::IpList::create(config.ip_white_list()); - THROW_IF_STATUS_NOT_OK(list_or_error, throw); + THROW_IF_NOT_OK_REF(list_or_error.status()); ip_allowlist_ = std::move(list_or_error.value()); if (!cm.clusters().hasCluster(remote_cluster_name_)) { diff --git a/contrib/sip_proxy/filters/network/source/tra/tra_impl.cc b/contrib/sip_proxy/filters/network/source/tra/tra_impl.cc index 95b77c071d5a..e9c0eca313f4 100644 --- a/contrib/sip_proxy/filters/network/source/tra/tra_impl.cc +++ b/contrib/sip_proxy/filters/network/source/tra/tra_impl.cc @@ -204,7 +204,7 @@ ClientPtr traClient(Event::Dispatcher& dispatcher, Server::Configuration::Factor .clusterManager() .grpcAsyncClientManager() .getOrCreateRawAsyncClient(grpc_service, context.scope(), true); - THROW_IF_STATUS_NOT_OK(client_or_error, throw); + THROW_IF_NOT_OK_REF(client_or_error.status()); return std::make_unique( client_or_error.value(), dispatcher, timeout); } diff --git a/envoy/common/exception.h b/envoy/common/exception.h index 0688b440dfbc..5734df1f6628 100644 --- a/envoy/common/exception.h +++ b/envoy/common/exception.h @@ -42,21 +42,14 @@ class EnvoyException : public std::runtime_error { } \ } while (0) +// Simple macro to handle bridging functions which return absl::StatusOr, and +// functions which throw errors. #define THROW_IF_NOT_OK(status_fn) \ do { \ const absl::Status status = (status_fn); \ THROW_IF_NOT_OK_REF(status); \ } while (0) -// Simple macro to handle bridging functions which return absl::StatusOr, and -// functions which throw errors. -// -// The completely unnecessary throw_action argument was just so 'throw' appears -// at the call site, so format checks about use of exceptions would be triggered. -// This didn't work, so the variable is no longer used and is not duplicated in -// the macros above. -#define THROW_IF_STATUS_NOT_OK(variable, throw_action) THROW_IF_NOT_OK_REF(variable.status()); - #define RETURN_IF_NOT_OK_REF(variable) \ if (const absl::Status& temp_status = variable; !temp_status.ok()) { \ return temp_status; \ @@ -69,7 +62,7 @@ class EnvoyException : public std::runtime_error { } template Type returnOrThrow(absl::StatusOr type_or_error) { - THROW_IF_STATUS_NOT_OK(type_or_error, throw); + THROW_IF_NOT_OK_REF(type_or_error.status()); return std::move(type_or_error.value()); } diff --git a/source/common/common/logger_delegates.cc b/source/common/common/logger_delegates.cc index cf3874d6a654..52975cd22129 100644 --- a/source/common/common/logger_delegates.cc +++ b/source/common/common/logger_delegates.cc @@ -15,7 +15,7 @@ FileSinkDelegate::FileSinkDelegate(const std::string& log_path, : SinkDelegate(log_sink) { auto file_or_error = log_manager.createAccessLog( Filesystem::FilePathAndType{Filesystem::DestinationType::File, log_path}); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); log_file_ = file_or_error.value(); setDelegate(); } diff --git a/source/common/formatter/http_specific_formatter.cc b/source/common/formatter/http_specific_formatter.cc index a46c9559c9f5..ab668bb60ac2 100644 --- a/source/common/formatter/http_specific_formatter.cc +++ b/source/common/formatter/http_specific_formatter.cc @@ -300,7 +300,7 @@ BuiltInHttpCommandParser::getKnownFormatters() { {CommandSyntaxChecker::PARAMS_REQUIRED | CommandSyntaxChecker::LENGTH_ALLOWED, [](absl::string_view format, absl::optional max_length) { auto result = SubstitutionFormatUtils::parseSubcommandHeaders(format); - THROW_IF_STATUS_NOT_OK(result, throw); + THROW_IF_NOT_OK_REF(result.status()); return std::make_unique(result.value().first, result.value().second, max_length); }}}, @@ -308,7 +308,7 @@ BuiltInHttpCommandParser::getKnownFormatters() { {CommandSyntaxChecker::PARAMS_REQUIRED | CommandSyntaxChecker::LENGTH_ALLOWED, [](absl::string_view format, absl::optional max_length) { auto result = SubstitutionFormatUtils::parseSubcommandHeaders(format); - THROW_IF_STATUS_NOT_OK(result, throw); + THROW_IF_NOT_OK_REF(result.status()); return std::make_unique(result.value().first, result.value().second, max_length); }}}, @@ -316,7 +316,7 @@ BuiltInHttpCommandParser::getKnownFormatters() { {CommandSyntaxChecker::PARAMS_REQUIRED | CommandSyntaxChecker::LENGTH_ALLOWED, [](absl::string_view format, absl::optional max_length) { auto result = SubstitutionFormatUtils::parseSubcommandHeaders(format); - THROW_IF_STATUS_NOT_OK(result, throw); + THROW_IF_NOT_OK_REF(result.status()); return std::make_unique(result.value().first, result.value().second, max_length); }}}, @@ -364,7 +364,7 @@ BuiltInHttpCommandParser::getKnownFormatters() { {CommandSyntaxChecker::PARAMS_REQUIRED | CommandSyntaxChecker::LENGTH_ALLOWED, [](absl::string_view format, absl::optional max_length) { auto result = SubstitutionFormatUtils::parseSubcommandHeaders(format); - THROW_IF_STATUS_NOT_OK(result, throw); + THROW_IF_NOT_OK_REF(result.status()); return std::make_unique(result.value().first, result.value().second, max_length); }}}, diff --git a/source/common/listener_manager/listener_impl.cc b/source/common/listener_manager/listener_impl.cc index 5924d2deec86..a82bf3a8d375 100644 --- a/source/common/listener_manager/listener_impl.cc +++ b/source/common/listener_manager/listener_impl.cc @@ -236,7 +236,7 @@ std::string listenerStatsScope(const envoy::config::listener::v3::Listener& conf return absl::StrCat("envoy_internal_", config.name()); } auto address_or_error = Network::Address::resolveProtoAddress(config.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); return address_or_error.value()->asString(); } } // namespace @@ -324,7 +324,7 @@ ListenerImpl::ListenerImpl(const envoy::config::listener::v3::Listener& config, // All the addresses should be same socket type, so get the first address's socket type is // enough. auto address_or_error = Network::Address::resolveProtoAddress(config.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); auto address = std::move(address_or_error.value()); checkIpv4CompatAddress(address, config.address()); addresses_.emplace_back(address); @@ -340,7 +340,7 @@ ListenerImpl::ListenerImpl(const envoy::config::listener::v3::Listener& config, } auto addresses_or_error = Network::Address::resolveProtoAddress(config.additional_addresses(i).address()); - THROW_IF_STATUS_NOT_OK(addresses_or_error, throw); + THROW_IF_NOT_OK_REF(addresses_or_error.status()); auto additional_address = std::move(addresses_or_error.value()); checkIpv4CompatAddress(address, config.additional_addresses(i).address()); addresses_.emplace_back(additional_address); diff --git a/source/common/protobuf/utility.cc b/source/common/protobuf/utility.cc index e9b5003b9061..2bf646a6b907 100644 --- a/source/common/protobuf/utility.cc +++ b/source/common/protobuf/utility.cc @@ -936,7 +936,7 @@ void MessageUtil::loadFromFile(const std::string& path, Protobuf::Message& messa ProtobufMessage::ValidationVisitor& validation_visitor, Api::Api& api) { auto file_or_error = api.fileSystem().fileReadToEnd(path); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); const std::string contents = file_or_error.value(); // If the filename ends with .pb, attempt to parse it as a binary proto. if (absl::EndsWithIgnoreCase(path, FileExtensions::get().ProtoBinary)) { diff --git a/source/common/secret/sds_api.cc b/source/common/secret/sds_api.cc index 620bffb4972d..1f88e78babc1 100644 --- a/source/common/secret/sds_api.cc +++ b/source/common/secret/sds_api.cc @@ -210,7 +210,7 @@ SdsApi::FileContentMap SdsApi::loadFiles() { FileContentMap files; for (auto const& filename : getDataSourceFilenames()) { auto file_or_error = api_.fileSystem().fileReadToEnd(filename); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); files[filename] = file_or_error.value(); } return files; diff --git a/source/common/upstream/cluster_manager_impl.cc b/source/common/upstream/cluster_manager_impl.cc index 6c16ac21db73..fcdef2ad85cf 100644 --- a/source/common/upstream/cluster_manager_impl.cc +++ b/source/common/upstream/cluster_manager_impl.cc @@ -844,7 +844,7 @@ bool ClusterManagerImpl::addOrUpdateCluster(const envoy::config::cluster::v3::Cl // before destroy to avoid early initialization complete. auto status_or_cluster = loadCluster(cluster, new_hash, version_info, /*added_via_api=*/true, /*required_for_ads=*/false, warming_clusters_); - THROW_IF_STATUS_NOT_OK(status_or_cluster, throw); + THROW_IF_NOT_OK_REF(status_or_cluster.status()); const ClusterDataPtr previous_cluster = std::move(status_or_cluster.value()); auto& cluster_entry = warming_clusters_.at(cluster_name); cluster_entry->cluster_->info()->configUpdateStats().warming_state_.set(1); diff --git a/source/common/upstream/health_checker_event_logger.h b/source/common/upstream/health_checker_event_logger.h index 38bd0ed9d0a6..1039f78493f8 100644 --- a/source/common/upstream/health_checker_event_logger.h +++ b/source/common/upstream/health_checker_event_logger.h @@ -34,7 +34,7 @@ class HealthCheckEventLoggerImpl : public HealthCheckEventLogger { auto file_or_error = context.serverFactoryContext().accessLogManager().createAccessLog( Filesystem::FilePathAndType{Filesystem::DestinationType::File, health_check_config.event_log_path()}); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); file_ = file_or_error.value(); } for (const auto& config : health_check_config.event_logger()) { diff --git a/source/common/upstream/health_discovery_service.cc b/source/common/upstream/health_discovery_service.cc index b1b219263584..c12503b2169c 100644 --- a/source/common/upstream/health_discovery_service.cc +++ b/source/common/upstream/health_discovery_service.cc @@ -372,7 +372,7 @@ HdsCluster::HdsCluster(Server::Configuration::ServerFactoryContext& server_conte const LocalityEndpointTuple endpoint_key = {locality_endpoints.locality(), host}; // Initialize an endpoint host object. auto address_or_error = Network::Address::resolveProtoAddress(host.endpoint().address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); HostSharedPtr endpoint = std::make_shared( info_, "", std::move(address_or_error.value()), nullptr, nullptr, 1, locality_endpoints.locality(), host.endpoint().health_check_config(), 0, @@ -487,7 +487,7 @@ void HdsCluster::updateHosts( // We do not have this endpoint saved, so create a new one. auto address_or_error = Network::Address::resolveProtoAddress(endpoint.endpoint().address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); host = std::make_shared(info_, "", std::move(address_or_error.value()), nullptr, nullptr, 1, endpoints.locality(), endpoint.endpoint().health_check_config(), 0, @@ -560,7 +560,7 @@ void HdsCluster::initHealthchecks() { for (auto& health_check : cluster_.health_checks()) { auto health_checker_or_error = Upstream::HealthCheckerFactory::create(health_check, *this, server_context_); - THROW_IF_STATUS_NOT_OK(health_checker_or_error, throw); + THROW_IF_NOT_OK_REF(health_checker_or_error.status()); auto health_checker = health_checker_or_error.value(); health_checkers_.push_back(health_checker); diff --git a/source/common/upstream/outlier_detection_impl.h b/source/common/upstream/outlier_detection_impl.h index bf74a3d6b8c1..4eea999121a5 100644 --- a/source/common/upstream/outlier_detection_impl.h +++ b/source/common/upstream/outlier_detection_impl.h @@ -498,7 +498,7 @@ class EventLoggerImpl : public EventLogger { : time_source_(time_source) { auto file_or_error = log_manager.createAccessLog( Filesystem::FilePathAndType{Filesystem::DestinationType::File, file_name}); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); file_ = file_or_error.value(); } diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index b75c0898e622..805ceb849c70 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -2546,7 +2546,7 @@ Network::Address::InstanceConstSharedPtr resolveHealthCheckAddress( const auto& port_value = health_check_config.port_value(); if (health_check_config.has_address()) { auto address_or_error = Network::Address::resolveProtoAddress(health_check_config.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); auto address = address_or_error.value(); health_check_address = port_value == 0 ? address : Network::Utility::getAddressWithPort(*address, port_value); diff --git a/source/extensions/access_loggers/common/file_access_log_impl.cc b/source/extensions/access_loggers/common/file_access_log_impl.cc index 4ec65df5a0fa..fa7b85554190 100644 --- a/source/extensions/access_loggers/common/file_access_log_impl.cc +++ b/source/extensions/access_loggers/common/file_access_log_impl.cc @@ -10,7 +10,7 @@ FileAccessLog::FileAccessLog(const Filesystem::FilePathAndType& access_log_file_ AccessLog::AccessLogManager& log_manager) : ImplBase(std::move(filter)), formatter_(std::move(formatter)) { auto file_or_error = log_manager.createAccessLog(access_log_file_info); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); log_file_ = file_or_error.value(); } diff --git a/source/extensions/access_loggers/grpc/grpc_access_log_impl.cc b/source/extensions/access_loggers/grpc/grpc_access_log_impl.cc index b1838fe56f9a..790c000aa24a 100644 --- a/source/extensions/access_loggers/grpc/grpc_access_log_impl.cc +++ b/source/extensions/access_loggers/grpc/grpc_access_log_impl.cc @@ -63,7 +63,7 @@ GrpcAccessLoggerImpl::SharedPtr GrpcAccessLoggerCacheImpl::createLogger( // the main thread if necessary. auto factory_or_error = async_client_manager_.factoryForGrpcService(config.grpc_service(), scope_, true); - THROW_IF_STATUS_NOT_OK(factory_or_error, throw); + THROW_IF_NOT_OK_REF(factory_or_error.status()); return std::make_shared( factory_or_error.value()->createUncachedRawAsyncClient(), config, dispatcher, local_info_, scope_); diff --git a/source/extensions/access_loggers/open_telemetry/grpc_access_log_impl.cc b/source/extensions/access_loggers/open_telemetry/grpc_access_log_impl.cc index d6100a807b60..c180f28aa564 100644 --- a/source/extensions/access_loggers/open_telemetry/grpc_access_log_impl.cc +++ b/source/extensions/access_loggers/open_telemetry/grpc_access_log_impl.cc @@ -116,7 +116,7 @@ GrpcAccessLoggerImpl::SharedPtr GrpcAccessLoggerCacheImpl::createLogger( // the main thread if necessary to ensure it does not throw here. auto factory_or_error = async_client_manager_.factoryForGrpcService( config.common_config().grpc_service(), scope_, true); - THROW_IF_STATUS_NOT_OK(factory_or_error, throw); + THROW_IF_NOT_OK_REF(factory_or_error.status()); auto client = factory_or_error.value()->createUncachedRawAsyncClient(); return std::make_shared(std::move(client), config, dispatcher, local_info_, scope_); diff --git a/source/extensions/common/wasm/remote_async_datasource.cc b/source/extensions/common/wasm/remote_async_datasource.cc index 4ed28651c564..b3e8989e7a9a 100644 --- a/source/extensions/common/wasm/remote_async_datasource.cc +++ b/source/extensions/common/wasm/remote_async_datasource.cc @@ -32,7 +32,7 @@ RemoteAsyncDataProvider::RemoteAsyncDataProvider( auto strategy_or_error = Config::Utility::prepareJitteredExponentialBackOffStrategy( source, random, RetryInitialDelayMilliseconds, RetryMaxDelayMilliseconds); - THROW_IF_STATUS_NOT_OK(strategy_or_error, throw); + THROW_IF_NOT_OK_REF(strategy_or_error.status()); backoff_strategy_ = std::move(strategy_or_error.value()); retry_timer_ = dispatcher.createTimer([this]() -> void { start(); }); diff --git a/source/extensions/compression/zstd/common/dictionary_manager.h b/source/extensions/compression/zstd/common/dictionary_manager.h index 85d161c73559..99be8fc15fff 100644 --- a/source/extensions/compression/zstd/common/dictionary_manager.h +++ b/source/extensions/compression/zstd/common/dictionary_manager.h @@ -94,7 +94,7 @@ template class void onDictionaryUpdate(unsigned origin_id, const std::string& filename) { auto file_or_error = api_.fileSystem().fileReadToEnd(filename); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); const auto data = file_or_error.value(); if (!data.empty()) { auto dictionary = DictionarySharedPtr(builder_(data.data(), data.length())); diff --git a/source/extensions/config_subscription/grpc/grpc_collection_subscription_factory.cc b/source/extensions/config_subscription/grpc/grpc_collection_subscription_factory.cc index 9468f1d32c2e..fb2b82033b7a 100644 --- a/source/extensions/config_subscription/grpc/grpc_collection_subscription_factory.cc +++ b/source/extensions/config_subscription/grpc/grpc_collection_subscription_factory.cc @@ -20,15 +20,15 @@ SubscriptionPtr DeltaGrpcCollectionConfigSubscriptionFactory::create( auto strategy_or_error = Utility::prepareJitteredExponentialBackOffStrategy( api_config_source, data.api_.randomGenerator(), SubscriptionFactory::RetryInitialDelayMs, SubscriptionFactory::RetryMaxDelayMs); - THROW_IF_STATUS_NOT_OK(strategy_or_error, throw); + THROW_IF_NOT_OK_REF(strategy_or_error.status()); JitteredExponentialBackOffStrategyPtr backoff_strategy = std::move(strategy_or_error.value()); auto factory_primary_or_error = Config::Utility::factoryForGrpcApiConfigSource( data.cm_.grpcAsyncClientManager(), api_config_source, data.scope_, true, 0); - THROW_IF_STATUS_NOT_OK(factory_primary_or_error, throw); + THROW_IF_NOT_OK_REF(factory_primary_or_error.status()); absl::StatusOr rate_limit_settings_or_error = Utility::parseRateLimitSettings(api_config_source); - THROW_IF_STATUS_NOT_OK(rate_limit_settings_or_error, throw); + THROW_IF_NOT_OK_REF(rate_limit_settings_or_error.status()); GrpcMuxContext grpc_mux_context{ factory_primary_or_error.value()->createUncachedRawAsyncClient(), /*failover_async_client_=*/nullptr, diff --git a/source/extensions/config_subscription/grpc/grpc_mux_impl.cc b/source/extensions/config_subscription/grpc/grpc_mux_impl.cc index ba038b140955..4317cdca1a2c 100644 --- a/source/extensions/config_subscription/grpc/grpc_mux_impl.cc +++ b/source/extensions/config_subscription/grpc/grpc_mux_impl.cc @@ -48,7 +48,7 @@ bool isXdsTpWildcard(const std::string& resource_name) { std::string convertToWildcard(const std::string& resource_name) { ASSERT(XdsResourceIdentifier::hasXdsTpScheme(resource_name)); auto resource_or_error = XdsResourceIdentifier::decodeUrn(resource_name); - THROW_IF_STATUS_NOT_OK(resource_or_error, throw); + THROW_IF_NOT_OK_REF(resource_or_error.status()); xds::core::v3::ResourceName xdstp_resource = resource_or_error.value(); const auto pos = xdstp_resource.id().find_last_of('/'); xdstp_resource.set_id( @@ -445,7 +445,7 @@ void GrpcMuxImpl::processDiscoveryResources(const std::vectorname())) { // Sort the context params of an xdstp resource, so we can compare them easily. auto resource_or_error = XdsResourceIdentifier::decodeUrn(resource->name()); - THROW_IF_STATUS_NOT_OK(resource_or_error, throw); + THROW_IF_NOT_OK_REF(resource_or_error.status()); xds::core::v3::ResourceName xdstp_resource = resource_or_error.value(); XdsResourceIdentifier::EncodeOptions options; options.sort_context_params_ = true; @@ -631,7 +631,7 @@ class GrpcMuxFactory : public MuxFactory { XdsResourcesDelegateOptRef xds_resources_delegate, bool use_eds_resources_cache) override { absl::StatusOr rate_limit_settings_or_error = Utility::parseRateLimitSettings(ads_config); - THROW_IF_STATUS_NOT_OK(rate_limit_settings_or_error, throw); + THROW_IF_NOT_OK_REF(rate_limit_settings_or_error.status()); GrpcMuxContext grpc_mux_context{ /*async_client_=*/std::move(async_client), /*failover_async_client_=*/std::move(failover_async_client), diff --git a/source/extensions/config_subscription/grpc/grpc_mux_impl.h b/source/extensions/config_subscription/grpc/grpc_mux_impl.h index c6d6df79dc6d..885942f3fb2a 100644 --- a/source/extensions/config_subscription/grpc/grpc_mux_impl.h +++ b/source/extensions/config_subscription/grpc/grpc_mux_impl.h @@ -169,7 +169,7 @@ class GrpcMuxImpl : public GrpcMux, [this](const std::string& resource_name) -> std::string { if (XdsResourceIdentifier::hasXdsTpScheme(resource_name)) { auto xdstp_resource_or_error = XdsResourceIdentifier::decodeUrn(resource_name); - THROW_IF_STATUS_NOT_OK(xdstp_resource_or_error, throw); + THROW_IF_NOT_OK_REF(xdstp_resource_or_error.status()); auto xdstp_resource = xdstp_resource_or_error.value(); if (subscription_options_.add_xdstp_node_context_params_) { const auto context = XdsContextParams::encodeResource( diff --git a/source/extensions/config_subscription/grpc/grpc_subscription_factory.cc b/source/extensions/config_subscription/grpc/grpc_subscription_factory.cc index da174b438ce7..a93fb9b4544a 100644 --- a/source/extensions/config_subscription/grpc/grpc_subscription_factory.cc +++ b/source/extensions/config_subscription/grpc/grpc_subscription_factory.cc @@ -23,15 +23,15 @@ GrpcConfigSubscriptionFactory::create(ConfigSubscriptionFactory::SubscriptionDat auto strategy_or_error = Utility::prepareJitteredExponentialBackOffStrategy( api_config_source, data.api_.randomGenerator(), SubscriptionFactory::RetryInitialDelayMs, SubscriptionFactory::RetryMaxDelayMs); - THROW_IF_STATUS_NOT_OK(strategy_or_error, throw); + THROW_IF_NOT_OK_REF(strategy_or_error.status()); JitteredExponentialBackOffStrategyPtr backoff_strategy = std::move(strategy_or_error.value()); auto factory_primary_or_error = Utility::factoryForGrpcApiConfigSource( data.cm_.grpcAsyncClientManager(), api_config_source, data.scope_, true, 0); - THROW_IF_STATUS_NOT_OK(factory_primary_or_error, throw); + THROW_IF_NOT_OK_REF(factory_primary_or_error.status()); absl::StatusOr rate_limit_settings_or_error = Utility::parseRateLimitSettings(api_config_source); - THROW_IF_STATUS_NOT_OK(rate_limit_settings_or_error, throw); + THROW_IF_NOT_OK_REF(rate_limit_settings_or_error.status()); GrpcMuxContext grpc_mux_context{ /*async_client_=*/factory_primary_or_error.value()->createUncachedRawAsyncClient(), /*failover_async_client_=*/nullptr, // Failover is only supported for ADS. @@ -72,15 +72,15 @@ DeltaGrpcConfigSubscriptionFactory::create(ConfigSubscriptionFactory::Subscripti auto strategy_or_error = Utility::prepareJitteredExponentialBackOffStrategy( api_config_source, data.api_.randomGenerator(), SubscriptionFactory::RetryInitialDelayMs, SubscriptionFactory::RetryMaxDelayMs); - THROW_IF_STATUS_NOT_OK(strategy_or_error, throw); + THROW_IF_NOT_OK_REF(strategy_or_error.status()); JitteredExponentialBackOffStrategyPtr backoff_strategy = std::move(strategy_or_error.value()); auto factory_primary_or_error = Utility::factoryForGrpcApiConfigSource( data.cm_.grpcAsyncClientManager(), api_config_source, data.scope_, true, 0); - THROW_IF_STATUS_NOT_OK(factory_primary_or_error, throw); + THROW_IF_NOT_OK_REF(factory_primary_or_error.status()); absl::StatusOr rate_limit_settings_or_error = Utility::parseRateLimitSettings(api_config_source); - THROW_IF_STATUS_NOT_OK(rate_limit_settings_or_error, throw); + THROW_IF_NOT_OK_REF(rate_limit_settings_or_error.status()); GrpcMuxContext grpc_mux_context{ /*async_client_=*/factory_primary_or_error.value()->createUncachedRawAsyncClient(), /*failover_async_client_=*/nullptr, // Failover is only supported for ADS. diff --git a/source/extensions/config_subscription/grpc/new_grpc_mux_impl.cc b/source/extensions/config_subscription/grpc/new_grpc_mux_impl.cc index 15efac2b82d5..1a47a63572c7 100644 --- a/source/extensions/config_subscription/grpc/new_grpc_mux_impl.cc +++ b/source/extensions/config_subscription/grpc/new_grpc_mux_impl.cc @@ -262,7 +262,7 @@ void NewGrpcMuxImpl::updateWatch(const std::string& type_url, Watch* watch, for (const auto& resource : resources) { if (XdsResourceIdentifier::hasXdsTpScheme(resource)) { auto xdstp_resource_or_error = XdsResourceIdentifier::decodeUrn(resource); - THROW_IF_STATUS_NOT_OK(xdstp_resource_or_error, throw); + THROW_IF_NOT_OK_REF(xdstp_resource_or_error.status()); auto xdstp_resource = xdstp_resource_or_error.value(); if (options.add_xdstp_node_context_params_) { const auto context = XdsContextParams::encodeResource( @@ -420,7 +420,7 @@ class NewGrpcMuxFactory : public MuxFactory { OptRef, bool use_eds_resources_cache) override { absl::StatusOr rate_limit_settings_or_error = Utility::parseRateLimitSettings(ads_config); - THROW_IF_STATUS_NOT_OK(rate_limit_settings_or_error, throw); + THROW_IF_NOT_OK_REF(rate_limit_settings_or_error.status()); GrpcMuxContext grpc_mux_context{ /*async_client_=*/std::move(async_client), /*failover_async_client_=*/std::move(failover_async_client), diff --git a/source/extensions/config_subscription/grpc/watch_map.cc b/source/extensions/config_subscription/grpc/watch_map.cc index 88bbf01125de..5b40d625fadb 100644 --- a/source/extensions/config_subscription/grpc/watch_map.cc +++ b/source/extensions/config_subscription/grpc/watch_map.cc @@ -96,7 +96,7 @@ absl::flat_hash_set WatchMap::watchesInterestedIn(const std::string& res // operations, but this implementation provides a reference for later optimization while we // adopt xdstp://. auto resource_or_error = XdsResourceIdentifier::decodeUrn(resource_name); - THROW_IF_STATUS_NOT_OK(resource_or_error, throw); + THROW_IF_NOT_OK_REF(resource_or_error.status()); xdstp_resource = resource_or_error.value(); } auto watches_interested = watch_interest_.find( diff --git a/source/extensions/config_subscription/grpc/xds_mux/grpc_mux_impl.cc b/source/extensions/config_subscription/grpc/xds_mux/grpc_mux_impl.cc index 9269df1d37df..273fb0081040 100644 --- a/source/extensions/config_subscription/grpc/xds_mux/grpc_mux_impl.cc +++ b/source/extensions/config_subscription/grpc/xds_mux/grpc_mux_impl.cc @@ -167,7 +167,7 @@ void GrpcMuxImpl::updateWatch(const std::string& type_url, Watch* for (const auto& resource : resources) { if (XdsResourceIdentifier::hasXdsTpScheme(resource)) { auto xdstp_resource_or_error = XdsResourceIdentifier::decodeUrn(resource); - THROW_IF_STATUS_NOT_OK(xdstp_resource_or_error, throw); + THROW_IF_NOT_OK_REF(xdstp_resource_or_error.status()); auto xdstp_resource = xdstp_resource_or_error.value(); if (options.add_xdstp_node_context_params_) { const auto context = XdsContextParams::encodeResource( @@ -456,7 +456,7 @@ class DeltaGrpcMuxFactory : public MuxFactory { XdsResourcesDelegateOptRef, bool use_eds_resources_cache) override { absl::StatusOr rate_limit_settings_or_error = Utility::parseRateLimitSettings(ads_config); - THROW_IF_STATUS_NOT_OK(rate_limit_settings_or_error, throw); + THROW_IF_NOT_OK_REF(rate_limit_settings_or_error.status()); GrpcMuxContext grpc_mux_context{ /*async_client_=*/std::move(async_client), /*failover_async_client=*/std::move(failover_async_client), @@ -495,7 +495,7 @@ class SotwGrpcMuxFactory : public MuxFactory { XdsResourcesDelegateOptRef, bool use_eds_resources_cache) override { absl::StatusOr rate_limit_settings_or_error = Utility::parseRateLimitSettings(ads_config); - THROW_IF_STATUS_NOT_OK(rate_limit_settings_or_error, throw); + THROW_IF_NOT_OK_REF(rate_limit_settings_or_error.status()); GrpcMuxContext grpc_mux_context{ /*async_client_=*/std::move(async_client), /*failover_async_client_=*/std::move(failover_async_client), diff --git a/source/extensions/filters/common/ratelimit/ratelimit_impl.cc b/source/extensions/filters/common/ratelimit/ratelimit_impl.cc index a72fa1b81661..3350e132562a 100644 --- a/source/extensions/filters/common/ratelimit/ratelimit_impl.cc +++ b/source/extensions/filters/common/ratelimit/ratelimit_impl.cc @@ -132,7 +132,7 @@ ClientPtr rateLimitClient(Server::Configuration::FactoryContext& context, .clusterManager() .grpcAsyncClientManager() .getOrCreateRawAsyncClientWithHashKey(config_with_hash_key, context.scope(), true); - THROW_IF_STATUS_NOT_OK(client_or_error, throw); + THROW_IF_NOT_OK_REF(client_or_error.status()); return std::make_unique(client_or_error.value(), timeout); } diff --git a/source/extensions/filters/http/composite/action.cc b/source/extensions/filters/http/composite/action.cc index 27cfe9e6f28e..9d70c9c10671 100644 --- a/source/extensions/filters/http/composite/action.cc +++ b/source/extensions/filters/http/composite/action.cc @@ -115,7 +115,7 @@ Matcher::ActionFactoryCb ExecuteFilterActionFactory::createStaticActionFactoryCb if (context.factory_context_.has_value()) { auto callback_or_status = factory.createFilterFactoryFromProto( *message, context.stat_prefix_, context.factory_context_.value()); - THROW_IF_STATUS_NOT_OK(callback_or_status, throw); + THROW_IF_NOT_OK_REF(callback_or_status.status()); callback = callback_or_status.value(); } @@ -146,7 +146,7 @@ Matcher::ActionFactoryCb ExecuteFilterActionFactory::createStaticActionFactoryCb if (context.upstream_factory_context_.has_value()) { auto callback_or_status = factory.createFilterFactoryFromProto( *message, context.stat_prefix_, context.upstream_factory_context_.value()); - THROW_IF_STATUS_NOT_OK(callback_or_status, throw); + THROW_IF_NOT_OK_REF(callback_or_status.status()); callback = callback_or_status.value(); } diff --git a/source/extensions/filters/http/ext_authz/config.cc b/source/extensions/filters/http/ext_authz/config.cc index 949d3f4654db..bfdab7fe36f2 100644 --- a/source/extensions/filters/http/ext_authz/config.cc +++ b/source/extensions/filters/http/ext_authz/config.cc @@ -54,7 +54,7 @@ Http::FilterFactoryCb ExtAuthzFilterConfig::createFilterFactoryFromProtoWithServ .grpcAsyncClientManager() .getOrCreateRawAsyncClientWithHashKey( config_with_hash_key, server_context.scope(), true); - THROW_IF_STATUS_NOT_OK(client_or_error, throw); + THROW_IF_NOT_OK_REF(client_or_error.status()); auto client = std::make_unique( client_or_error.value(), std::chrono::milliseconds(timeout_ms)); callbacks.addStreamFilter(std::make_shared(filter_config, std::move(client))); diff --git a/source/extensions/filters/http/ext_proc/client_impl.cc b/source/extensions/filters/http/ext_proc/client_impl.cc index 8bfc80bc5908..fef44968dc5d 100644 --- a/source/extensions/filters/http/ext_proc/client_impl.cc +++ b/source/extensions/filters/http/ext_proc/client_impl.cc @@ -18,7 +18,7 @@ ExternalProcessorStreamPtr ExternalProcessorClientImpl::start( Http::StreamFilterSidestreamWatermarkCallbacks& sidestream_watermark_callbacks) { auto client_or_error = client_manager_.getOrCreateRawAsyncClientWithHashKey(config_with_hash_key, scope_, true); - THROW_IF_STATUS_NOT_OK(client_or_error, throw); + THROW_IF_NOT_OK_REF(client_or_error.status()); Grpc::AsyncClient grpcClient(client_or_error.value()); return ExternalProcessorStreamImpl::create(std::move(grpcClient), callbacks, options, sidestream_watermark_callbacks); diff --git a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc index 63be1f6fe24a..2ffc80e63720 100644 --- a/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc +++ b/source/extensions/filters/http/grpc_json_transcoder/json_transcoder_filter.cc @@ -124,7 +124,7 @@ JsonTranscoderConfig::JsonTranscoderConfig( case envoy::extensions::filters::http::grpc_json_transcoder::v3::GrpcJsonTranscoder:: DescriptorSetCase::kProtoDescriptor: { auto file_or_error = api.fileSystem().fileReadToEnd(proto_config.proto_descriptor()); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); if (!descriptor_set.ParseFromString(file_or_error.value())) { throw EnvoyException("transcoding_filter: Unable to parse proto descriptor"); } diff --git a/source/extensions/filters/http/rate_limit_quota/client_impl.cc b/source/extensions/filters/http/rate_limit_quota/client_impl.cc index 92390ea8a302..7d886a49e7b3 100644 --- a/source/extensions/filters/http/rate_limit_quota/client_impl.cc +++ b/source/extensions/filters/http/rate_limit_quota/client_impl.cc @@ -9,7 +9,7 @@ namespace RateLimitQuota { Grpc::RawAsyncClientSharedPtr getOrThrow(absl::StatusOr client_or_error) { - THROW_IF_STATUS_NOT_OK(client_or_error, throw); + THROW_IF_NOT_OK_REF(client_or_error.status()); return client_or_error.value(); } diff --git a/source/extensions/filters/network/ext_authz/config.cc b/source/extensions/filters/network/ext_authz/config.cc index b4d62365d02f..ab0560664863 100644 --- a/source/extensions/filters/network/ext_authz/config.cc +++ b/source/extensions/filters/network/ext_authz/config.cc @@ -34,7 +34,7 @@ Network::FilterFactoryCb ExtAuthzConfigFactory::createFilterFactoryFromProtoType .clusterManager() .grpcAsyncClientManager() .factoryForGrpcService(grpc_service, context.scope(), true); - THROW_IF_STATUS_NOT_OK(factory_or_error, throw); + THROW_IF_NOT_OK_REF(factory_or_error.status()); auto client = std::make_unique( factory_or_error.value()->createUncachedRawAsyncClient(), std::chrono::milliseconds(timeout_ms)); diff --git a/source/extensions/filters/network/mongo_proxy/proxy.cc b/source/extensions/filters/network/mongo_proxy/proxy.cc index 87f9b6a073d6..fd56c5caa8a7 100644 --- a/source/extensions/filters/network/mongo_proxy/proxy.cc +++ b/source/extensions/filters/network/mongo_proxy/proxy.cc @@ -39,7 +39,7 @@ AccessLog::AccessLog(const std::string& file_name, Envoy::AccessLog::AccessLogMa : time_source_(time_source) { auto file_or_error = log_manager.createAccessLog( Filesystem::FilePathAndType{Filesystem::DestinationType::File, file_name}); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); file_ = file_or_error.value(); } diff --git a/source/extensions/filters/network/redis_proxy/config.cc b/source/extensions/filters/network/redis_proxy/config.cc index ebae3bee724a..9e45c04a3d4f 100644 --- a/source/extensions/filters/network/redis_proxy/config.cc +++ b/source/extensions/filters/network/redis_proxy/config.cc @@ -111,7 +111,7 @@ Network::FilterFactoryCb RedisProxyFilterConfigFactory::createFilterFactoryFromP .clusterManager() .grpcAsyncClientManager() .factoryForGrpcService(grpc_service, context.scope(), true); - THROW_IF_STATUS_NOT_OK(auth_client_factory_or_error, throw); + THROW_IF_NOT_OK_REF(auth_client_factory_or_error.status()); auth_client = std::make_unique( auth_client_factory_or_error.value()->createUncachedRawAsyncClient(), diff --git a/source/extensions/filters/network/sni_dynamic_forward_proxy/proxy_filter.cc b/source/extensions/filters/network/sni_dynamic_forward_proxy/proxy_filter.cc index af3407c3d727..fd6f87d7d200 100644 --- a/source/extensions/filters/network/sni_dynamic_forward_proxy/proxy_filter.cc +++ b/source/extensions/filters/network/sni_dynamic_forward_proxy/proxy_filter.cc @@ -22,7 +22,7 @@ ProxyFilterConfig::ProxyFilterConfig( : port_(static_cast(proto_config.port_value())), dns_cache_manager_(cache_manager_factory.get()) { auto cache_or_error = dns_cache_manager_->getCache(proto_config.dns_cache_config()); - THROW_IF_STATUS_NOT_OK(cache_or_error, throw); + THROW_IF_NOT_OK_REF(cache_or_error.status()); dns_cache_ = std::move(cache_or_error.value()); } diff --git a/source/extensions/filters/udp/udp_proxy/session_filters/dynamic_forward_proxy/proxy_filter.cc b/source/extensions/filters/udp/udp_proxy/session_filters/dynamic_forward_proxy/proxy_filter.cc index 00cd4298aa4a..abfd730e61a4 100644 --- a/source/extensions/filters/udp/udp_proxy/session_filters/dynamic_forward_proxy/proxy_filter.cc +++ b/source/extensions/filters/udp/udp_proxy/session_filters/dynamic_forward_proxy/proxy_filter.cc @@ -36,7 +36,7 @@ ProxyFilterConfig::ProxyFilterConfig( DefaultMaxBufferedBytes) : DefaultMaxBufferedBytes) { auto cache_or_error = dns_cache_manager_->getCache(config.dns_cache_config()); - THROW_IF_STATUS_NOT_OK(cache_or_error, throw); + THROW_IF_NOT_OK_REF(cache_or_error.status()); dns_cache_ = std::move(cache_or_error.value()); } diff --git a/source/extensions/health_check/event_sinks/file/file_sink_impl.h b/source/extensions/health_check/event_sinks/file/file_sink_impl.h index b2e51da4f778..712e0fe2964f 100644 --- a/source/extensions/health_check/event_sinks/file/file_sink_impl.h +++ b/source/extensions/health_check/event_sinks/file/file_sink_impl.h @@ -16,7 +16,7 @@ class HealthCheckEventFileSink : public HealthCheckEventSink { AccessLog::AccessLogManager& log_manager) { auto file_or_error = log_manager.createAccessLog( Filesystem::FilePathAndType{Filesystem::DestinationType::File, config.event_log_path()}); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); file_ = file_or_error.value(); } diff --git a/source/extensions/health_checkers/http/health_checker_impl.cc b/source/extensions/health_checkers/http/health_checker_impl.cc index 88c02582abdd..bcbed8bd861e 100644 --- a/source/extensions/health_checkers/http/health_checker_impl.cc +++ b/source/extensions/health_checkers/http/health_checker_impl.cc @@ -76,7 +76,7 @@ HttpHealthCheckerImpl::HttpHealthCheckerImpl( // TODO(boteng): introduce additional validation for the authority and path headers // based on the default UHV when it is available. auto bytes_or_error = PayloadMatcher::loadProtoBytes(config.http_health_check().receive()); - THROW_IF_STATUS_NOT_OK(bytes_or_error, throw); + THROW_IF_NOT_OK_REF(bytes_or_error.status()); receive_bytes_ = bytes_or_error.value(); if (config.http_health_check().has_service_name_matcher()) { service_name_matcher_.emplace(config.http_health_check().service_name_matcher(), diff --git a/source/extensions/health_checkers/tcp/health_checker_impl.cc b/source/extensions/health_checkers/tcp/health_checker_impl.cc index 585df883a571..d1c75e45531b 100644 --- a/source/extensions/health_checkers/tcp/health_checker_impl.cc +++ b/source/extensions/health_checkers/tcp/health_checker_impl.cc @@ -55,7 +55,7 @@ TcpHealthCheckerImpl::TcpHealthCheckerImpl(const Cluster& cluster, send_repeated.Add()->CopyFrom(config.tcp_health_check().send()); } auto bytes_or_error = PayloadMatcher::loadProtoBytes(send_repeated); - THROW_IF_STATUS_NOT_OK(bytes_or_error, throw); + THROW_IF_NOT_OK_REF(bytes_or_error.status()); return bytes_or_error.value(); }()), proxy_protocol_config_(config.tcp_health_check().has_proxy_protocol_config() @@ -63,7 +63,7 @@ TcpHealthCheckerImpl::TcpHealthCheckerImpl(const Cluster& cluster, config.tcp_health_check().proxy_protocol_config()) : nullptr) { auto bytes_or_error = PayloadMatcher::loadProtoBytes(config.tcp_health_check().receive()); - THROW_IF_STATUS_NOT_OK(bytes_or_error, throw); + THROW_IF_NOT_OK_REF(bytes_or_error.status()); receive_bytes_ = bytes_or_error.value(); } diff --git a/source/extensions/key_value/file_based/config.cc b/source/extensions/key_value/file_based/config.cc index 195f07f6c0ed..0822c6a71c2e 100644 --- a/source/extensions/key_value/file_based/config.cc +++ b/source/extensions/key_value/file_based/config.cc @@ -17,7 +17,7 @@ FileBasedKeyValueStore::FileBasedKeyValueStore(Event::Dispatcher& dispatcher, return; } auto file_or_error = file_system_.fileReadToEnd(filename_); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); const std::string contents = file_or_error.value(); if (!parseContents(contents)) { ENVOY_LOG(warn, "Failed to parse key value store file {}", filename); diff --git a/source/extensions/resource_monitors/injected_resource/injected_resource_monitor.cc b/source/extensions/resource_monitors/injected_resource/injected_resource_monitor.cc index 8b02e398431d..589652b7e77c 100644 --- a/source/extensions/resource_monitors/injected_resource/injected_resource_monitor.cc +++ b/source/extensions/resource_monitors/injected_resource/injected_resource_monitor.cc @@ -31,7 +31,7 @@ void InjectedResourceMonitor::updateResourceUsage(Server::ResourceUpdateCallback file_changed_ = false; TRY_ASSERT_MAIN_THREAD { auto file_or_error = api_.fileSystem().fileReadToEnd(filename_); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); const std::string contents = file_or_error.value(); double pressure; if (absl::SimpleAtod(contents, &pressure)) { diff --git a/source/extensions/stat_sinks/common/statsd/statsd.cc b/source/extensions/stat_sinks/common/statsd/statsd.cc index 25872589ca74..48f76c620821 100644 --- a/source/extensions/stat_sinks/common/statsd/statsd.cc +++ b/source/extensions/stat_sinks/common/statsd/statsd.cc @@ -197,7 +197,7 @@ TcpStatsdSink::TcpStatsdSink(const LocalInfo::LocalInfo& local_info, THROW_IF_NOT_OK(Config::Utility::checkLocalInfo("tcp statsd", local_info)); const auto cluster_or_error = Config::Utility::checkCluster("tcp statsd", cluster_name, cluster_manager); - THROW_IF_STATUS_NOT_OK(cluster_or_error, throw); + THROW_IF_NOT_OK_REF(cluster_or_error.status()); const auto cluster = cluster_or_error.value(); cluster_info_ = cluster->get().info(); tls_->set([this](Event::Dispatcher& dispatcher) -> ThreadLocal::ThreadLocalObjectSharedPtr { diff --git a/source/extensions/stat_sinks/dog_statsd/config.cc b/source/extensions/stat_sinks/dog_statsd/config.cc index 78c39f20d914..a3fd1941cbe1 100644 --- a/source/extensions/stat_sinks/dog_statsd/config.cc +++ b/source/extensions/stat_sinks/dog_statsd/config.cc @@ -23,7 +23,7 @@ DogStatsdSinkFactory::createStatsSink(const Protobuf::Message& config, MessageUtil::downcastAndValidate( config, server.messageValidationContext().staticValidationVisitor()); auto address_or_error = Network::Address::resolveProtoAddress(sink_config.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); Network::Address::InstanceConstSharedPtr address = address_or_error.value(); ENVOY_LOG(debug, "dog_statsd UDP ip address: {}", address->asString()); absl::optional max_bytes; diff --git a/source/extensions/stat_sinks/graphite_statsd/config.cc b/source/extensions/stat_sinks/graphite_statsd/config.cc index 93322442900d..1afd0a8846c3 100644 --- a/source/extensions/stat_sinks/graphite_statsd/config.cc +++ b/source/extensions/stat_sinks/graphite_statsd/config.cc @@ -26,7 +26,7 @@ GraphiteStatsdSinkFactory::createStatsSink(const Protobuf::Message& config, case envoy::extensions::stat_sinks::graphite_statsd::v3::GraphiteStatsdSink::StatsdSpecifierCase:: kAddress: { auto address_or_error = Network::Address::resolveProtoAddress(statsd_sink.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); Network::Address::InstanceConstSharedPtr address = address_or_error.value(); ENVOY_LOG(debug, "statsd UDP ip address: {}", address->asString()); absl::optional max_bytes; diff --git a/source/extensions/stat_sinks/metrics_service/config.cc b/source/extensions/stat_sinks/metrics_service/config.cc index 791f81508f31..1463b8e943af 100644 --- a/source/extensions/stat_sinks/metrics_service/config.cc +++ b/source/extensions/stat_sinks/metrics_service/config.cc @@ -30,7 +30,7 @@ MetricsServiceSinkFactory::createStatsSink(const Protobuf::Message& config, auto client_or_error = server.clusterManager().grpcAsyncClientManager().getOrCreateRawAsyncClient( grpc_service, server.scope(), false); - THROW_IF_STATUS_NOT_OK(client_or_error, throw); + THROW_IF_NOT_OK_REF(client_or_error.status()); std::shared_ptr> grpc_metrics_streamer = diff --git a/source/extensions/stat_sinks/open_telemetry/config.cc b/source/extensions/stat_sinks/open_telemetry/config.cc index 2dc66d339aef..4b7e806fd018 100644 --- a/source/extensions/stat_sinks/open_telemetry/config.cc +++ b/source/extensions/stat_sinks/open_telemetry/config.cc @@ -29,7 +29,7 @@ OpenTelemetrySinkFactory::createStatsSink(const Protobuf::Message& config, auto client_or_error = server.clusterManager().grpcAsyncClientManager().getOrCreateRawAsyncClient( grpc_service, server.scope(), false); - THROW_IF_STATUS_NOT_OK(client_or_error, throw); + THROW_IF_NOT_OK_REF(client_or_error.status()); std::shared_ptr grpc_metrics_exporter = std::make_shared(otlp_options, client_or_error.value()); diff --git a/source/extensions/stat_sinks/statsd/config.cc b/source/extensions/stat_sinks/statsd/config.cc index ae76707892a0..47b26bbc6834 100644 --- a/source/extensions/stat_sinks/statsd/config.cc +++ b/source/extensions/stat_sinks/statsd/config.cc @@ -24,7 +24,7 @@ StatsdSinkFactory::createStatsSink(const Protobuf::Message& config, switch (statsd_sink.statsd_specifier_case()) { case envoy::config::metrics::v3::StatsdSink::StatsdSpecifierCase::kAddress: { auto address_or_error = Network::Address::resolveProtoAddress(statsd_sink.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); Network::Address::InstanceConstSharedPtr address = address_or_error.value(); ENVOY_LOG(debug, "statsd UDP ip address: {}", address->asString()); return std::make_unique(server.threadLocal(), std::move(address), diff --git a/source/extensions/tracers/datadog/tracer.cc b/source/extensions/tracers/datadog/tracer.cc index 280647595558..ae5b510f9c0f 100644 --- a/source/extensions/tracers/datadog/tracer.cc +++ b/source/extensions/tracers/datadog/tracer.cc @@ -63,9 +63,9 @@ Tracer::Tracer(const std::string& collector_cluster, const std::string& collecto thread_local_slot_( ThreadLocal::TypedSlot::makeUnique(thread_local_slot_allocator)) { const bool allow_added_via_api = true; - THROW_IF_STATUS_NOT_OK(Config::Utility::checkCluster("envoy.tracers.datadog", collector_cluster, - cluster_manager, allow_added_via_api), - throw); + THROW_IF_NOT_OK_REF(Config::Utility::checkCluster("envoy.tracers.datadog", collector_cluster, + cluster_manager, allow_added_via_api) + .status()); thread_local_slot_->set([&logger = ENVOY_LOGGER(), collector_cluster, collector_reference_host, config, &tracer_stats = tracer_stats_, &cluster_manager, diff --git a/source/extensions/tracers/opentelemetry/opentelemetry_tracer_impl.cc b/source/extensions/tracers/opentelemetry/opentelemetry_tracer_impl.cc index d3fe8624c65d..5d9a9ed7b62e 100644 --- a/source/extensions/tracers/opentelemetry/opentelemetry_tracer_impl.cc +++ b/source/extensions/tracers/opentelemetry/opentelemetry_tracer_impl.cc @@ -92,7 +92,7 @@ Driver::Driver(const envoy::config::trace::v3::OpenTelemetryConfig& opentelemetr auto factory_or_error = factory_context.clusterManager().grpcAsyncClientManager().factoryForGrpcService( opentelemetry_config.grpc_service(), factory_context.scope(), true); - THROW_IF_STATUS_NOT_OK(factory_or_error, throw); + THROW_IF_NOT_OK_REF(factory_or_error.status()); Grpc::AsyncClientFactoryPtr&& factory = std::move(factory_or_error.value()); const Grpc::RawAsyncClientSharedPtr& async_client_shared_ptr = factory->createUncachedRawAsyncClient(); diff --git a/source/extensions/tracers/skywalking/skywalking_tracer_impl.cc b/source/extensions/tracers/skywalking/skywalking_tracer_impl.cc index d312b83f707d..5e73f32fe942 100644 --- a/source/extensions/tracers/skywalking/skywalking_tracer_impl.cc +++ b/source/extensions/tracers/skywalking/skywalking_tracer_impl.cc @@ -38,7 +38,7 @@ Driver::Driver(const envoy::config::trace::v3::SkyWalkingConfig& proto_config, auto factory_or_error = factory_context.clusterManager().grpcAsyncClientManager().factoryForGrpcService( proto_config.grpc_service(), factory_context.scope(), true); - THROW_IF_STATUS_NOT_OK(factory_or_error, throw); + THROW_IF_NOT_OK_REF(factory_or_error.status()); TracerPtr tracer = std::make_unique(std::make_unique( std::move(factory_or_error.value()), dispatcher, factory_context.api().randomGenerator(), tracing_stats_, config_.delayed_buffer_size(), config_.token())); diff --git a/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc b/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc index 2fda60aca87d..88b0f5d57325 100644 --- a/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc +++ b/source/extensions/tracers/zipkin/zipkin_tracer_impl.cc @@ -77,10 +77,10 @@ Driver::Driver(const envoy::config::trace::v3::ZipkinConfig& zipkin_config, POOL_COUNTER_PREFIX(scope, "tracing.zipkin."))}, tls_(tls.allocateSlot()), runtime_(runtime), local_info_(local_info), time_source_(time_source) { - THROW_IF_STATUS_NOT_OK(Config::Utility::checkCluster("envoy.tracers.zipkin", - zipkin_config.collector_cluster(), cm_, - /* allow_added_via_api */ true), - throw); + THROW_IF_NOT_OK_REF(Config::Utility::checkCluster("envoy.tracers.zipkin", + zipkin_config.collector_cluster(), cm_, + /* allow_added_via_api */ true) + .status()); cluster_ = zipkin_config.collector_cluster(); hostname_ = !zipkin_config.collector_hostname().empty() ? zipkin_config.collector_hostname() : zipkin_config.collector_cluster(); diff --git a/source/server/config_validation/server.cc b/source/server/config_validation/server.cc index b19238c8226b..ac23e376900d 100644 --- a/source/server/config_validation/server.cc +++ b/source/server/config_validation/server.cc @@ -102,7 +102,7 @@ void ValidationInstance::initialize(const Options& options, auto producer_or_error = Stats::TagProducerImpl::createTagProducer(bootstrap_.stats_config(), options_.statsTags()); - THROW_IF_STATUS_NOT_OK(producer_or_error, throw); + THROW_IF_NOT_OK_REF(producer_or_error.status()); if (!bootstrap_.node().user_agent_build_version().has_version()) { *bootstrap_.mutable_node()->mutable_user_agent_build_version() = VersionInfo::buildVersion(); } diff --git a/source/server/server.cc b/source/server/server.cc index a8fbc195549e..6b3418bb84e6 100644 --- a/source/server/server.cc +++ b/source/server/server.cc @@ -828,7 +828,7 @@ void InstanceBase::onRuntimeReady() { // HDS does not support xDS-Failover. auto factory_or_error = Config::Utility::factoryForGrpcApiConfigSource( *async_client_manager_, hds_config, *stats_store_.rootScope(), false, 0); - THROW_IF_STATUS_NOT_OK(factory_or_error, throw); + THROW_IF_NOT_OK_REF(factory_or_error.status()); hds_delegate_ = std::make_unique( serverFactoryContext(), *stats_store_.rootScope(), factory_or_error.value()->createUncachedRawAsyncClient(), stats_store_, diff --git a/test/common/http/async_client_impl_test.cc b/test/common/http/async_client_impl_test.cc index dab5f185d3dc..0885eb927d3a 100644 --- a/test/common/http/async_client_impl_test.cc +++ b/test/common/http/async_client_impl_test.cc @@ -2221,7 +2221,7 @@ class AsyncClientImplUnitTest : public AsyncClientImplTest { auto policy_or_error = Router::RetryPolicyImpl::create(proto_policy, ProtobufMessage::getNullValidationVisitor(), factory_context, client_.factory_context_); - THROW_IF_STATUS_NOT_OK(policy_or_error, throw); + THROW_IF_NOT_OK_REF(policy_or_error.status()); retry_policy_ = std::move(policy_or_error.value()); EXPECT_TRUE(retry_policy_.get()); @@ -2259,7 +2259,7 @@ class AsyncClientImplUnitTest : public AsyncClientImplTest { auto policy_or_error = Router::RetryPolicyImpl::create(proto_policy, ProtobufMessage::getNullValidationVisitor(), factory_context, client_.factory_context_); - THROW_IF_STATUS_NOT_OK(policy_or_error, throw); + THROW_IF_NOT_OK_REF(policy_or_error.status()); retry_policy_ = std::move(policy_or_error.value()); EXPECT_TRUE(retry_policy_.get()); diff --git a/test/common/router/header_formatter_test.cc b/test/common/router/header_formatter_test.cc index 324492f2e689..0e27b66d6939 100644 --- a/test/common/router/header_formatter_test.cc +++ b/test/common/router/header_formatter_test.cc @@ -217,7 +217,7 @@ TEST(HeaderParserTest, TestParse) { if (test_case.expected_exception_) { EXPECT_FALSE(test_case.expected_output_); - EXPECT_THROW(THROW_IF_STATUS_NOT_OK(HeaderParser::configure(to_add), throw), EnvoyException); + EXPECT_THROW(THROW_IF_NOT_OK_REF(HeaderParser::configure(to_add).status()), EnvoyException); continue; } diff --git a/test/common/upstream/upstream_impl_test.cc b/test/common/upstream/upstream_impl_test.cc index b7c23e96f2ae..3ef5cef66f7f 100644 --- a/test/common/upstream/upstream_impl_test.cc +++ b/test/common/upstream/upstream_impl_test.cc @@ -75,7 +75,7 @@ class UpstreamImplTestBase { ClusterFactoryContext& context) { StaticClusterFactory factory; auto status_or_cluster = factory.createClusterImpl(cluster, context); - THROW_IF_STATUS_NOT_OK(status_or_cluster, throw); + THROW_IF_NOT_OK_REF(status_or_cluster.status()); return std::dynamic_pointer_cast(status_or_cluster->first); } diff --git a/test/extensions/clusters/original_dst/original_dst_cluster_test.cc b/test/extensions/clusters/original_dst/original_dst_cluster_test.cc index 301860fb6811..d0e1cd8e82f7 100644 --- a/test/extensions/clusters/original_dst/original_dst_cluster_test.cc +++ b/test/extensions/clusters/original_dst/original_dst_cluster_test.cc @@ -85,7 +85,7 @@ class OriginalDstClusterTest : public Event::TestUsingSimulatedTime, public test OriginalDstClusterFactory factory; auto status_or_pair = factory.createClusterImpl(cluster_config, factory_context); - THROW_IF_STATUS_NOT_OK(status_or_pair, throw); + THROW_IF_NOT_OK_REF(status_or_pair.status()); cluster_ = std::dynamic_pointer_cast(status_or_pair.value().first); priority_update_cb_ = cluster_->prioritySet().addPriorityUpdateCb( diff --git a/test/extensions/common/dynamic_forward_proxy/dns_cache_impl_test.cc b/test/extensions/common/dynamic_forward_proxy/dns_cache_impl_test.cc index a39c18d30433..fd3a4819cf10 100644 --- a/test/extensions/common/dynamic_forward_proxy/dns_cache_impl_test.cc +++ b/test/extensions/common/dynamic_forward_proxy/dns_cache_impl_test.cc @@ -60,7 +60,7 @@ class DnsCacheImplTest : public testing::Test, public Event::TestUsingSimulatedT EXPECT_CALL(dns_resolver_factory_, createDnsResolver(_, _, _)) .WillRepeatedly(Return(resolver_)); auto status_or_cache = DnsCacheImpl::createDnsCacheImpl(context_, config_); - THROW_IF_STATUS_NOT_OK(status_or_cache, throw); + THROW_IF_NOT_OK_REF(status_or_cache.status()); dns_cache_ = status_or_cache.value(); update_callbacks_handle_ = dns_cache_->addUpdateCallbacks(update_callbacks_); } diff --git a/test/extensions/filters/http/common/fuzz/uber_filter.cc b/test/extensions/filters/http/common/fuzz/uber_filter.cc index 514379e66792..d4ada699261d 100644 --- a/test/extensions/filters/http/common/fuzz/uber_filter.cc +++ b/test/extensions/filters/http/common/fuzz/uber_filter.cc @@ -81,7 +81,7 @@ void UberFilterFuzzer::fuzz( // Clean-up config with filter-specific logic before it runs through validations. cleanFuzzedConfig(proto_config.name(), message.get()); auto cb_or = factory.createFilterFactoryFromProto(*message, "stats", factory_context_); - THROW_IF_STATUS_NOT_OK(cb_or, throw); + THROW_IF_NOT_OK_REF(cb_or.status()); cb_ = cb_or.value(); cb_(filter_callback_); } catch (const EnvoyException& e) { diff --git a/test/fuzz/utility.h b/test/fuzz/utility.h index 25120a3f69b6..d1ac39a70aa6 100644 --- a/test/fuzz/utility.h +++ b/test/fuzz/utility.h @@ -171,7 +171,7 @@ inline std::unique_ptr fromStreamInfo(const test::fuzz::StreamIn stream_info.address().envoy_internal_address().server_listener_name())); } else { auto address_or_error = Envoy::Network::Address::resolveProtoAddress(stream_info.address()); - THROW_IF_STATUS_NOT_OK(address_or_error, throw); + THROW_IF_NOT_OK_REF(address_or_error.status()); address = address_or_error.value(); } } else { @@ -181,7 +181,7 @@ inline std::unique_ptr fromStreamInfo(const test::fuzz::StreamIn if (stream_info.has_upstream_local_address()) { auto upstream_local_address_or_error = Envoy::Network::Address::resolveProtoAddress(stream_info.upstream_local_address()); - THROW_IF_STATUS_NOT_OK(upstream_local_address_or_error, throw); + THROW_IF_NOT_OK_REF(upstream_local_address_or_error.status()); upstream_local_address = upstream_local_address_or_error.value(); } else { upstream_local_address = *Network::Utility::resolveUrl("tcp://10.0.0.1:10000"); diff --git a/test/integration/admin_html/test_server.cc b/test/integration/admin_html/test_server.cc index d371d7b22108..a96432d303e5 100644 --- a/test/integration/admin_html/test_server.cc +++ b/test/integration/admin_html/test_server.cc @@ -42,7 +42,7 @@ Http::Code testCallback(Http::ResponseHeaderMap& response_headers, Buffer::Insta std::string path = absl::StrCat(prefix, leaf); TRY_ASSERT_MAIN_THREAD { auto file_or_error = file_system.fileReadToEnd(path); - THROW_IF_STATUS_NOT_OK(file_or_error, throw); + THROW_IF_NOT_OK_REF(file_or_error.status()); response.add(file_or_error.value()); } END_TRY