LCOV - code coverage report
Current view: top level - adump/common - adump_error_manager.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.7 % 7 6
Test Date: 2026-08-31 10:09:28 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : #ifndef ADUMP_ERROR_MANAGER_H
      11              : #define ADUMP_ERROR_MANAGER_H
      12              : #include <string>
      13              : #include <vector>
      14              : #include "base/err_msg.h"
      15              : #include "str_utils.h"
      16              : #include "log/adx_log.h"
      17              : 
      18              : namespace Adx {
      19              : // REPORT_PREDEFINED_ERR_MSG takes std::vector<const char *>, while the REPORT_EP000x_* macros below
      20              : // pass std::vector<std::string>. Converting here keeps those macros unchanged.
      21         1254 : inline std::vector<const char*> ToCStrVec(const std::vector<std::string>& in)
      22              : {
      23         1254 :     std::vector<const char*> out;
      24         1254 :     out.reserve(in.size());
      25         6516 :     for (const auto& s : in) {
      26         4008 :         out.emplace_back(s.c_str());
      27              :     }
      28         1254 :     return out;
      29            0 : }
      30              : } // namespace Adx
      31              : 
      32              : // Named locals before c_str(): every caller builds the vectors inline as temporaries. Binding them
      33              : // to the do/while block makes the lifetime explicit rather than relying on full-expression scope.
      34              : #define ADUMP_INPUT_ERROR(error_code, key, value)                                                                \
      35              :     do {                                                                                                         \
      36              :         const std::vector<std::string> adumpErrKeys__ = (key);                                                   \
      37              :         const std::vector<std::string> adumpErrVals__ = (value);                                                 \
      38              :         REPORT_PREDEFINED_ERR_MSG((error_code), Adx::ToCStrVec(adumpErrKeys__), Adx::ToCStrVec(adumpErrVals__)); \
      39              :     } while (0)
      40              : 
      41              : namespace Adx {
      42              : 
      43              : #define ADUMP_TO_CSTR(s) (std::string(s).c_str())
      44              : 
      45              : // EP0004 Parse Error Report Macro - Inline for performance
      46              : #define REPORT_EP0004_PARSE_ERROR(moduleName, reason, configPath)                                                    \
      47              :     do {                                                                                                             \
      48              :         IDE_LOGE("[%s] Parse failed: %s", moduleName, ADUMP_TO_CSTR(reason));                                        \
      49              :         ADUMP_INPUT_ERROR(                                                                                           \
      50              :             "EP0004", std::vector<std::string>({"path", "reason"}), std::vector<std::string>({configPath, reason})); \
      51              :     } while (0)
      52              : 
      53              : // EP0001 Configuration Item Error Report Macro - Inline for performance
      54              : #define REPORT_EP0001_ITEM_ERROR(moduleName, item, reason, configPath)                                        \
      55              :     do {                                                                                                      \
      56              :         IDE_LOGE(                                                                                             \
      57              :             "[%s] The content of configuration item %s in config file %s is invalid. Reason: %s", moduleName, \
      58              :             ADUMP_TO_CSTR(item), configPath, ADUMP_TO_CSTR(reason));                                          \
      59              :         ADUMP_INPUT_ERROR(                                                                                    \
      60              :             "EP0001", std::vector<std::string>({"item", "path", "reason"}),                                   \
      61              :             std::vector<std::string>({item, configPath, reason}));                                            \
      62              :     } while (0)
      63              : 
      64              : // EP0002 Enum Value Invalid Report Macro - Inline for performance
      65              : #define REPORT_EP0002_ENUM_VALUE_INVALID(moduleName, value, item, expectedValue, configPath)                          \
      66              :     do {                                                                                                              \
      67              :         IDE_LOGE(                                                                                                     \
      68              :             "[%s] Value %s for configuration item %s in file %s is invalid, must be selected from [%s].", moduleName, \
      69              :             ADUMP_TO_CSTR(value), ADUMP_TO_CSTR(item), configPath, ADUMP_TO_CSTR(expectedValue));                     \
      70              :         ADUMP_INPUT_ERROR(                                                                                            \
      71              :             "EP0002", std::vector<std::string>({"value", "item", "path", "expected_value"}),                          \
      72              :             std::vector<std::string>({value, item, configPath, expectedValue}));                                      \
      73              :     } while (0)
      74              : 
      75              : // EP0003 Value Invalid Report Macro - Inline for performance
      76              : #define REPORT_EP0003_INVALID_VALUE(moduleName, value, item, reason, configPath)                   \
      77              :     do {                                                                                           \
      78              :         IDE_LOGE(                                                                                  \
      79              :             "[%s] Value %s for parameter %s in config file %s is invalid. Reason: %s", moduleName, \
      80              :             ADUMP_TO_CSTR(value), ADUMP_TO_CSTR(item), configPath, ADUMP_TO_CSTR(reason));         \
      81              :         ADUMP_INPUT_ERROR(                                                                         \
      82              :             "EP0003", std::vector<std::string>({"value", "item", "path", "reason"}),               \
      83              :             std::vector<std::string>({value, item, configPath, reason}));                          \
      84              :     } while (0)
      85              : 
      86              : // EP0005 Conflict Report Macros - Inline for performance
      87              : #define REPORT_EP0005_ITEM_CANNOT_SET_WHEN_ITEM_SET(moduleName, errorItem, conditionItem, configPath)                \
      88              :     do {                                                                                                             \
      89              :         std::string reason = StrUtils::Format(                                                                       \
      90              :             ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_SET, ADUMP_TO_CSTR(errorItem), ADUMP_TO_CSTR(conditionItem)); \
      91              :         IDE_LOGE("[%s] %s", moduleName, reason.c_str());                                                             \
      92              :         ADUMP_INPUT_ERROR(                                                                                           \
      93              :             "EP0005", std::vector<std::string>({"path", "reason"}), std::vector<std::string>({configPath, reason})); \
      94              :     } while (0)
      95              : 
      96              : #define REPORT_EP0005_ITEM_CANNOT_SET_WHEN_ITEM_VALUE(                                                               \
      97              :     moduleName, errorItem, conditionItem, conditionValue, configPath)                                                \
      98              :     do {                                                                                                             \
      99              :         std::string reason = StrUtils::Format(                                                                       \
     100              :             ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_VALUE, ADUMP_TO_CSTR(conditionItem),                          \
     101              :             ADUMP_TO_CSTR(conditionValue), ADUMP_TO_CSTR(errorItem));                                                \
     102              :         IDE_LOGE("[%s] %s", moduleName, reason.c_str());                                                             \
     103              :         ADUMP_INPUT_ERROR(                                                                                           \
     104              :             "EP0005", std::vector<std::string>({"path", "reason"}), std::vector<std::string>({configPath, reason})); \
     105              :     } while (0)
     106              : 
     107              : #define REPORT_EP0005_ITEM_CANNOT_SET_WHEN_ITEM_NOT_VALUE(                                                           \
     108              :     moduleName, errorItem, conditionItem, conditionValue, configPath)                                                \
     109              :     do {                                                                                                             \
     110              :         std::string reason = StrUtils::Format(                                                                       \
     111              :             ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_NOT_VALUE, ADUMP_TO_CSTR(conditionItem),                      \
     112              :             ADUMP_TO_CSTR(conditionValue), ADUMP_TO_CSTR(errorItem));                                                \
     113              :         IDE_LOGE("[%s] %s", moduleName, reason.c_str());                                                             \
     114              :         ADUMP_INPUT_ERROR(                                                                                           \
     115              :             "EP0005", std::vector<std::string>({"path", "reason"}), std::vector<std::string>({configPath, reason})); \
     116              :     } while (0)
     117              : 
     118              : #define REPORT_EP0005_ITEM_VALUE_CANNOT_SET_WHEN_ITEM_VALUE(                                                         \
     119              :     moduleName, errorItem, errorValue, conditionItem, conditionValue, configPath)                                    \
     120              :     do {                                                                                                             \
     121              :         std::string reason = StrUtils::Format(                                                                       \
     122              :             ADUMP_REASON_FMT_ITEM_VALUE_CANNOT_SET_WHEN_ITEM_VALUE, ADUMP_TO_CSTR(conditionItem),                    \
     123              :             ADUMP_TO_CSTR(conditionValue), ADUMP_TO_CSTR(errorItem), ADUMP_TO_CSTR(errorValue));                     \
     124              :         IDE_LOGE("[%s] %s", moduleName, reason.c_str());                                                             \
     125              :         ADUMP_INPUT_ERROR(                                                                                           \
     126              :             "EP0005", std::vector<std::string>({"path", "reason"}), std::vector<std::string>({configPath, reason})); \
     127              :     } while (0)
     128              : 
     129              : #define REPORT_EP0006_INVALID_ARGUMENT(funcName, value, param, reason)                                   \
     130              :     do {                                                                                                 \
     131              :         IDE_LOGE(                                                                                        \
     132              :             "[%s] %s failed. Value %s for parameter %s is invalid. Reason: %s", ADUMP_TO_CSTR(funcName), \
     133              :             ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(value), ADUMP_TO_CSTR(param), ADUMP_TO_CSTR(reason)); \
     134              :         ADUMP_INPUT_ERROR(                                                                               \
     135              :             "EP0006", std::vector<std::string>({"func", "value", "param", "reason"}),                    \
     136              :             std::vector<std::string>({funcName, value, param, reason}));                                 \
     137              :     } while (0)
     138              : 
     139              : #define REPORT_EP0007_NULL_POINTER(funcName, param)                                                                  \
     140              :     do {                                                                                                             \
     141              :         IDE_LOGE(                                                                                                    \
     142              :             "[%s] %s failed because %s cannot be a NULL pointer.", ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(funcName), \
     143              :             ADUMP_TO_CSTR(param));                                                                                   \
     144              :         ADUMP_INPUT_ERROR(                                                                                           \
     145              :             "EP0007", std::vector<std::string>({"func", "param"}), std::vector<std::string>({funcName, param}));     \
     146              :     } while (0)
     147              : 
     148              : #define REPORT_EP0008_API_CALL_SEQUENCE(funcName, reason)                                                            \
     149              :     do {                                                                                                             \
     150              :         IDE_LOGE(                                                                                                    \
     151              :             "[%s] %s failed. Reason: %s.", ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(funcName), ADUMP_TO_CSTR(reason)); \
     152              :         ADUMP_INPUT_ERROR(                                                                                           \
     153              :             "EP0008", std::vector<std::string>({"func", "reason"}),                                                  \
     154              :             std::vector<std::string>({std::string(funcName), std::string(reason)}));                                 \
     155              :     } while (0)
     156              : 
     157              : // EP0001 Reasons - Configuration item problems
     158              : constexpr const char* ADUMP_REASON_ITEM_NOT_FOUND = "The configuration item is not found";
     159              : constexpr const char* ADUMP_REASON_ITEM_VALUE_EMPTY = "The configuration item value is empty";
     160              : constexpr const char* ADUMP_REASON_ITEM_MUST_BE_STRING = "This configuration item must be of the string type";
     161              : constexpr const char* ADUMP_REASON_ITEM_MUST_BE_ARRAY = "This configuration item must be of the array type";
     162              : constexpr const char* ADUMP_REASON_ITEM_MUST_BE_OBJECT = "This configuration item must be of the object type";
     163              : constexpr const char* ADUMP_REASON_MEMBER_MUST_BE_STRING = "The member type of this configuration item must be string";
     164              : constexpr const char* ADUMP_REASON_MEMBER_MUST_BE_OBJECT = "The member type of this configuration item must be object";
     165              : 
     166              : // EP0003 Reasons - Value validity problems
     167              : constexpr const char* ADUMP_REASON_VALUE_INVALID_CHARS = "The value contains invalid characters";
     168              : constexpr const char* ADUMP_REASON_PATH_NOT_EXIST = "The path does not exist";
     169              : constexpr const char* ADUMP_REASON_PATH_NO_PERMISSION = "The value is a path without read and write permissions";
     170              : constexpr const char* ADUMP_REASON_PATH_INVALID = "The value is an invalid path";
     171              : constexpr const char* ADUMP_REASON_PATH_NOT_DIRECTORY = "The path is not a directory path";
     172              : constexpr const char* ADUMP_REASON_PATH_LENGTH_EXCEED_LIMIT =
     173              :     "The path length exceeds the maximum limit of 512 characters";
     174              : constexpr const char* ADUMP_REASON_DUMP_STEP_EXCEED_LIMIT = "The value exceeds the maximum limit of 100 intervals";
     175              : constexpr const char* ADUMP_REASON_DUMP_STEP_INVALID_FORMAT = "The value has invalid format, expected format: 5-10";
     176              : constexpr const char* ADUMP_REASON_DUMP_STEP_NOT_DIGIT =
     177              :     "The value contains non-digit characters,  expected format: 1 or 5-10";
     178              : constexpr const char* ADUMP_REASON_DUMP_STEP_INVALID_RANGE =
     179              :     "The value has invalid format, start step must not exceed end step, expected format: 5-10";
     180              : constexpr const char* ADUMP_REASON_BLACKLIST_SIZE_EXCEED_LIMIT = "The value size exceeds the maximum limit of 100";
     181              : constexpr const char* ADUMP_REASON_BLACKLIST_POS_INVALID_FORMAT =
     182              :     "The value has invalid format, the prefix must be input or output, expected format: inputn or outputn";
     183              : constexpr const char* ADUMP_REASON_BLACKLIST_POS_INDEX_NOT_DIGIT =
     184              :     "The value has invalid format, the index must be a digit, expected format: input1 or output1";
     185              : constexpr const char* ADUMP_REASON_OPNAME_RANGE_INCOMPLETE =
     186              :     "The item is incomplete, begin and end must be configured together and non-empty";
     187              : 
     188              : // EP0005 Reason Templates - Configuration conflict
     189              : constexpr const char* ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_SET =
     190              :     "Configuration items %s and %s cannot be configured";
     191              : constexpr const char* ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_VALUE =
     192              :     "When configuration item %s is set to %s, configuration item %s cannot be configured";
     193              : constexpr const char* ADUMP_REASON_FMT_ITEM_CANNOT_SET_WHEN_ITEM_NOT_VALUE =
     194              :     "When configuration item %s is not set to %s, configuration item %s cannot be configured";
     195              : constexpr const char* ADUMP_REASON_FMT_ITEM_VALUE_CANNOT_SET_WHEN_ITEM_VALUE =
     196              :     "When configuration item %s is set to %s, configuration item %s cannot be set to %s";
     197              : 
     198              : // EP0006 Reasons - Invalid argument problems
     199              : constexpr const char* ADUMP_REASON_RESERVED_PARAM_MUST_EQUAL = "The parameter is reserved and can only be %s";
     200              : constexpr const char* ADUMP_REASON_PARAM_PATH_EMPTY = "The parameter is a path and cannot be empty";
     201              : constexpr const char* ADUMP_REASON_PARAM_PATH_HAS_PARENT_DIR =
     202              :     "The parameter is a relative path and cannot contain '..' segment";
     203              : constexpr const char* ADUMP_REASON_PARAM_PATH_CREATE_DIR_ERROR =
     204              :     "The parameter is a path and the path fails to be created. Error: %s";
     205              : constexpr const char* ADUMP_REASON_PARAM_PATH_NOT_DIRECTORY = "The parameter is not a directory path";
     206              : constexpr const char* ADUMP_REASON_PARAM_MUST_BE_GREATER_THAN = "The parameter must be greater than %s";
     207              : constexpr const char* ADUMP_REASON_BUFFER_SIZE_NOT_ENOUGH = "The buffer size %s is not enough for the result size %s";
     208              : constexpr const char* ADUMP_REASON_PARAM_VALUE_EXCEED_LIMIT = "The value %s exceeds the maximum limit of %s";
     209              : constexpr const char* ADUMP_REASON_PARAM_VALUE_NOT_SUPPORTED = "The value %s is not supported, it must be %s";
     210              : 
     211              : // EP0008 Reasons - Call API sequence
     212              : constexpr const char* ADUMP_REASON_API_CALLED_REPEATEDLY = "This API cannot be called repeatedly";
     213              : constexpr const char* ADUMP_REASON_EXCEPTION_DUMP_NOT_ENABLED = "Exception Dump must be enabled before %s is called";
     214              : 
     215              : constexpr const char* FUNC_NAME_ACL_OP_START_DUMP_ARGS = "aclopStartDumpArgs";
     216              : constexpr const char* FUNC_ACL_OP_START_DUMP_ARGS_PARAM_PATH = "path";
     217              : constexpr const char* FUNC_ACL_OP_START_DUMP_ARGS_PARAM_DUMPTYPE = "dumpType";
     218              : constexpr const char* FUNC_NAME_ACL_DUMP_REG_CALLBACK = "acldumpRegCallback";
     219              : constexpr const char* FUNC_ACL_DUMP_REG_CALLBACK_PARAM_CLBK = "messageCallback";
     220              : constexpr const char* FUNC_ACL_DUMP_REG_CALLBACK_PARAM_FLAG = "flag";
     221              : constexpr const char* FUNC_NAME_ACL_DUMP_SAVE_EXCEPTION_INFO = "acldumpSaveExceptionInfo";
     222              : constexpr const char* FUNC_ACL_DUMP_SAVE_EXCEPTION_INFO_PARAM_FILENAME = "fileName";
     223              : constexpr const char* FUNC_ACL_DUMP_SAVE_EXCEPTION_INFO_PARAM_TENSORS = "tensors";
     224              : constexpr const char* FUNC_ACL_DUMP_SAVE_EXCEPTION_INFO_PARAM_TENSORCOUNT = "tensorCount";
     225              : constexpr const char* FUNC_NAME_ACL_DUMP_GET_EXCEPTION_INFO_PATH = "acldumpGetExceptionInfoPath";
     226              : constexpr const char* FUNC_ACL_DUMP_GET_EXCEPTION_INFO_PATH_PARAM_PATH = "path";
     227              : constexpr const char* FUNC_ACL_DUMP_GET_EXCEPTION_INFO_PATH_PARAM_MAXLEN = "maxLen";
     228              : } // namespace Adx
     229              : 
     230              : #endif
        

Generated by: LCOV version 2.0-1