Add an error handling logic of stod
Very rarely this error comes in host power cycle stress tests:
intel-obmc cpusensor[234]: terminate called after throwing an instance of 'std::invalid_argument'
intel-obmc cpusensor[234]: what(): stod
intel-obmc systemd[1]: xyz.openbmc_project.cpusensor.service: Main process exited, code=killed, status=6/ABRT
intel-obmc systemd[1]: xyz.openbmc_project.cpusensor.service: Failed with result 'signal'.
To handle this case gracefully, this commit adds an exceptional error
handling logic.
Tested: CPU sensor service worked well.
Change-Id: Id65b9b6ee65386f81e966eca1d13586248d2af07
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index f07f086..4ae1acb 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -347,7 +347,16 @@
Level level;
Direction direction;
- double val = std::stod(attr) / scaleFactor;
+ double val;
+ try
+ {
+ val = std::stod(attr) / scaleFactor;
+ }
+ catch (const std::invalid_argument&)
+ {
+ return false;
+ }
+
if (type == "min" || type == "max")
{
level = Level::WARNING;
@@ -377,7 +386,7 @@
thresholdVector.emplace_back(level, direction, val);
}
- // no thresholds is allowed, not an error so return true always
+ // no thresholds is allowed, not an error so return true.
return true;
}