{"record":{"id":"b18e21e9a94fa49f","repo":"prestodb/presto","slug":"out-of-range-classname-typename-fieldname","errorCode":null,"errorMessage":"{out_of_range} {className} {typeName} {fieldName}","messagePattern":"\\{out_of_range\\} \\{className\\} \\{typeName\\} \\{fieldName\\}","errorType":"validation","errorClass":"OutOfRange","httpStatus":null,"severity":"error","filePath":"presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.h","lineNumber":189,"sourceCode":"  }\n}\n\ntemplate <typename T>\nvoid from_json_key(\n    const json& j,\n    const char* key,\n    T& value,\n    const char* className,\n    const char* typeName,\n    const char* fieldName) {\n  try {\n    from_json_key(j, key, value);\n  } catch (json::type_error& e) {\n    throw TypeError(\n        std::string(e.what()) + \" \" + className + \" \" + typeName + \" \" +\n        fieldName);\n  } catch (json::out_of_range& e) {\n    throw OutOfRange(\n        std::string(e.what()) + \" \" + className + \" \" + typeName + \" \" +\n        fieldName);\n  }\n}\n\nstruct KeyedSubclass {\n  std::string _type; // This member holds the subtype that was serialized.\n\n  std::string getSubclassKey(const json& j);\n  virtual ~KeyedSubclass() {}\n};\n\nstruct JsonEncodedSubclass : public KeyedSubclass {\n  std::string getSubclassKey(const json& j);\n};\n\nstruct Base64EncodedSubclass : public KeyedSubclass {\n  std::string getSubclassKey(const json& j);","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.h#L171-L207","documentation":"This OutOfRange is thrown when json::out_of_range escapes from_json_key while deserializing a keyed field. In nlohmann json, out_of_range almost always means a required key (via j.at(key)) is missing from the JSON object. The error is re-thrown as OutOfRange with className, typeName, and fieldName appended, identifying which protocol field was missing.","triggerScenarios":"from_json on a payload where a mandatory key inside a keyed field is absent — e.g. the coordinator omits a field the native protocol struct requires via j.at().","commonSituations":"Coordinator and native worker version mismatch (field added on one side only); connector omitting optional fields the native side treats as required; hand-written or filtered JSON payloads.","solutions":["Read the appended fieldName to identify the missing key, then check why the producer omits it","Align coordinator and native worker versions","Make the field optional in the native struct (std::optional + contains() check) if it is legitimately optional","Validate incoming JSON against the expected schema before deserialization"],"exampleFix":"// before: throws when key missing\nvalue = j.at(\"requiredField\").get<std::string>();\n// after\nvalue = j.value(\"requiredField\", std::string{}); // or optional + contains check","handlingStrategy":"validation","validationCode":"// verify required keys exist before from_json\nfor (const std::string& required : {\"type\", \"requiredField\"}) {\n  if (!j.contains(required)) {\n    throw std::runtime_error(\"missing required key: \" + required);\n  }\n}","typeGuard":"bool hasKey(const json& j, const std::string& key) {\n  return j.is_object() && j.contains(key);\n}","tryCatchPattern":"try {\n  from_json(j, obj);\n} catch (const OutOfRange& e) {\n  // message ends with className typeName fieldName naming the missing key\n  LOG(ERROR) << \"missing JSON key: \" << e.what();\n  throw;\n}","preventionTips":["Prefer j.value(key, default) or contains() checks for optional fields","Use std::optional in protocol structs for fields that may be absent","Keep producer and consumer protocol versions in sync","Validate payloads against the expected schema before deserialization"],"tags":["json","deserialization","out-of-range","missing-key"],"backgroundTag":"missing-json-key","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}