Matter SDK Coverage Report
Current view: top level - inet - InetError.cpp (source / functions) Coverage Total Hit
Test: SHA:b879ecb8e99e175eea0a293a888bda853da2b19c Lines: 61.7 % 94 58
Test Date: 2025-01-17 19:00:11 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :  *
       3              :  *    Copyright (c) 2020 Project CHIP Authors
       4              :  *    Copyright (c) 2019 Google LLC.
       5              :  *
       6              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       7              :  *    you may not use this file except in compliance with the License.
       8              :  *    You may obtain a copy of the License at
       9              :  *
      10              :  *        http://www.apache.org/licenses/LICENSE-2.0
      11              :  *
      12              :  *    Unless required by applicable law or agreed to in writing, software
      13              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      14              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15              :  *    See the License for the specific language governing permissions and
      16              :  *    limitations under the License.
      17              :  */
      18              : 
      19              : /**
      20              :  *    @file
      21              :  *      This file contains functions for working with Inet Layer errors.
      22              :  */
      23              : 
      24              : #include <stddef.h>
      25              : 
      26              : #include <inet/Inet.h>
      27              : #include <inet/InetError.h>
      28              : 
      29              : extern void FormatError(char * buf, uint16_t bufSize, const char * subsys, int32_t err, const char * desc);
      30              : 
      31              : namespace chip {
      32              : namespace Inet {
      33              : 
      34              : /**
      35              :  * Register a text error formatter for Inet Layer errors.
      36              :  */
      37          187 : void RegisterLayerErrorFormatter()
      38              : {
      39              :     static chip::ErrorFormatter sInetLayerErrorFormatter = { FormatLayerError, nullptr };
      40              : 
      41          187 :     RegisterErrorFormatter(&sInetLayerErrorFormatter);
      42          187 : }
      43              : 
      44              : /**
      45              :  * Given an Inet Layer error, returns a human-readable NULL-terminated C string
      46              :  * describing the error.
      47              :  *
      48              :  * @param[in] buf                   Buffer into which the error string will be placed.
      49              :  * @param[in] bufSize               Size of the supplied buffer in bytes.
      50              :  * @param[in] err                   The error to be described.
      51              :  *
      52              :  * @return true                     If a description string was written into the supplied buffer.
      53              :  * @return false                    If the supplied error was not an Inet Layer error.
      54              :  *
      55              :  */
      56          309 : bool FormatLayerError(char * buf, uint16_t bufSize, CHIP_ERROR err)
      57              : {
      58          309 :     const char * desc = nullptr;
      59              : 
      60          309 :     if (!err.IsPart(ChipError::SdkPart::kInet))
      61              :     {
      62          279 :         return false;
      63              :     }
      64              : 
      65              : #if !CHIP_CONFIG_SHORT_ERROR_STR
      66           30 :     switch (err.AsInteger())
      67              :     {
      68           13 :     case INET_ERROR_WRONG_ADDRESS_TYPE.AsInteger():
      69           13 :         desc = "Wrong address type";
      70           13 :         break;
      71            0 :     case CHIP_ERROR_CONNECTION_ABORTED.AsInteger():
      72            0 :         desc = "TCP connection aborted";
      73            0 :         break;
      74            1 :     case INET_ERROR_PEER_DISCONNECTED.AsInteger():
      75            1 :         desc = "Peer disconnected";
      76            1 :         break;
      77            0 :     case CHIP_ERROR_INCORRECT_STATE.AsInteger():
      78            0 :         desc = "Incorrect state";
      79            0 :         break;
      80            0 :     case CHIP_ERROR_MESSAGE_TOO_LONG.AsInteger():
      81            0 :         desc = "Message too long";
      82            0 :         break;
      83            0 :     case CHIP_ERROR_NO_CONNECTION_HANDLER.AsInteger():
      84            0 :         desc = "No TCP connection handler";
      85            0 :         break;
      86            0 :     case CHIP_ERROR_NO_MEMORY.AsInteger():
      87            0 :         desc = "No memory";
      88            0 :         break;
      89            0 :     case CHIP_ERROR_OUTBOUND_MESSAGE_TOO_BIG.AsInteger():
      90            0 :         desc = "Outbound message truncated";
      91            0 :         break;
      92            0 :     case CHIP_ERROR_INBOUND_MESSAGE_TOO_BIG.AsInteger():
      93            0 :         desc = "Inbound message too big";
      94            0 :         break;
      95            1 :     case INET_ERROR_HOST_NOT_FOUND.AsInteger():
      96            1 :         desc = "Host not found";
      97            1 :         break;
      98            1 :     case INET_ERROR_DNS_TRY_AGAIN.AsInteger():
      99            1 :         desc = "DNS try again";
     100            1 :         break;
     101            1 :     case INET_ERROR_DNS_NO_RECOVERY.AsInteger():
     102            1 :         desc = "DNS no recovery";
     103            1 :         break;
     104            0 :     case CHIP_ERROR_INVALID_ARGUMENT.AsInteger():
     105            0 :         desc = "Bad arguments";
     106            0 :         break;
     107            1 :     case INET_ERROR_WRONG_PROTOCOL_TYPE.AsInteger():
     108            1 :         desc = "Wrong protocol type";
     109            1 :         break;
     110            2 :     case INET_ERROR_UNKNOWN_INTERFACE.AsInteger():
     111            2 :         desc = "Unknown interface";
     112            2 :         break;
     113            0 :     case CHIP_ERROR_NOT_IMPLEMENTED.AsInteger():
     114            0 :         desc = "Not implemented";
     115            0 :         break;
     116            2 :     case INET_ERROR_ADDRESS_NOT_FOUND.AsInteger():
     117            2 :         desc = "Address not found";
     118            2 :         break;
     119            1 :     case INET_ERROR_HOST_NAME_TOO_LONG.AsInteger():
     120            1 :         desc = "Host name too long";
     121            1 :         break;
     122            1 :     case INET_ERROR_INVALID_HOST_NAME.AsInteger():
     123            1 :         desc = "Invalid host name";
     124            1 :         break;
     125            0 :     case CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE.AsInteger():
     126            0 :         desc = "Not supported";
     127            0 :         break;
     128            0 :     case CHIP_ERROR_ENDPOINT_POOL_FULL.AsInteger():
     129            0 :         desc = "No more TCP endpoints";
     130            0 :         break;
     131            1 :     case INET_ERROR_IDLE_TIMEOUT.AsInteger():
     132            1 :         desc = "Idle timeout";
     133            1 :         break;
     134            0 :     case CHIP_ERROR_UNEXPECTED_EVENT.AsInteger():
     135            0 :         desc = "Unexpected event";
     136            0 :         break;
     137            1 :     case INET_ERROR_INVALID_IPV6_PKT.AsInteger():
     138            1 :         desc = "Invalid IPv6 Packet";
     139            1 :         break;
     140            1 :     case INET_ERROR_INTERFACE_INIT_FAILURE.AsInteger():
     141            1 :         desc = "Failure to initialize interface";
     142            1 :         break;
     143            1 :     case INET_ERROR_TCP_USER_TIMEOUT.AsInteger():
     144            1 :         desc = "TCP User Timeout";
     145            1 :         break;
     146            1 :     case INET_ERROR_TCP_CONNECT_TIMEOUT.AsInteger():
     147            1 :         desc = "TCP Connect Timeout";
     148            1 :         break;
     149            1 :     case INET_ERROR_INCOMPATIBLE_IP_ADDRESS_TYPE.AsInteger():
     150            1 :         desc = "Incompatible IP address type";
     151            1 :         break;
     152              :     }
     153              : #endif // !CHIP_CONFIG_SHORT_ERROR_STR
     154              : 
     155           30 :     FormatError(buf, bufSize, "Inet", err, desc);
     156              : 
     157           30 :     return true;
     158              : }
     159              : 
     160              : } // namespace Inet
     161              : } // namespace chip
        

Generated by: LCOV version 2.0-1