summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-intel/smbios/smbios-mdrv2/0001-Replace-throw-with-log-error-message.patch
blob: 9cf75563e5f6c4a4989f3b8b22067c802c4f97d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
From b84c3bd333a7b67d7b7ff73e12c382aa529f3e5c Mon Sep 17 00:00:00 2001
From: Kuiying Wang <kuiying.wang@intel.com>
Date: Tue, 20 Oct 2020 15:44:41 +0800
Subject: [PATCH] Replace throw with log error message.

Replace throw with log error message and return.
When run into error, log error message but not crash
smbios service as throw did.

Tested:
smbiosmdrv2app is working well.

Change-Id: Ia2d40997987a0c84a613568d65f93006043459d0
Signed-off-by: Kuiying Wang <kuiying.wang@intel.com>
---
 src/mdrv2.cpp | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/mdrv2.cpp b/src/mdrv2.cpp
index 9a73c65..c1bc09d 100644
--- a/src/mdrv2.cpp
+++ b/src/mdrv2.cpp
@@ -35,8 +35,9 @@ std::vector<uint8_t> MDR_V2::getDirectoryInformation(uint8_t dirIndex)
     if (dirIndex > smbiosDir.dirEntries)
     {
         responseDir.push_back(0);
-        throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
-            InvalidParameter();
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "getDirectoryInformation: Invalid Parameter");
+        return responseDir;
     }
     responseDir.push_back(mdr2Version);
     responseDir.push_back(smbiosDir.dirVersion);
@@ -117,8 +118,6 @@ std::vector<uint8_t> MDR_V2::getDataOffer()
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "smbios is not ready for update");
-        throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
-            UpdateInProgress();
     }
     return offer;
 }
@@ -173,8 +172,9 @@ std::vector<uint8_t> MDR_V2::getDataInformation(uint8_t idIndex)
 
     if (idIndex >= maxDirEntries)
     {
-        throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
-            InvalidParameter();
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "getDataInformation: Invalid Parameter");
+        return responseInfo;
     }
 
     for (uint8_t index = 0; index < sizeof(DataIdStruct); index++)
@@ -253,15 +253,13 @@ bool MDR_V2::sendDirectoryInformation(uint8_t dirVersion, uint8_t dirIndex,
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "Send Dir info failed - input parameter invalid");
-        throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
-            InvalidParameter();
+        return teminate;
     }
     if (dirEntry.size() < sizeof(Mdr2DirEntry))
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "Directory size invalid");
-        throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
-            InvalidParameter();
+        return teminate;
     }
     if (dirVersion == smbiosDir.dirVersion)
     {
@@ -307,8 +305,9 @@ bool MDR_V2::sendDataInformation(uint8_t idIndex, uint8_t flag,
 {
     if (idIndex >= maxDirEntries)
     {
-        throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
-            InvalidParameter();
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "sendDataInformation:  Invalid Parameter");
+        return false;
     }
     int entryChanged = 0;
     if (smbiosDir.dir[idIndex].common.dataSetSize != dataLen)
@@ -341,8 +340,7 @@ int MDR_V2::findIdIndex(std::vector<uint8_t> dataInfo)
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
             "Length of dataInfo invalid");
-        throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
-            InvalidParameter();
+        return -1;
     }
     std::array<uint8_t, 16> arrayDataInfo;
 
@@ -364,7 +362,9 @@ int MDR_V2::findIdIndex(std::vector<uint8_t> dataInfo)
             return index;
         }
     }
-    throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::InvalidId();
+    phosphor::logging::log<phosphor::logging::level::ERR>(
+        "findIdIndex: Invalid ID");
+    return -1;
 }
 
 uint8_t MDR_V2::directoryEntries(uint8_t value)
@@ -546,7 +546,9 @@ std::vector<boost::container::flat_map<std::string, RecordVariant>>
 
         if (dataIn == nullptr)
         {
-            throw std::runtime_error("Data not populated");
+            phosphor::logging::log<phosphor::logging::level::ERR>(
+                "Data not populated");
+            return ret;
         }
 
         do
@@ -617,7 +619,8 @@ std::vector<boost::container::flat_map<std::string, RecordVariant>>
         return ret;
     }
 
-    throw std::invalid_argument("Invalid record type");
+    phosphor::logging::log<phosphor::logging::level::ERR>(
+        "Invalid record type");
     return ret;
 }
 
-- 
2.7.4