Catch a null schema more gracefully
We were dereferencing the null pointer. It gives a rather cryptic
error. We can do a lot better.
Change-Id: I1aae2109cee6aa9f972d4e149a5779df42ab7d36
diff --git a/aos/flatbuffer_introspection.cc b/aos/flatbuffer_introspection.cc
index 6f32424..ae402fe 100644
--- a/aos/flatbuffer_introspection.cc
+++ b/aos/flatbuffer_introspection.cc
@@ -351,6 +351,14 @@
std::string FlatbufferToJson(const reflection::Schema *schema,
const uint8_t *data, bool multi_line,
size_t max_vector_size) {
+ CHECK(schema != nullptr) << ": Need to provide a schema";
+
+ // It is pretty common to get passed in a nullptr when a test fails. Rather
+ // than CHECK, return a more user friendly result.
+ if (data == nullptr) {
+ return "null";
+ }
+
const flatbuffers::Table *table = flatbuffers::GetAnyRoot(data);
const reflection::Object *obj = schema->root_table();