1 /** 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_GUARD_UTIL_ERROR_H 17 #define PANDA_GUARD_UTIL_ERROR_H 18 19 #include <sstream> 20 #include <string_view> 21 22 namespace panda::guard { 23 24 enum class ErrorCode { 25 CONFIG_FILE_FORMAT_ERROR = 11303001, 26 CONFIG_FILE_CONTENT_EMPTY = 11303002, 27 NOT_CONFIGURED_OBFUSCATION_RULES = 11303003, 28 NOT_CONFIGURED_ABC_FILE_PATH = 11303004, 29 NOT_CONFIGURED_OBF_ABC_FILE_PATH = 11303005, 30 NOT_CONFIGURED_TARGET_API_VERSION = 11303006, 31 NOT_CONFIGURED_DEFAULT_AND_PRINT_NAME_CACHE_PATH = 11303007, 32 NOT_CONFIGURED_REQUIRED_FIELD = 11303008, 33 NAME_CACHE_FILE_FORMAT_ERROR = 11303009, 34 COMMAND_PARAMS_PARSE_ERROR = 11310010, 35 36 GENERIC_ERROR = 11310001, 37 }; 38 39 class Error { 40 public: Error(ErrorCode code,std::string_view tag)41 Error(ErrorCode code, std::string_view tag) : errorCode_(code), tag_(tag) {} 42 43 std::ostream &GetDescStream(); 44 45 std::ostream &GetCauseStream(); 46 47 std::ostream &GetSolutionsStream(); 48 49 void Print(); 50 51 private: 52 void PrintGenericError(); 53 54 ErrorCode errorCode_; 55 56 std::string_view tag_; 57 58 std::stringstream descStream_; 59 60 std::stringstream causeStream_; 61 62 std::stringstream solutionsStream_; 63 }; 64 65 } // namespace panda::guard 66 67 #endif // PANDA_GUARD_UTIL_ERROR_H 68