{"record":{"id":"c4af7e8e3527bee4","repo":"t8y2/dbx","slug":"failed-to-parse-index-s-columns-w","errorCode":null,"errorMessage":"failed to parse index %s columns: %w","messagePattern":"failed to parse index (.+?) columns: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/kingbase_metadata.go","lineNumber":1582,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer rows.Close()\n\ttype rawIndex struct {\n\t\tname, kind      string\n\t\tunique, primary bool\n\t\tattributeNums   []int\n\t}\n\trawIndexes := []rawIndex{}\n\tfor rows.Next() {\n\t\tvar item rawIndex\n\t\tvar raw any\n\t\tif err := rows.Scan(&item.name, &item.kind, &item.unique, &item.primary, &raw); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\titem.attributeNums, err = parseCatalogAttributeNumbers(raw)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse index %s columns: %w\", item.name, err)\n\t\t}\n\t\trawIndexes = append(rawIndexes, item)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, err\n\t}\n\tif len(rawIndexes) == 0 {\n\t\treturn []indexInfo{}, nil\n\t}\n\tattributes, err := s.relationAttributesByNumber(catalog, prefix, schema, table)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tresult := make([]indexInfo, 0, len(rawIndexes))\n\tfor _, raw := range rawIndexes {\n\t\titem := indexInfo{Name: raw.name, IsUnique: raw.unique, IsPrimary: raw.primary, IndexType: stringPtr(raw.kind), Columns: []string{}, IncludedColumns: []string{}}\n\t\tfor _, number := range raw.attributeNums {\n\t\t\tif name := attributes[number]; name != \"\" {","sourceCodeStart":1564,"sourceCodeEnd":1600,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/kingbase_metadata.go#L1564-L1600","documentation":"Returned when parseCatalogAttributeNumbers cannot parse the raw indkey value (the pg/sys_catalog int2vector of index attribute numbers) scanned for an index while listing indexes from the catalog. The error wraps an \"invalid attribute number %q\" failure with the index name for context. It means the driver could not decode the index's column-number list into []int.","triggerScenarios":"Calling the index listing API (e.g. ListIndexes / describe table indexes) using listIndexesWithoutOrdinality on a Kingbase server whose ix.indkey value, after catalog scan, contains tokens that are not plain integers — e.g. a non-standard indkey representation (expression indexes with 0 entries are fine, but corrupted or unexpectedly formatted values fail), or a driver returning an unusual type whose fmt.Sprint output is not a comma/space separated integer list.","commonSituations":"Older or patched Kingbase versions that serialize int2vector differently; custom index access methods returning unexpected indkey contents; driver type mapping changes so indkey arrives as a non-string type with odd string representation; indexes created by external tools with malformed catalog entries.","solutions":["Look at the wrapped \"invalid attribute number\" message to see which token failed to parse","Identify the offending index (named in the error) and inspect its ix.indkey value in the catalog (SELECT indkey FROM sys_catalog.sys_index WHERE ...)","Drop and recreate the malformed index to regenerate a clean indkey value","Upgrade or fix the Kingbase driver/compat mode so int2vector is returned as a string of integers; or use the WITH ORDINALITY query path if the server supports it"],"exampleFix":"// before: query returns raw indkey for all indexes, one bad index fails everything\nindexes, err := srv.ListIndexes(schema, table) // fails: failed to parse index myidx columns: invalid attribute number \"x\"\n// after: recreate the bad index in the database\n// DROP INDEX myidx; CREATE INDEX myidx ON t(col); then re-run listing\nindexes, err := srv.ListIndexes(schema, table)","handlingStrategy":"try-catch","validationCode":"// Go: verify indkey values are parseable integer lists before listing indexes\nrows, _ := db.Query(`SELECT i.relname, ix.indkey::text FROM sys_catalog.sys_index ix JOIN sys_catalog.sys_class i ON i.oid = ix.indexrelid`)\nfor rows.Next() {\n    var name, indkey string\n    rows.Scan(&name, &indkey)\n    for _, tok := range strings.Fields(strings.Trim(indkey, \"{}\")) {\n        if _, err := strconv.Atoi(tok); err != nil {\n            log.Printf(\"index %s has unparseable indkey token %q - recreate it\", name, tok)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"indexes, err := srv.ListIndexes(schema, table)\nif err != nil {\n    var parseErr string\n    if _, e := fmt.Sprint(err); strings.Contains(err.Error(), \"failed to parse index\") {\n        parseErr = \"catalog indkey malformed; recreate the named index\"\n    }\n    _ = parseErr\n    return fmt.Errorf(\"list indexes: %w\", err)\n}","preventionTips":["Recreate indexes that were migrated by ad-hoc tooling rather than trusting copied catalog rows","Pin the Kingbase driver version and re-run index listings in CI after driver upgrades","Prefer the WITH ORDINALITY query path when the server supports it (avoids client-side indkey parsing)","Watch for expression indexes: values like 0 in indkey are valid but odd tokens are not"],"tags":["go","database","kingbase","parsing","index"],"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-14T05:17:10.506Z"}