error_cfstream.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
21 #ifdef GRPC_CFSTREAM
22 #include <CoreFoundation/CoreFoundation.h>
23 
24 #include <string>
25 
26 #include "absl/strings/str_format.h"
27 
28 #include <grpc/support/alloc.h>
29 
31 
32 #define MAX_ERROR_DESCRIPTION 256
33 
34 grpc_error_handle grpc_error_create_from_cferror(const char* file, int line,
35  void* arg,
36  const char* custom_desc) {
37  CFErrorRef error = static_cast<CFErrorRef>(arg);
38  char buf_domain[MAX_ERROR_DESCRIPTION];
39  char buf_desc[MAX_ERROR_DESCRIPTION];
40  CFErrorDomain domain = CFErrorGetDomain((error));
41  CFIndex code = CFErrorGetCode((error));
42  CFStringRef desc = CFErrorCopyDescription((error));
43  CFStringGetCString(domain, buf_domain, MAX_ERROR_DESCRIPTION,
44  kCFStringEncodingUTF8);
45  CFStringGetCString(desc, buf_desc, MAX_ERROR_DESCRIPTION,
46  kCFStringEncodingUTF8);
47  std::string error_msg =
48  absl::StrFormat("%s (error domain:%s, code:%ld, description:%s)",
49  custom_desc, buf_domain, code, buf_desc);
50  CFRelease(desc);
51 #ifdef GRPC_ERROR_IS_ABSEIL_STATUS
52  return StatusCreate(absl::StatusCode::kUnknown, error_msg,
54 #else
55  return grpc_error_create(
56  file, line, grpc_slice_from_copied_string(error_msg.c_str()), NULL, 0);
57 #endif
58 }
59 #endif /* GRPC_CFSTREAM */
grpc_core::DebugLocation
Definition: debug_location.h:31
grpc_error_create
grpc_error_handle grpc_error_create(const char *file, int line, const grpc_slice &desc, grpc_error_handle *referencing, size_t num_referencing)
Create an error - but use GRPC_ERROR_CREATE instead.
Definition: error.cc:489
absl::StrFormat
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec< Args... > &format, const Args &... args)
Definition: abseil-cpp/absl/strings/str_format.h:338
grpc_slice_from_copied_string
GPRAPI grpc_slice grpc_slice_from_copied_string(const char *source)
Definition: slice/slice.cc:177
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
grpc_core::StatusCreate
absl::Status StatusCreate(absl::StatusCode code, absl::string_view msg, const DebugLocation &location, std::vector< absl::Status > children)
Creates a status with given additional information.
Definition: status_helper.cc:168
arg
Definition: cmdline.cc:40
error.h
absl::StatusCode::kUnknown
@ kUnknown
alloc.h
regen-readme.line
line
Definition: regen-readme.py:30
arg
struct arg arg
desc
#define desc
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set.h:338
code
Definition: bloaty/third_party/zlib/contrib/infback9/inftree9.h:24
grpc_error
Definition: error_internal.h:42
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:15