prestodb/presto · error · TypeError
{type_error} {className} {typeName} {fieldName}
Error message
{type_error} {className} {typeName} {fieldName} What it means
This TypeError is thrown by the keyed-serialization helper when to_json_key raises a json::type_error while serializing a map/keyed field. It is re-thrown as TypeError with the class name, type name, and field name appended, so you know exactly which protocol class/field failed to serialize. Typically the key or value type does not match what nlohmann json expects (e.g. serializing a non-string key, or a value whose to_json overload is missing/mismatched).
Source
Thrown at presto-native-execution/presto_cpp/presto_protocol/core/presto_protocol_core.h:156
template <typename T>
void to_json_key(json& j, const char* key, const std::shared_ptr<T>& value) {
if (value != nullptr) {
j[key] = value;
}
}
template <typename T>
void to_json_key(
json& j,
const char* key,
const T& value,
const char* className,
const char* typeName,
const char* fieldName) {
try {
to_json_key(j, key, value);
} catch (json::type_error& e) {
throw TypeError(
std::string(e.what()) + " " + className + " " + typeName + " " +
fieldName);
}
}
template <typename T>
void from_json_key(const json& j, const char* key, T& value) {
j.at(key).get_to(value);
}
template <typename T>
void from_json_key(const json& j, const char* key, std::shared_ptr<T>& value) {
if (j.count(key)) {
j.at(key).get_to(value);
}
}
template <typename T>View on GitHub (pinned to 55bb57d202)
Solutions
- Read the appended className/typeName/fieldName in the message to identify the failing field
- Add or fix the to_json/to_json_key overload for the field's type
- Ensure keys are std::string-convertible and values have valid serializers
- Test serialization of the struct in a unit test with representative data
Example fix
// before: field without serializer
struct MyParams { std::chrono::milliseconds ttl; };
// after: provide conversion
inline void to_json(json& j, const MyParams& p) { j = json{{"ttl", p.ttl.count()}}; } Defensive patterns
Strategy: try-catch
Validate before calling
// serialize a sample instance before sending json probe; to_json(probe, myProtocolObject); // fails fast on missing serializers
Type guard
bool serializable(const json& j) {
return !j.is_null() || /* field optional */ true;
} Try / catch
try {
to_json(j, obj);
} catch (const TypeError& e) {
// message carries className typeName fieldName
LOG(ERROR) << "serialization failed: " << e.what();
throw;
} Prevention
- Provide to_json overloads for every field type in protocol structs
- Keep map keys std::string-convertible
- Add round-trip (to_json -> from_json) unit tests for protocol structs
- Never serialize null where an object is required
When it happens
Trigger: Calling to_json on a protocol object with a keyed field (map-like) where the key or value cannot be converted by nlohmann json — e.g. wrong variant alternative, undefined json value assigned where an object is required, or key type not convertible to string.
Common situations: Adding a new field of an unsupported type to a protocol struct; a custom type lacking a to_json overload; nullptr/empty optional being serialized as json where an object is expected.
Related errors
- no abstract type ColumnHandle
- no abstract type FunctionHandle
- no abstract type RowExpression
- LANCE_ERROR
- PLAN_SERIALIZATION_ERROR
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/af533d230107fbbb.
Report an issue: GitHub.