LCOV - code coverage report
Current view: top level - wirestead/wrapper - error_context_builder.hpp (source / functions) Coverage Total Hit
Test: Wirestead Coverage Report Lines: 100.0 % 5 5
Test Date: 2026-08-30 10:35:09 Functions: 100.0 % 1 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 75.0 % 4 3

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright 2025 Jinwoo Sung
       3                 :             :  *
       4                 :             :  * Licensed under the Apache License, Version 2.0 (the "License");
       5                 :             :  * you may not use this file except in compliance with the License.
       6                 :             :  * You may obtain a copy of the License at
       7                 :             :  *
       8                 :             :  *     http://www.apache.org/licenses/LICENSE-2.0
       9                 :             :  *
      10                 :             :  * Unless required by applicable law or agreed to in writing, software
      11                 :             :  * distributed under the License is distributed on an "AS IS" BASIS,
      12                 :             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13                 :             :  * See the License for the specific language governing permissions and
      14                 :             :  * limitations under the License.
      15                 :             :  */
      16                 :             : 
      17                 :             : #pragma once
      18                 :             : 
      19                 :             : #include <optional>
      20                 :             : #include <string_view>
      21                 :             : 
      22                 :             : #include "wirestead/diagnostics/error_mapping.hpp"
      23                 :             : #include "wirestead/interface/channel.hpp"
      24                 :             : #include "wirestead/wrapper/context.hpp"
      25                 :             : 
      26                 :             : // Shared replacement for the per-wrapper dynamic_pointer_cast<TcpClient>/
      27                 :             : // <UdsClient> special-casing (previously the only two transports whose
      28                 :             : // wrapper could report a detailed ErrorContext) and every other wrapper's
      29                 :             : // independent hardcoded generic-string fallback (jwsung91/wirestead#445).
      30                 :             : // Works uniformly now that interface::Channel::last_error_info() is
      31                 :             : // virtual - no cast to a concrete transport type needed.
      32                 :             : namespace wirestead {
      33                 :             : namespace wrapper {
      34                 :             : namespace detail {
      35                 :             : 
      36                 :         118 : inline ErrorContext build_error_context(const interface::Channel& channel, std::string_view fallback_message,
      37                 :             :                                         std::optional<ClientId> client_id = std::nullopt) {
      38   [ +  -  +  + ]:         118 :   if (auto info = channel.last_error_info()) {
      39                 :          19 :     return diagnostics::to_error_context(*info, client_id);
      40                 :         118 :   }
      41                 :          99 :   return ErrorContext(ErrorCode::IoError, fallback_message, client_id);
      42                 :             : }
      43                 :             : 
      44                 :             : }  // namespace detail
      45                 :             : }  // namespace wrapper
      46                 :             : }  // namespace wirestead
        

Generated by: LCOV version 2.0-1