{"record":{"id":"9eb9a24bd335246d","repo":"t8y2/dbx","slug":"failed-to-read-enum-values-w","errorCode":null,"errorMessage":"failed to read enum values: %w","messagePattern":"failed to read enum values: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/kingbase_metadata.go","lineNumber":796,"sourceCode":"\tproperties.AnalyzeFunction = nullStringPtr(analyzeFn)\n\tif typlen.Valid && typlen.Int64 > 0 {\n\t\tvalue := int32(typlen.Int64)\n\t\tproperties.Internallength = &value\n\t}\n\tproperties.PassedByValue = &typbyval\n\tif typalign != \"\" {\n\t\tproperties.Alignment = &typalign\n\t}\n\tif typstorage != \"\" {\n\t\tproperties.Storage = &typstorage\n\t}\n\treturn properties\n}\n\nfunc (s *server) customTypeEnumMembers(sqlTemplate string, oid int64) ([]customTypeMember, error) {\n\trows, err := s.metadataQuery(fmt.Sprintf(sqlTemplate, oid))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read enum values: %w\", err)\n\t}\n\tdefer rows.Close()\n\tvar members []customTypeMember\n\tindex := 0\n\tfor rows.Next() {\n\t\tvar label string\n\t\tvar sortOrder float64\n\t\tif err := rows.Scan(&label, &sortOrder); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\t// enumsortorder is float4; ALTER TYPE ... ADD VALUE BEFORE/AFTER can\n\t\t// yield fractional values. Use the ORDER BY position for a unique key.\n\t\tindex++\n\t\tmembers = append(members, customTypeMember{Ordinal: int32(index), EnumValue: &label})\n\t}\n\treturn members, rows.Err()\n}\n","sourceCodeStart":778,"sourceCodeEnd":814,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/kingbase_metadata.go#L778-L814","documentation":"After getTypeDetails classifies a type as an enum, it runs customTypeEnumMembers, which executes the prebuilt enum-members catalog SQL (ordered by enumsortorder) via metadataQuery. If that query fails to execute, the error is wrapped with 'failed to read enum values' and returned, so the enum's member list cannot be produced.","triggerScenarios":"Calling the type details API on an enum type (typtype 'e') whose enum-label catalog query (e.g. pg_enum/sys_enum join) fails — wrong template interpolation of the OID, missing catalog table, insufficient privileges, or connection dropped mid-query.","commonSituations":"Restricted role lacking SELECT on enum catalogs; Kingbase instance where the enum catalog table name differs from the expected pg/sys schema layout; transient connection failure between the general type lookup and the members query.","solutions":["Read the wrapped inner error (%w) to see the underlying SQL/scan failure cause","Grant the connecting role SELECT on the enum catalog (pg_enum / sys_enum) and joined catalogs","Verify the server mode flag (postgresCatalog vs sys_catalog) matches the actual Kingbase instance layout","Retry the metadata call if the inner error indicates a transient connection issue"],"exampleFix":"// before\nrows, err := s.metadataQuery(fmt.Sprintf(sqlTemplate, oid))\n// after — ensure the query template matches the active catalog\nif rows == nil || err != nil { return nil, fmt.Errorf(\"failed to read enum values (oid=%d): %w\", oid, err) }","handlingStrategy":"try-catch","validationCode":"// ensure privileges and mode before the call\nif !roleCanSelect(\"pg_enum\", \"pg_type\") && !roleCanSelect(\"sys_enum\", \"sys_type\") { grantEnumCatalogAccess() }\nif driverModeMismatch() { reconfigureDriverMode() }","typeGuard":"func isEnumDetails(details *customTypeDetails) bool {\n  return details != nil && details.Kind == \"enum\"\n} // only then expect a non-error member list","tryCatchPattern":"details, err := server.GetTypeDetails(schema, name)\nif err != nil && strings.Contains(err.Error(), \"failed to read enum values\") {\n  if isTransient(err) { return retryWithBackoff() }\n  return fmt.Errorf(\"enum members unreadable for %s.%s: %w\", schema, name, err)\n}","preventionTips":["Grant SELECT on enum catalog tables to the introspection role","Match the driver's postgresCatalog/sys_catalog setting to the server deployment","Run metadata queries on a stable connection; retry transient failures with backoff"],"tags":["metadata","enum","catalog-query","kingbase"],"backgroundTag":"enum-catalog-query-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}