fix posix and tsi stuff

pull/36523/head
Mark D. Roth 10 months ago
parent 120b0d9ef1
commit 45f691b271
  1. 2
      BUILD
  2. 3
      CMakeLists.txt
  3. 1
      Makefile
  4. 2
      Package.swift
  5. 6
      build_autogenerated.yaml
  6. 1
      config.m4
  7. 1
      config.w32
  8. 2
      gRPC-C++.podspec
  9. 3
      gRPC-Core.podspec
  10. 2
      grpc.gemspec
  11. 2
      package.xml
  12. 8
      src/core/handshaker/security/secure_endpoint.cc
  13. 44
      src/core/handshaker/security/security_handshaker.cc
  14. 31
      src/core/handshaker/security/tsi_error.cc
  15. 30
      src/core/handshaker/security/tsi_error.h
  16. 9
      src/core/lib/event_engine/posix_engine/posix_endpoint.cc
  17. 20
      src/core/lib/gprpp/status_helper.cc
  18. 21
      src/core/lib/gprpp/status_helper.h
  19. 14
      src/core/lib/iomgr/error.cc
  20. 8
      src/core/lib/iomgr/resolve_address_posix.cc
  21. 8
      src/core/lib/iomgr/tcp_client_posix.cc
  22. 1
      src/python/grpcio/grpc_core_dependencies.py
  23. 32
      test/core/gprpp/status_helper_test.cc
  24. 40
      test/core/iomgr/error_test.cc
  25. 5
      test/core/tsi/transport_security_test_lib.cc
  26. 2
      tools/doxygen/Doxyfile.c++.internal
  27. 2
      tools/doxygen/Doxyfile.core.internal

