{"record":{"id":"a7568067495f1b81","repo":"t8y2/dbx","slug":"list-triggers-in-schema-q-w","errorCode":null,"errorMessage":"list triggers in schema %q: %w","messagePattern":"list triggers in schema %q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/kingbase_metadata.go","lineNumber":1146,"sourceCode":"LEFT JOIN %s.%s_description d ON d.objoid = p.oid AND d.objsubid = 0\nWHERE n.nspname = %s ORDER BY p.proname`, catalog, function, catalog, function, catalog, function, quoteLiteral(effective))\n\t\t}\n\t\trows, queryErr := s.metadataQuery(query)\n\t\tif queryErr == nil {\n\t\t\tfor rows.Next() {\n\t\t\t\tvar name, kind string\n\t\t\t\tvar comment sql.NullString\n\t\t\t\tif rows.Scan(&name, &kind, &comment) == nil {\n\t\t\t\t\tresult = append(result, objectInfo{Name: name, ObjectType: kind, Schema: effective, Comment: nullStringPtr(comment)})\n\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}","sourceCodeStart":1128,"sourceCodeEnd":1164,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/kingbase_metadata.go#L1128-L1164","documentation":"listObjects (the 'all objects in schema' metadata listing) aggregates tables, routines, triggers, and types. When triggers are allowed by the request constraints, it calls listTriggerObjects; any failure is wrapped as 'list triggers in schema %q', so the whole schema listing fails rather than silently returning a result missing the trigger group — surfacing the fault lets callers distinguish an incomplete view from an actually empty schema.","triggerScenarios":"Calling the list-objects/list-schema-objects metadata API with triggers included (constraintsAllowTriggers true) on a schema where the trigger catalog query fails — missing privileges on trigger-related catalogs, SQL incompatibility with the Kingbase mode, or a connection error.","commonSituations":"Limited-privilege role connecting to the database; Kingbase instance whose trigger catalog layout (pg_trigger/sys_trigger with pg_proc joins) differs from what the driver expects; transient network failure during a broad introspection sweep.","solutions":["Read the wrapped inner error (%w) to identify the actual trigger-query failure","Grant the connecting role SELECT on the trigger catalogs (pg_trigger/sys_trigger, pg_proc/sys_proc)","Verify the driver's catalog mode (postgresCatalog vs MySQL-compat) matches the server","Retry the listing if the inner error is transient; or request the listing with triggers excluded if you don't need them"],"exampleFix":"// before\nobjects, err := server.ListObjects(\"public\", metadataListConstraints{})\n// after — skip triggers if their introspection isn't needed\nconstraints := metadataListConstraints{ /* trigger-disallowing preset */ }\nobjects, err := server.ListObjects(\"public\", constraints)","handlingStrategy":"try-catch","validationCode":"// preflight: confirm the role can read trigger catalogs before the wide listing\nif !roleCanSelect(\"pg_trigger\", \"pg_proc\") && !roleCanSelect(\"sys_trigger\", \"sys_proc\") { grantTriggerCatalogAccess() }","typeGuard":"func listingFailedWithTriggerError(err error) bool {\n  return err != nil && strings.Contains(err.Error(), \"list triggers in schema\")\n}","tryCatchPattern":"objects, err := server.ListObjects(schema, constraints)\nif err != nil {\n  if listingFailedWithTriggerError(err) && isTransient(err) {\n    return retryWithBackoff()\n  }\n  if listingFailedWithTriggerError(err) {\n    return listObjectsWithoutTriggers(schema) // degraded listing\n  }\n  return err\n}","preventionTips":["Grant SELECT on trigger-related catalogs to the introspection role","Use a metadata-list constraint set that excludes triggers when you don't need them","Retry the listing with backoff on transient connection errors","Keep the driver's catalog mode matching the Kingbase deployment to avoid incompatible trigger SQL"],"tags":["metadata","triggers","schema-listing","kingbase"],"backgroundTag":"schema-introspection-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"}