PEL: Add a try/catch to a nlohmann::json::dump()
In some automated system boot testing, there was an occurrence of:
```
An extension's create function threw an exception: [json.exception.type_error.316] invalid UTF-8 byte at index 56: 0x20
```
This is coming from nlohmann::json::dump(), though I'm not sure how an
invalid json object can even be constructed, since it would just fail
earlier.
This commit adds a try/catch around the only occurrence of dump() that
doesn't already have one, as seemingly this is where that exception has
to have come from.
Change-Id: I16095459091bcd1df033846517c3b822e504e6ff
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index fbedb8b..8b635e5 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -780,7 +780,17 @@
std::unique_ptr<UserData> makeJSONUserDataSection(const nlohmann::json& json)
{
- auto jsonString = json.dump();
+ std::string jsonString;
+ try
+ {
+ jsonString = json.dump();
+ }
+ catch (const std::exception& e)
+ {
+ lg2::error("json.dump() failed with: {ERROR}", "ERROR", e);
+ jsonString = "Invalid JSON passed to makeJSONUserDataSection!";
+ }
+
std::vector<uint8_t> jsonData(jsonString.begin(), jsonString.end());
// Pad to a 4 byte boundary