{"record":{"id":"9909874cf3d6e90b","repo":"t8y2/dbx","slug":"failed-to-parse-constraint-s-columns-w","errorCode":null,"errorMessage":"failed to parse constraint %s columns: %w","messagePattern":"failed to parse constraint (.+?) columns: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/kingbase_metadata.go","lineNumber":1874,"sourceCode":"\t\tname, kind, definition        string\n\t\tcolumns, refColumns           []int\n\t\trefSchema, refTable           sql.NullString\n\t\tmatchType, onUpdate, onDelete sql.NullString\n\t\tdeferrable, initiallyDeferred bool\n\t\tvalid, enabled                bool\n\t}\n\traw := []rawConstraint{}\n\tfor rows.Next() {\n\t\tvar item rawConstraint\n\t\tvar columnsRaw, refColumnsRaw, validRaw, statusRaw any\n\t\tif err := rows.Scan(&item.name, &item.kind, &item.definition, &columnsRaw, &item.refSchema, &item.refTable, &refColumnsRaw, &item.matchType, &item.onUpdate, &item.onDelete, &item.deferrable, &item.initiallyDeferred, &validRaw, &statusRaw); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\titem.valid = parseConstraintEnabled(validRaw)\n\t\titem.enabled = parseConstraintEnabled(statusRaw)\n\t\titem.columns, err = parseCatalogAttributeNumbers(columnsRaw)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse constraint %s columns: %w\", item.name, err)\n\t\t}\n\t\titem.refColumns, err = parseCatalogAttributeNumbers(refColumnsRaw)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse constraint %s referenced columns: %w\", item.name, err)\n\t\t}\n\t\traw = append(raw, item)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tattributes, err := s.relationAttributesByNumber(catalog, prefix, effective, table)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\trefAttributes := map[string]map[int]string{}\n\tresult := make([]constraintInfo, 0, len(raw))\n\tfor _, item := range raw {","sourceCodeStart":1856,"sourceCodeEnd":1892,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/kingbase_metadata.go#L1856-L1892","documentation":"While reading catalog constraint metadata rows, the value in the columns attribute (e.g. from sysconstraint) could not be parsed into a list of column numbers by parseCatalogAttributeNumbers. The driver wraps the underlying parse error with the constraint name so you know which catalog row is malformed.","triggerScenarios":"Calling metadata/DDL functions that list constraints (getTableConstraints/getTableDDL paths in kingbase_metadata.go) when the constraint's columns attribute is NULL, empty, or not a comma/brace-delimited numeric list the parser expects.","commonSituations":"Kingbase database versions whose catalog stores constraint column arrays in a different delimiter or encoding format; corrupted or partially-dumped catalogs; driver querying a system view whose column-format changed between Kingbase V8/V9 releases.","solutions":["Check the underlying wrapped error to see which attribute value failed to parse","Verify the Kingbase server version is one supported by this driver version","Inspect the raw catalog value (e.g. SELECT the columns attribute for that constraint) to see the actual format","Update or patch the driver's parseCatalogAttributeNumbers to handle the server's attribute format","If the catalog row is corrupt, rebuild/validate that constraint or restore from a clean dump"],"exampleFix":"// before: driver fails on unexpected format\ncols, err := parseCatalogAttributeNumbers(columnsRaw)\n// after: guard and log the raw value before parsing\nif columnsRaw == nil || strings.TrimSpace(fmt.Sprintf(\"%v\", columnsRaw)) == \"\" {\n    return nil, fmt.Errorf(\"constraint %s has empty columns attribute\", item.name)\n}\ncols, err := parseCatalogAttributeNumbers(columnsRaw)","handlingStrategy":"try-catch","validationCode":"// Go: pre-check the catalog row before driver introspection\nvar cols sql.NullString\nerr := db.QueryRow(`SELECT conkey FROM pg_constraint WHERE conname=$1`, name).Scan(&cols)\nif err != nil || !cols.Valid || cols.String == \"\" {\n    return fmt.Errorf(\"constraint %s columns attribute missing\", name)\n}","typeGuard":null,"tryCatchPattern":"conns, err := server.GetTableConstraints(ctx, schema, table)\nif err != nil {\n    var parseErr string\n    if strings.Contains(err.Error(), \"failed to parse constraint\") {\n        // fall back to raw catalog query or skip the malformed constraint\n        return fallbackRawConstraints(db, schema, table)\n    }\n    return err\n}","preventionTips":["Pin driver version to your Kingbase server version","Spot-check pg_constraint attribute formats after upgrades","Wrap metadata listing with a raw-catalog fallback"],"tags":["kingbase","metadata","catalog-parsing","go"],"backgroundTag":"catalog-attribute-parse-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"}