diff --git a/google/cloud/functions/internal/parse_cloud_event_json.cc b/google/cloud/functions/internal/parse_cloud_event_json.cc index e1ea8fc0..2f979fd9 100644 --- a/google/cloud/functions/internal/parse_cloud_event_json.cc +++ b/google/cloud/functions/internal/parse_cloud_event_json.cc @@ -23,6 +23,12 @@ inline namespace FUNCTIONS_FRAMEWORK_CPP_NS { namespace { functions::CloudEvent ParseCloudEventJson(nlohmann::json const& json) { + if (!json.contains("id") || !json.contains("source") || + !json.contains("type")) { + throw std::runtime_error( + "JSON message missing `id`, `source`, and/or `type` fields"); + } + auto event = functions::CloudEvent( json.at("id").get(), json.at("source").get(), json.at("type").get(),