• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "error.h"
17 
18 #include "utils/logger.h"
19 
GetDescStream()20 std::ostream &panda::guard::Error::GetDescStream()
21 {
22     return descStream_;
23 }
24 
GetCauseStream()25 std::ostream &panda::guard::Error::GetCauseStream()
26 {
27     return causeStream_;
28 }
29 
GetSolutionsStream()30 std::ostream &panda::guard::Error::GetSolutionsStream()
31 {
32     return solutionsStream_;
33 }
34 
Print()35 void panda::guard::Error::Print()
36 {
37     LOG(ERROR, PANDAGUARD) << tag_ << descStream_.str();
38 
39     if (errorCode_ == ErrorCode::GENERIC_ERROR) {
40         PrintGenericError();  // print to console without displaying internal details
41         return;
42     }
43 
44     std::stringstream ss;
45     ss << "[ErrorCode]:" << static_cast<int>(errorCode_) << std::endl;
46     ss << "[Description]:" << descStream_.str();
47     if (!causeStream_.str().empty()) {
48         ss << std::endl;
49         ss << "[Cause]:" << causeStream_.str();
50     }
51     if (!solutionsStream_.str().empty()) {
52         ss << std::endl;
53         ss << "[Solutions]:" << solutionsStream_.str();
54     }
55     std::cerr << ss.str() << std::endl;
56 }
57 
PrintGenericError()58 void panda::guard::Error::PrintGenericError()
59 {
60     std::stringstream ss;
61     ss << "[ErrorCode]:" << static_cast<int>(ErrorCode::GENERIC_ERROR) << std::endl;
62     ss << "[Description]:obfuscate failed" << std::endl;
63     std::cerr << ss.str() << std::endl;
64 }