@ -2261,7 +2261,6 @@ grpc_cc_library(
srcs = [
"//src/core:handshaker/security/secure_endpoint.cc",
"//src/core:handshaker/security/security_handshaker.cc",
"//src/core:handshaker/security/tsi_error.cc",
"//src/core:lib/security/context/security_context.cc",
"//src/core:lib/security/credentials/call_creds_util.cc",
"//src/core:lib/security/credentials/composite/composite_credentials.cc",
@ -2274,7 +2273,6 @@ grpc_cc_library(
hdrs = [
"//src/core:handshaker/security/secure_endpoint.h",
"//src/core:handshaker/security/security_handshaker.h",
"//src/core:handshaker/security/tsi_error.h",
"//src/core:lib/security/context/security_context.h",
"//src/core:lib/security/credentials/call_creds_util.h",
"//src/core:lib/security/credentials/composite/composite_credentials.h",

3
CMakeLists.txt generated

@ -2245,7 +2245,6 @@ add_library(grpc
src/core/handshaker/proxy_mapper_registry.cc
src/core/handshaker/security/secure_endpoint.cc
src/core/handshaker/security/security_handshaker.cc
src/core/handshaker/security/tsi_error.cc
src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc
src/core/lib/address_utils/parse_address.cc
src/core/lib/address_utils/sockaddr_utils.cc
@ -3013,7 +3012,6 @@ add_library(grpc_unsecure
src/core/handshaker/proxy_mapper_registry.cc
src/core/handshaker/security/secure_endpoint.cc
src/core/handshaker/security/security_handshaker.cc
src/core/handshaker/security/tsi_error.cc
src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc
src/core/lib/address_utils/parse_address.cc
src/core/lib/address_utils/sockaddr_utils.cc
@ -5132,7 +5130,6 @@ add_library(grpc_authorization_provider
src/core/handshaker/proxy_mapper_registry.cc
src/core/handshaker/security/secure_endpoint.cc
src/core/handshaker/security/security_handshaker.cc
src/core/handshaker/security/tsi_error.cc
src/core/lib/address_utils/parse_address.cc
src/core/lib/address_utils/sockaddr_utils.cc
src/core/lib/backoff/backoff.cc

1
Makefile generated

@ -1086,7 +1086,6 @@ LIBGRPC_SRC = \
src/core/handshaker/proxy_mapper_registry.cc \
src/core/handshaker/security/secure_endpoint.cc \
src/core/handshaker/security/security_handshaker.cc \
src/core/handshaker/security/tsi_error.cc \
src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc \
src/core/lib/address_utils/parse_address.cc \
src/core/lib/address_utils/sockaddr_utils.cc \

2
Package.swift generated

@ -1132,8 +1132,6 @@ let package = Package(
"src/core/handshaker/security/secure_endpoint.h",
"src/core/handshaker/security/security_handshaker.cc",
"src/core/handshaker/security/security_handshaker.h",
"src/core/handshaker/security/tsi_error.cc",
"src/core/handshaker/security/tsi_error.h",
"src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc",
"src/core/handshaker/tcp_connect/tcp_connect_handshaker.h",
"src/core/lib/address_utils/parse_address.cc",

@ -817,7 +817,6 @@ libs:
- src/core/handshaker/proxy_mapper_registry.h
- src/core/handshaker/security/secure_endpoint.h
- src/core/handshaker/security/security_handshaker.h
- src/core/handshaker/security/tsi_error.h
- src/core/handshaker/tcp_connect/tcp_connect_handshaker.h
- src/core/lib/address_utils/parse_address.h
- src/core/lib/address_utils/sockaddr_utils.h
@ -1665,7 +1664,6 @@ libs:
- src/core/handshaker/proxy_mapper_registry.cc
- src/core/handshaker/security/secure_endpoint.cc
- src/core/handshaker/security/security_handshaker.cc
- src/core/handshaker/security/tsi_error.cc
- src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc
- src/core/lib/address_utils/parse_address.cc
- src/core/lib/address_utils/sockaddr_utils.cc
@ -2322,7 +2320,6 @@ libs:
- src/core/handshaker/proxy_mapper_registry.h
- src/core/handshaker/security/secure_endpoint.h
- src/core/handshaker/security/security_handshaker.h
- src/core/handshaker/security/tsi_error.h
- src/core/handshaker/tcp_connect/tcp_connect_handshaker.h
- src/core/lib/address_utils/parse_address.h
- src/core/lib/address_utils/sockaddr_utils.h
@ -2791,7 +2788,6 @@ libs:
- src/core/handshaker/proxy_mapper_registry.cc
- src/core/handshaker/security/secure_endpoint.cc
- src/core/handshaker/security/security_handshaker.cc
- src/core/handshaker/security/tsi_error.cc
- src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc
- src/core/lib/address_utils/parse_address.cc
- src/core/lib/address_utils/sockaddr_utils.cc
@ -4411,7 +4407,6 @@ libs:
- src/core/handshaker/proxy_mapper_registry.h
- src/core/handshaker/security/secure_endpoint.h
- src/core/handshaker/security/security_handshaker.h
- src/core/handshaker/security/tsi_error.h
- src/core/lib/address_utils/parse_address.h
- src/core/lib/address_utils/sockaddr_utils.h
- src/core/lib/avl/avl.h
@ -4756,7 +4751,6 @@ libs:
- src/core/handshaker/proxy_mapper_registry.cc
- src/core/handshaker/security/secure_endpoint.cc
- src/core/handshaker/security/security_handshaker.cc
- src/core/handshaker/security/tsi_error.cc
- src/core/lib/address_utils/parse_address.cc
- src/core/lib/address_utils/sockaddr_utils.cc
- src/core/lib/backoff/backoff.cc

1
config.m4 generated

@ -461,7 +461,6 @@ if test "$PHP_GRPC" != "no"; then
src/core/handshaker/proxy_mapper_registry.cc \
src/core/handshaker/security/secure_endpoint.cc \
src/core/handshaker/security/security_handshaker.cc \
src/core/handshaker/security/tsi_error.cc \
src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc \
src/core/lib/address_utils/parse_address.cc \
src/core/lib/address_utils/sockaddr_utils.cc \

1
config.w32 generated

@ -426,7 +426,6 @@ if (PHP_GRPC != "no") {
"src\\core\\handshaker\\proxy_mapper_registry.cc " +
"src\\core\\handshaker\\security\\secure_endpoint.cc " +
"src\\core\\handshaker\\security\\security_handshaker.cc " +
"src\\core\\handshaker\\security\\tsi_error.cc " +
"src\\core\\handshaker\\tcp_connect\\tcp_connect_handshaker.cc " +
"src\\core\\lib\\address_utils\\parse_address.cc " +
"src\\core\\lib\\address_utils\\sockaddr_utils.cc " +

2
gRPC-C++.podspec generated

@ -897,7 +897,6 @@ Pod::Spec.new do |s|
'src/core/handshaker/proxy_mapper_registry.h',
'src/core/handshaker/security/secure_endpoint.h',
'src/core/handshaker/security/security_handshaker.h',
'src/core/handshaker/security/tsi_error.h',
'src/core/handshaker/tcp_connect/tcp_connect_handshaker.h',
'src/core/lib/address_utils/parse_address.h',
'src/core/lib/address_utils/sockaddr_utils.h',
@ -2166,7 +2165,6 @@ Pod::Spec.new do |s|
'src/core/handshaker/proxy_mapper_registry.h',
'src/core/handshaker/security/secure_endpoint.h',
'src/core/handshaker/security/security_handshaker.h',
'src/core/handshaker/security/tsi_error.h',
'src/core/handshaker/tcp_connect/tcp_connect_handshaker.h',
'src/core/lib/address_utils/parse_address.h',
'src/core/lib/address_utils/sockaddr_utils.h',

3
gRPC-Core.podspec generated

@ -1251,8 +1251,6 @@ Pod::Spec.new do |s|
'src/core/handshaker/security/secure_endpoint.h',
'src/core/handshaker/security/security_handshaker.cc',
'src/core/handshaker/security/security_handshaker.h',
'src/core/handshaker/security/tsi_error.cc',
'src/core/handshaker/security/tsi_error.h',
'src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc',
'src/core/handshaker/tcp_connect/tcp_connect_handshaker.h',
'src/core/lib/address_utils/parse_address.cc',
@ -2944,7 +2942,6 @@ Pod::Spec.new do |s|
'src/core/handshaker/proxy_mapper_registry.h',
'src/core/handshaker/security/secure_endpoint.h',
'src/core/handshaker/security/security_handshaker.h',
'src/core/handshaker/security/tsi_error.h',
'src/core/handshaker/tcp_connect/tcp_connect_handshaker.h',
'src/core/lib/address_utils/parse_address.h',
'src/core/lib/address_utils/sockaddr_utils.h',

2
grpc.gemspec generated

@ -1138,8 +1138,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/handshaker/security/secure_endpoint.h )
s.files += %w( src/core/handshaker/security/security_handshaker.cc )
s.files += %w( src/core/handshaker/security/security_handshaker.h )
s.files += %w( src/core/handshaker/security/tsi_error.cc )
s.files += %w( src/core/handshaker/security/tsi_error.h )
s.files += %w( src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc )
s.files += %w( src/core/handshaker/tcp_connect/tcp_connect_handshaker.h )
s.files += %w( src/core/lib/address_utils/parse_address.cc )

2
package.xml generated

@ -1120,8 +1120,6 @@
<file baseinstalldir="/" name="src/core/handshaker/security/secure_endpoint.h" role="src" />
<file baseinstalldir="/" name="src/core/handshaker/security/security_handshaker.cc" role="src" />
<file baseinstalldir="/" name="src/core/handshaker/security/security_handshaker.h" role="src" />
<file baseinstalldir="/" name="src/core/handshaker/security/tsi_error.cc" role="src" />
<file baseinstalldir="/" name="src/core/handshaker/security/tsi_error.h" role="src" />
<file baseinstalldir="/" name="src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc" role="src" />
<file baseinstalldir="/" name="src/core/handshaker/tcp_connect/tcp_connect_handshaker.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/address_utils/parse_address.cc" role="src" />

@ -40,7 +40,6 @@
#include <grpc/support/port_platform.h>
#include <grpc/support/sync.h>
#include "src/core/handshaker/security/tsi_error.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/debug_location.h"
@ -340,8 +339,8 @@ static void on_read(void* user_data, grpc_error_handle error) {
if (result != TSI_OK) {
grpc_slice_buffer_reset_and_unref(ep->read_buffer);
call_read_cb(ep, grpc_set_tsi_error_result(
GRPC_ERROR_CREATE("Unwrap failed"), result));
call_read_cb(ep, GRPC_ERROR_CREATE(absl::StrCat(
"Unwrap failed (", tsi_result_to_string(result), ")")));
return;
}
@ -484,7 +483,8 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
grpc_slice_buffer_reset_and_unref(&ep->output_buffer);
grpc_core::ExecCtx::Run(
DEBUG_LOCATION, cb,
grpc_set_tsi_error_result(GRPC_ERROR_CREATE("Wrap failed"), result));
GRPC_ERROR_CREATE(
absl::StrCat("Wrap failed (", tsi_result_to_string(result), ")")));
return;
}

@ -48,7 +48,6 @@
#include "src/core/handshaker/handshaker_factory.h"
#include "src/core/handshaker/handshaker_registry.h"
#include "src/core/handshaker/security/secure_endpoint.h"
#include "src/core/handshaker/security/tsi_error.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/stats.h"
@ -260,10 +259,10 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
tsi_result result = tsi_handshaker_result_get_unused_bytes(
handshaker_result_, &unused_bytes, &unused_bytes_size);
if (result != TSI_OK) {
HandshakeFailedLocked(grpc_set_tsi_error_result(
GRPC_ERROR_CREATE(
"TSI handshaker result does not provide unused bytes"),
result));
HandshakeFailedLocked(
GRPC_ERROR_CREATE(absl::StrCat(
"TSI handshaker result does not provide unused bytes (",
tsi_result_to_string(result), ")")));
return;
}
// Check whether we need to wrap the endpoint.
@ -271,10 +270,11 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
result = tsi_handshaker_result_get_frame_protector_type(
handshaker_result_, &frame_protector_type);
if (result != TSI_OK) {
HandshakeFailedLocked(grpc_set_tsi_error_result(
GRPC_ERROR_CREATE("TSI handshaker result does not implement "
"get_frame_protector_type"),
result));
HandshakeFailedLocked(
GRPC_ERROR_CREATE(absl::StrCat(
"TSI handshaker result does not implement "
"get_frame_protector_type (",
tsi_result_to_string(result), ")")));
return;
}
tsi_zero_copy_grpc_protector* zero_copy_protector = nullptr;
@ -288,9 +288,10 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
handshaker_result_, max_frame_size_ == 0 ? nullptr : &max_frame_size_,
&zero_copy_protector);
if (result != TSI_OK) {
HandshakeFailedLocked(grpc_set_tsi_error_result(
GRPC_ERROR_CREATE("Zero-copy frame protector creation failed"),
result));
HandshakeFailedLocked(
GRPC_ERROR_CREATE(absl::StrCat(
"Zero-copy frame protector creation failed (",
tsi_result_to_string(result), ")")));
return;
}
break;
@ -300,8 +301,10 @@ void SecurityHandshaker::OnPeerCheckedInner(grpc_error_handle error) {
handshaker_result_, max_frame_size_ == 0 ? nullptr : &max_frame_size_,
&protector);
if (result != TSI_OK) {
HandshakeFailedLocked(grpc_set_tsi_error_result(
GRPC_ERROR_CREATE("Frame protector creation failed"), result));
HandshakeFailedLocked(
GRPC_ERROR_CREATE(absl::StrCat(
"Frame protector creation failed (",
tsi_result_to_string(result), ")")));
return;
}
break;
@ -356,8 +359,8 @@ grpc_error_handle SecurityHandshaker::CheckPeerLocked() {
tsi_result result =
tsi_handshaker_result_extract_peer(handshaker_result_, &peer);
if (result != TSI_OK) {
return grpc_set_tsi_error_result(
GRPC_ERROR_CREATE("Peer extraction failed"), result);
return GRPC_ERROR_CREATE(absl::StrCat(
"Peer extraction failed (", tsi_result_to_string(result), ")"));
}
connector_->check_peer(peer, args_->endpoint, args_->args, &auth_context_,
&on_peer_checked_);
@ -398,11 +401,10 @@ grpc_error_handle SecurityHandshaker::OnHandshakeNextDoneLocked(
if (security_connector != nullptr) {
connector_type = security_connector->type().name();
}
return grpc_set_tsi_error_result(
GRPC_ERROR_CREATE(absl::StrCat(
connector_type, " handshake failed",
(tsi_handshake_error_.empty() ? "" : ": "), tsi_handshake_error_)),
result);
return GRPC_ERROR_CREATE(absl::StrCat(
connector_type, " handshake failed (", tsi_result_to_string(result),
")", (tsi_handshake_error_.empty() ? "" : ": "),
tsi_handshake_error_));
}
// Update handshaker result.
if (handshaker_result != nullptr) {

@ -1,31 +0,0 @@
//
//
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#include "src/core/handshaker/security/tsi_error.h"
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/status_helper.h"
grpc_error_handle grpc_set_tsi_error_result(grpc_error_handle error,
tsi_result result) {
return grpc_error_set_int(
grpc_error_set_str(error, grpc_core::StatusStrProperty::kTsiError,
tsi_result_to_string(result)),
grpc_core::StatusIntProperty::kTsiCode, result);
}

@ -1,30 +0,0 @@
//
//
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#ifndef GRPC_SRC_CORE_HANDSHAKER_SECURITY_TSI_ERROR_H
#define GRPC_SRC_CORE_HANDSHAKER_SECURITY_TSI_ERROR_H
#include <grpc/support/port_platform.h>
#include "src/core/lib/iomgr/error.h"
#include "src/core/tsi/transport_security_interface.h"
grpc_error_handle grpc_set_tsi_error_result(grpc_error_handle error,
tsi_result result);
#endif // GRPC_SRC_CORE_HANDSHAKER_SECURITY_TSI_ERROR_H

@ -212,13 +212,8 @@ bool CmsgIsZeroCopy(const cmsghdr& cmsg) {
#endif // GRPC_LINUX_ERRQUEUE
absl::Status PosixOSError(int error_no, const char* call_name) {
absl::Status s = absl::UnknownError(grpc_core::StrError(error_no));
grpc_core::StatusSetInt(&s, grpc_core::StatusIntProperty::kErrorNo, error_no);
grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::kOsError,
grpc_core::StrError(error_no));
grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::kSyscall,
call_name);
return s;
return absl::UnknownError(absl::StrCat(
call_name, ": ", grpc_core::StrError(error_no), " (", error_no, ")"));
}
} // namespace

@ -59,24 +59,14 @@ const absl::string_view kChildrenPropertyUrl = TYPE_URL(TYPE_CHILDREN_TAG);
const char* GetStatusIntPropertyUrl(StatusIntProperty key) {
switch (key) {
case StatusIntProperty::kErrorNo:
return TYPE_URL(TYPE_INT_TAG "errno");
case StatusIntProperty::kFileLine:
return TYPE_URL(TYPE_INT_TAG "file_line");
case StatusIntProperty::kStreamId:
return TYPE_URL(TYPE_INT_TAG "stream_id");
case StatusIntProperty::kRpcStatus:
return TYPE_URL(TYPE_INT_TAG "grpc_status");
case StatusIntProperty::kOffset:
return TYPE_URL(TYPE_INT_TAG "offset");
case StatusIntProperty::kIndex:
return TYPE_URL(TYPE_INT_TAG "index");
case StatusIntProperty::kSize:
return TYPE_URL(TYPE_INT_TAG "size");
case StatusIntProperty::kHttp2Error:
return TYPE_URL(TYPE_INT_TAG "http2_error");
case StatusIntProperty::kTsiCode:
return TYPE_URL(TYPE_INT_TAG "tsi_code");
case StatusIntProperty::kWsaError:
return TYPE_URL(TYPE_INT_TAG "wsa_error");
case StatusIntProperty::kFd:
@ -99,24 +89,14 @@ const char* GetStatusStrPropertyUrl(StatusStrProperty key) {
return TYPE_URL(TYPE_STR_TAG "description");
case StatusStrProperty::kFile:
return TYPE_URL(TYPE_STR_TAG "file");
case StatusStrProperty::kOsError:
return TYPE_URL(TYPE_STR_TAG "os_error");
case StatusStrProperty::kSyscall:
return TYPE_URL(TYPE_STR_TAG "syscall");
case StatusStrProperty::kTargetAddress:
return TYPE_URL(TYPE_STR_TAG "target_address");
case StatusStrProperty::kGrpcMessage:
return TYPE_URL(TYPE_STR_TAG "grpc_message");
case StatusStrProperty::kRawBytes:
return TYPE_URL(TYPE_STR_TAG "raw_bytes");
case StatusStrProperty::kTsiError:
return TYPE_URL(TYPE_STR_TAG "tsi_error");
case StatusStrProperty::kFilename:
return TYPE_URL(TYPE_STR_TAG "filename");
case StatusStrProperty::kKey:
return TYPE_URL(TYPE_STR_TAG "key");
case StatusStrProperty::kValue:
return TYPE_URL(TYPE_STR_TAG "value");
}
GPR_UNREACHABLE_CODE(return "unknown");
}

@ -48,8 +48,6 @@ namespace grpc_core {
/// This enum should have the same value of grpc_error_ints
enum class StatusIntProperty {
/// 'errno' from the operating system
kErrorNo,
/// __LINE__ from the call site creating the error
kFileLine,
/// stream identifier: for errors that are associated with an individual
@ -58,17 +56,8 @@ enum class StatusIntProperty {
/// grpc status code representing this error
// TODO(veblush): Remove this after grpc_error is replaced with absl::Status
kRpcStatus,
/// offset into some binary blob (usually represented by
/// RAW_BYTES) where the error occurred
kOffset,
/// context sensitive index associated with the error
kIndex,
/// context sensitive size associated with the error
kSize,
/// http2 error code associated with the error (see the HTTP2 RFC)
kHttp2Error,
/// TSI status code associated with the error
kTsiCode,
/// WSAGetLastError() reported when this error occurred
kWsaError,
/// File descriptor associated with this error
@ -89,24 +78,14 @@ enum class StatusStrProperty {
kDescription,
/// source file in which this error occurred
kFile,
/// operating system description of this error
kOsError,
/// syscall that generated this error
kSyscall,
/// peer that we were trying to communicate when this error occurred
kTargetAddress,
/// grpc status message associated with this error
kGrpcMessage,
/// hex dump (or similar) with the data that generated this error
kRawBytes,
/// tsi error string associated with this error
kTsiError,
/// filename that we were trying to read/write when this error occurred
kFilename,
/// key associated with the error
kKey,
/// value associated with the error
kValue,
};
/// This enum should have the same value of grpc_error_times

@ -21,6 +21,7 @@
#include <string.h>
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include <grpc/status.h>
@ -58,15 +59,10 @@ absl::Status grpc_status_create(absl::StatusCode code, absl::string_view msg,
absl::Status grpc_os_error(const grpc_core::DebugLocation& location, int err,
const char* call_name) {
auto err_string = grpc_core::StrError(err);
absl::Status s =
StatusCreate(absl::StatusCode::kUnknown, err_string, location, {});
grpc_core::StatusSetInt(&s, grpc_core::StatusIntProperty::kErrorNo, err);
grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::kOsError,
err_string);
grpc_core::StatusSetStr(&s, grpc_core::StatusStrProperty::kSyscall,
call_name);
return s;
return StatusCreate(
absl::StatusCode::kUnknown,
absl::StrCat(call_name, ": ", grpc_core::StrError(err), " (", err, ")"),
location, {});
}
#ifdef GPR_WINDOWS

@ -140,12 +140,8 @@ NativeDNSResolver::LookupHostnameBlocking(absl::string_view name,
}
if (s != 0) {
err = grpc_error_set_str(
grpc_error_set_str(
grpc_error_set_str(
grpc_error_set_int(GRPC_ERROR_CREATE(gai_strerror(s)),
StatusIntProperty::kErrorNo, s),
StatusStrProperty::kOsError, gai_strerror(s)),
StatusStrProperty::kSyscall, "getaddrinfo"),
absl::UnknownError(absl::StrCat(
"getaddrinfo(\"", name, "\"): ", gai_strerror(s), " (", s, ")")),
StatusStrProperty::kTargetAddress, name);
goto done;
}

@ -198,8 +198,12 @@ static void on_writable(void* acp, grpc_error_handle error) {
gpr_mu_lock(&ac->mu);
if (!error.ok()) {
error = grpc_error_set_str(error, grpc_core::StatusStrProperty::kOsError,
"Timeout occurred");
absl::Status status(
error.code(), absl::StrCat(error.message(), " (Timeout occurred)"));
error.ForEachPayload([&](absl::string_view uri, const absl::Cord& value) {
status.SetPayload(uri, value);
});
error = std::move(status);
goto finish;
}

@ -435,7 +435,6 @@ CORE_SOURCE_FILES = [
'src/core/handshaker/proxy_mapper_registry.cc',
'src/core/handshaker/security/secure_endpoint.cc',
'src/core/handshaker/security/security_handshaker.cc',
'src/core/handshaker/security/tsi_error.cc',
'src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc',
'src/core/lib/address_utils/parse_address.cc',
'src/core/lib/address_utils/sockaddr_utils.cc',

@ -47,26 +47,26 @@ TEST(StatusUtilTest, CreateStatus) {
TEST(StatusUtilTest, SetAndGetInt) {
absl::Status s = absl::CancelledError();
StatusSetInt(&s, StatusIntProperty::kErrorNo, 2021);
EXPECT_EQ(2021, StatusGetInt(s, StatusIntProperty::kErrorNo));
StatusSetInt(&s, StatusIntProperty::kStreamId, 2021);
EXPECT_EQ(2021, StatusGetInt(s, StatusIntProperty::kStreamId));
}
TEST(StatusUtilTest, GetIntNotExistent) {
absl::Status s = absl::CancelledError();
EXPECT_EQ(absl::optional<intptr_t>(),
StatusGetInt(s, StatusIntProperty::kErrorNo));
StatusGetInt(s, StatusIntProperty::kStreamId));
}
TEST(StatusUtilTest, SetAndGetStr) {
absl::Status s = absl::CancelledError();
StatusSetStr(&s, StatusStrProperty::kOsError, "value");
EXPECT_EQ("value", StatusGetStr(s, StatusStrProperty::kOsError));
StatusSetStr(&s, StatusStrProperty::kFile, "value");
EXPECT_EQ("value", StatusGetStr(s, StatusStrProperty::kFile));
}
TEST(StatusUtilTest, GetStrNotExistent) {
absl::Status s = absl::CancelledError();
EXPECT_EQ(absl::optional<std::string>(),
StatusGetStr(s, StatusStrProperty::kOsError));
StatusGetStr(s, StatusStrProperty::kFile));
}
TEST(StatusUtilTest, SetAndGetTime) {
@ -96,8 +96,8 @@ TEST(StatusUtilTest, AddAndGetChildren) {
TEST(StatusUtilTest, ToAndFromProto) {
absl::Status s = absl::CancelledError("Message");
StatusSetInt(&s, StatusIntProperty::kErrorNo, 2021);
StatusSetStr(&s, StatusStrProperty::kOsError, "value");
StatusSetInt(&s, StatusIntProperty::kStreamId, 2021);
StatusSetStr(&s, StatusStrProperty::kFile, "value");
upb::Arena arena;
google_rpc_Status* msg = internal::StatusToProto(s, arena.ptr());
size_t len;
@ -109,8 +109,8 @@ TEST(StatusUtilTest, ToAndFromProto) {
TEST(StatusUtilTest, ToAndFromProtoWithNonUTF8Characters) {
absl::Status s = absl::CancelledError("_\xAB\xCD\xEF_");
StatusSetInt(&s, StatusIntProperty::kErrorNo, 2021);
StatusSetStr(&s, StatusStrProperty::kOsError, "!\xFF\xCC\xAA!");
StatusSetInt(&s, StatusIntProperty::kStreamId, 2021);
StatusSetStr(&s, StatusStrProperty::kFile, "!\xFF\xCC\xAA!");
upb::Arena arena;
google_rpc_Status* msg = internal::StatusToProto(s, arena.ptr());
size_t len;
@ -134,9 +134,9 @@ TEST(StatusUtilTest, CancelledErrorToString) {
TEST(StatusUtilTest, ErrorWithIntPropertyToString) {
absl::Status s = absl::CancelledError("Message");
StatusSetInt(&s, StatusIntProperty::kErrorNo, 2021);
StatusSetInt(&s, StatusIntProperty::kStreamId, 2021);
std::string t = StatusToString(s);
EXPECT_EQ("CANCELLED:Message {errno:2021}", t);
EXPECT_EQ("CANCELLED:Message {stream_id:2021}", t);
}
TEST(StatusUtilTest, ErrorWithStrPropertyToString) {
@ -158,16 +158,16 @@ TEST(StatusUtilTest, ErrorWithTimePropertyToString) {
TEST(StatusUtilTest, ComplexErrorWithChildrenToString) {
absl::Status s = absl::CancelledError("Message");
StatusSetInt(&s, StatusIntProperty::kErrorNo, 2021);
StatusSetInt(&s, StatusIntProperty::kStreamId, 2021);
absl::Status s1 = absl::AbortedError("Message1");
StatusAddChild(&s, s1);
absl::Status s2 = absl::AlreadyExistsError("Message2");
StatusSetStr(&s2, StatusStrProperty::kOsError, "value");
StatusSetStr(&s2, StatusStrProperty::kFile, "value");
StatusAddChild(&s, s2);
std::string t = StatusToString(s);
EXPECT_EQ(
"CANCELLED:Message {errno:2021, children:["
"ABORTED:Message1, ALREADY_EXISTS:Message2 {os_error:\"value\"}]}",
"CANCELLED:Message {stream_id:2021, children:["
"ABORTED:Message1, ALREADY_EXISTS:Message2 {file:\"value\"}]}",
t);
}

@ -40,16 +40,9 @@ TEST(ErrorTest, SetGetInt) {
EXPECT_TRUE(i); // line set will never be 0
#endif
EXPECT_TRUE(
!grpc_error_get_int(error, grpc_core::StatusIntProperty::kErrorNo, &i));
EXPECT_TRUE(
!grpc_error_get_int(error, grpc_core::StatusIntProperty::kSize, &i));
intptr_t errnumber = 314;
error = grpc_error_set_int(error, grpc_core::StatusIntProperty::kErrorNo,
errnumber);
EXPECT_TRUE(
grpc_error_get_int(error, grpc_core::StatusIntProperty::kErrorNo, &i));
EXPECT_EQ(i, errnumber);
!grpc_error_get_int(error, grpc_core::StatusIntProperty::kStreamId, &i));
EXPECT_TRUE(!grpc_error_get_int(
error, grpc_core::StatusIntProperty::kHttp2Error, &i));
intptr_t http = 2;
error = grpc_error_set_int(error, grpc_core::StatusIntProperty::kHttp2Error,
@ -63,10 +56,6 @@ TEST(ErrorTest, SetGetStr) {
grpc_error_handle error = GRPC_ERROR_CREATE("Test");
std::string str;
EXPECT_TRUE(
!grpc_error_get_str(error, grpc_core::StatusStrProperty::kSyscall, &str));
EXPECT_TRUE(!grpc_error_get_str(
error, grpc_core::StatusStrProperty::kTsiError, &str));
#ifndef NDEBUG
// grpc_core::StatusStrProperty::kFile is for debug only
EXPECT_TRUE(
@ -99,7 +88,7 @@ TEST(ErrorTest, CopyAndUnRef) {
// this gives error3 a ref to the new error, and decrements error1 to one ref
grpc_error_handle error3 = grpc_error_set_str(
error1, grpc_core::StatusStrProperty::kSyscall, "syscall");
error1, grpc_core::StatusStrProperty::kFile, "file");
EXPECT_NE(error3, error1); // should not be the same because of extra ref
EXPECT_TRUE(grpc_error_get_str(
error3, grpc_core::StatusStrProperty::kGrpcMessage, &str));
@ -107,10 +96,10 @@ TEST(ErrorTest, CopyAndUnRef) {
// error 1 should not have a syscall but 3 should
EXPECT_TRUE(!grpc_error_get_str(
error1, grpc_core::StatusStrProperty::kSyscall, &str));
error1, grpc_core::StatusStrProperty::kFile, &str));
EXPECT_TRUE(
grpc_error_get_str(error3, grpc_core::StatusStrProperty::kSyscall, &str));
EXPECT_EQ(str, "syscall");
grpc_error_get_str(error3, grpc_core::StatusStrProperty::kFile, &str));
EXPECT_EQ(str, "file");
}
TEST(ErrorTest, CreateReferencing) {
@ -145,7 +134,8 @@ TEST(ErrorTest, PrintErrorString) {
grpc_error_handle error = grpc_error_set_int(
GRPC_ERROR_CREATE("Error"), grpc_core::StatusIntProperty::kRpcStatus,
GRPC_STATUS_UNIMPLEMENTED);
error = grpc_error_set_int(error, grpc_core::StatusIntProperty::kSize, 666);
error = grpc_error_set_int(error, grpc_core::StatusIntProperty::kHttp2Error,
666);
error = grpc_error_set_str(error, grpc_core::StatusStrProperty::kGrpcMessage,
"message");
// gpr_log(GPR_DEBUG, "%s", grpc_core::StatusToString(error).c_str());
@ -175,16 +165,8 @@ TEST(ErrorTest, TestOsError) {
int fake_errno = 5;
const char* syscall = "syscall name";
grpc_error_handle error = GRPC_OS_ERROR(fake_errno, syscall);
intptr_t i = 0;
EXPECT_TRUE(
grpc_error_get_int(error, grpc_core::StatusIntProperty::kErrorNo, &i));
EXPECT_EQ(i, fake_errno);
std::string str;
EXPECT_TRUE(
grpc_error_get_str(error, grpc_core::StatusStrProperty::kSyscall, &str));
EXPECT_EQ(str, syscall);
EXPECT_EQ(error.message(),
absl::StrCat("syscall name: ", grpc_core::StrError(5), " (5)"));
}
int main(int argc, char** argv) {

@ -37,7 +37,6 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/handshaker/security/tsi_error.h"
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/memory.h"
@ -318,8 +317,8 @@ grpc_error_handle on_handshake_next_done(
}
if (result != TSI_OK) {
notification_signal(fixture);
return grpc_set_tsi_error_result(GRPC_ERROR_CREATE("Handshake failed"),
result);
return GRPC_ERROR_CREATE(absl::StrCat(
"Handshake failed (", tsi_result_to_string(result), ")"));
}
// Update handshaker result.
if (handshaker_result != nullptr) {

@ -2138,8 +2138,6 @@ src/core/handshaker/security/secure_endpoint.cc \
src/core/handshaker/security/secure_endpoint.h \
src/core/handshaker/security/security_handshaker.cc \
src/core/handshaker/security/security_handshaker.h \
src/core/handshaker/security/tsi_error.cc \
src/core/handshaker/security/tsi_error.h \
src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc \
src/core/handshaker/tcp_connect/tcp_connect_handshaker.h \
src/core/lib/address_utils/parse_address.cc \

@ -1907,8 +1907,6 @@ src/core/handshaker/security/secure_endpoint.cc \
src/core/handshaker/security/secure_endpoint.h \
src/core/handshaker/security/security_handshaker.cc \
src/core/handshaker/security/security_handshaker.h \
src/core/handshaker/security/tsi_error.cc \
src/core/handshaker/security/tsi_error.h \
src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc \
src/core/handshaker/tcp_connect/tcp_connect_handshaker.h \
src/core/lib/README.md \

Loading…
Cancel
Save