{"record":{"id":"e6475a90653d2536","repo":"hasura/graphql-engine","slug":"unable-to-serialize-to-json-0","errorCode":null,"errorMessage":"unable to serialize to json: {0}","messagePattern":"unable to serialize to json: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/crates/graphql/lang-graphql/src/generate_graphql_schema.rs","lineNumber":23,"sourceCode":"use json_ext;\nuse std::collections::BTreeMap;\nuse std::sync::OnceLock;\nuse tracing_util::SpanVisibility;\nuse tracing_util::{ErrorVisibility, TraceableError};\n\n#[derive(Debug, thiserror::Error)]\npub enum Error {\n    #[error(\"unable to parse introspection query: {0}\")]\n    ParseIntrospectionQuery(String),\n    #[error(\"unable to normalize introspection query: {0}\")]\n    NormalizeIntrospectionQuery(String),\n    #[error(\"unable to find field call\")]\n    FieldCallNotFound,\n    #[error(\"Only __schema field is expected but found: {name:}\")]\n    OnlySchemaFieldExpected { name: String },\n    #[error(\"introspection query failed: {0}\")]\n    IntrospactionQueryError(#[from] crate::introspection::Error),\n    #[error(\"unable to serialize to json: {0}\")]\n    SerializeJson(#[from] serde_json::Error),\n}\nimpl TraceableError for Error {\n    fn visibility(&self) -> ErrorVisibility {\n        ErrorVisibility::User\n    }\n}\n\n/// Generate GraphQL schema for a given namespace\npub fn build_namespace_schema<\n    S: crate::schema::SchemaContext,\n    NSGet: crate::schema::NamespacedGetter<S>,\n>(\n    namespaced_getter: &NSGet,\n    schema: &crate::schema::Schema<S>,\n) -> Result<serde_json::Value, Error> {\n    let tracer = tracing_util::global_tracer();\n    tracer.in_span(","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/graphql/lang-graphql/src/generate_graphql_schema.rs#L5-L41","documentation":"Serializing the introspection response to JSON failed (serde_json::Error). The introspection result could not be written to JSON, usually because a value in the schema response is not JSON-representable or contains an invalid value (e.g. invalid UTF-8 string in a name/description).","triggerScenarios":"Executing introspection on a schema whose names or descriptions contain invalid UTF-8 or other non-serializable content; map keys colliding in an unexpected way in the response.","commonSituations":"Metadata descriptions sourced from files with bad encodings; schema strings built from raw byte data.","solutions":["Check the inner serde_json error to find the offending value","Fix invalid UTF-8 or unserializable content in schema names/descriptions/metadata","Regenerate metadata from clean sources"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate metadata strings are valid UTF-8 before applying\nif (!Buffer.from(name, 'utf8').toString('utf8') === name) throw new Error('bad encoding');","typeGuard":"const isSafeUtf8 = (s) => { try { new TextEncoder().encode(s); return s === new TextDecoder().decode(new TextEncoder().encode(s)); } catch { return false; } };","tryCatchPattern":"// Catch, read the serde_json inner error to locate the unserializable value","preventionTips":["Keep descriptions/names in valid UTF-8","Source metadata from clean files"],"tags":["graphql","introspection","json","serialization"],"backgroundTag":"json-serialization-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}