{"record":{"id":"baf242cd6567ba78","repo":"t8y2/dbx","slug":"list-custom-types-in-schema-q-w","errorCode":null,"errorMessage":"list custom types in schema %q: %w","messagePattern":"list custom types in schema %q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/kingbase_metadata.go","lineNumber":1156,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t\t_ = rows.Close()\n\t\t}\n\t}\n\tif constraintsAllowTriggers(constraints) {\n\t\ttriggers, triggerErr := s.listTriggerObjects(effective)\n\t\tif triggerErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"list triggers in schema %q: %w\", effective, triggerErr)\n\t\t}\n\t\tresult = append(result, triggers...)\n\t}\n\tif constraintsAllowTypes(constraints) {\n\t\ttypes, typesErr := s.listCustomTypes(effective)\n\t\tif typesErr != nil {\n\t\t\t// A type catalog failure is a real fault: surfacing it lets the user\n\t\t\t// distinguish an incomplete “all objects” view from an actually\n\t\t\t// empty schema, instead of silently dropping the type group.\n\t\t\treturn nil, fmt.Errorf(\"list custom types in schema %q: %w\", effective, typesErr)\n\t\t}\n\t\tresult = append(result, types...)\n\t}\n\tfiltered := result[:0]\n\tfor _, item := range result {\n\t\tif constraintsMatch(constraints, item.Name, item.ObjectType) {\n\t\t\tfiltered = append(filtered, item)\n\t\t}\n\t}\n\tsort.SliceStable(filtered, func(i, j int) bool {\n\t\tif objectOrder(filtered[i].ObjectType) != objectOrder(filtered[j].ObjectType) {\n\t\t\treturn objectOrder(filtered[i].ObjectType) < objectOrder(filtered[j].ObjectType)\n\t\t}\n\t\treturn filtered[i].Name < filtered[j].Name\n\t})\n\treturn pageObjects(filtered, constraints), nil\n}\n","sourceCodeStart":1138,"sourceCodeEnd":1174,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/kingbase_metadata.go#L1138-L1174","documentation":"This error wraps a failure from s.listCustomTypes while the server is enumerating all objects in a schema. Custom types (enums, domains, composite types) are fetched as one group of the schema object listing; if that catalog query fails, the whole listing aborts with this message instead of silently returning a list missing the type group. The wrapper preserves the underlying driver error via %w.","triggerScenarios":"Calling the schema object listing API (e.g. listObjects/describe schema) with constraints that allow types (constraintsAllowTypes) on a Kingbase database whose type catalog query fails — e.g. missing sys_catalog/pg_catalog type views in a compatibility mode, permission denial on catalog tables, or a driver/connection error during the metadata query.","commonSituations":"Connecting to an older or non-standard Kingbase version where the catalog layout differs from the assumed compat mode; a role lacking SELECT on catalog objects; transient connection loss during metadata enumeration; mysqlCompat/postgresCatalog mode misconfigured so the wrong catalog schema is queried.","solutions":["Check the wrapped (Unwrap'ed) driver error to find the real cause — query failure, permission, or missing catalog view","Verify the compatibility mode (mysqlCompat / postgresCatalog) matches the actual Kingbase server version","Grant the connecting role SELECT permission on the system catalog (sys_catalog / pg_catalog) tables","Retry the listing if the wrapped error indicates a transient connection issue"],"exampleFix":"// before: assuming empty schema on listing error\nobjects, err := driver.ListObjects(schema, nil)\nif err != nil { return empty }\n// after: surface the wrapped cause\nobjects, err := driver.ListObjects(schema, nil)\nif err != nil {\n    var dbErr *gokb.Error\n    if errors.As(err, &dbErr) { log.Printf(\"catalog error code=%s\", dbErr.Code) }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// Go: probe catalog access before listing objects\nvar probe int\nerr := db.QueryRow(`SELECT 1 FROM sys_catalog.sys_type LIMIT 1`).Scan(&probe)\nif err != nil {\n    return fmt.Errorf(\"type catalog not readable (check permissions/version/compat mode): %w\", err)\n}","typeGuard":null,"tryCatchPattern":"objects, err := srv.ListObjects(schema, constraints)\nif err != nil {\n    var msg string\n    if errors.As(err, new(*gokb.Error)) {\n        msg = \"catalog error - check version/permissions\"\n    } else if strings.Contains(err.Error(), \"list custom types in schema\") {\n        msg = \"type listing failed; schema view would be incomplete\"\n    }\n    return fmt.Errorf(\"listing schema %s objects: %w (%s)\", schema, err, msg)\n}","preventionTips":["Verify the Kingbase server version and set mysqlCompat/postgresCatalog compat mode to match before listing objects","Grant the application role SELECT on sys_catalog/pg_catalog tables used for metadata","Smoke-test each metadata group (tables, routines, triggers, types) against staging environments on upgrade","Do not swallow listing errors and treat the result as complete — an incomplete view hides types"],"tags":["go","database","metadata","kingbase","catalog"],"backgroundTag":"catalog-metadata-query-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}