{"record":{"id":"4e8a9d9381d5894c","repo":"apache/answer","slug":"get-tag-failed-w","errorCode":null,"errorMessage":"get tag  failed: %w","messagePattern":"get tag  failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migrations/v13.go","lineNumber":237,"sourceCode":"\t// select tag count\n\tnewTagRelList := make([]entity.TagRel, 0)\n\terr = x.Context(ctx).Find(&newTagRelList, &entity.TagRel{Status: entity.TagRelStatusAvailable})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get tag rel failed: %w\", err)\n\t}\n\ttagCountMap := make(map[string]int)\n\tfor _, v := range newTagRelList {\n\t\t_, ok := tagCountMap[v.TagID]\n\t\tif !ok {\n\t\t\ttagCountMap[v.TagID] = 1\n\t\t} else {\n\t\t\ttagCountMap[v.TagID]++\n\t\t}\n\t}\n\tTagList := make([]entity.Tag, 0)\n\terr = x.Context(ctx).Find(&TagList, &entity.Tag{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get tag  failed: %w\", err)\n\t}\n\tfor _, tag := range TagList {\n\t\t_, ok := tagCountMap[tag.ID]\n\t\tif ok {\n\t\t\ttag.QuestionCount = tagCountMap[tag.ID]\n\t\t\tif _, err = x.Context(ctx).Update(tag, &entity.Tag{ID: tag.ID}); err != nil {\n\t\t\t\tlog.Errorf(\"update %+v tag failed: %s\", tag.ID, err)\n\t\t\t\treturn fmt.Errorf(\"update tag failed: %w\", err)\n\t\t\t}\n\t\t} else {\n\t\t\ttag.QuestionCount = 0\n\t\t\tif _, err = x.Context(ctx).Cols(\"question_count\").Update(tag, &entity.Tag{ID: tag.ID}); err != nil {\n\t\t\t\tlog.Errorf(\"update %+v tag failed: %s\", tag.ID, err)\n\t\t\t\treturn fmt.Errorf(\"update tag failed: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/migrations/v13.go#L219-L255","documentation":"Wraps an xorm Find error while loading all tags (entity.Tag) in updateTagCount, prior to writing the recomputed question_count. A failure reading the tag table aborts the migration step; the driver error is preserved via %w.","triggerScenarios":"x.Context(ctx).Find(&TagList, &entity.Tag{}) failing because the tag table is missing, the connection dropped, entity.Tag fields mismatch the table, or the context was cancelled.","commonSituations":"Tag table missing on databases where earlier migrations did not run; connectivity loss during a long migration; permission issues preventing SELECT on the tag table.","solutions":["Check the wrapped cause for table-missing vs connection vs permission errors","Run all prior migrations so the tag table exists with the expected schema","Re-run the migration on a healthy connection","Grant the migration DB user SELECT on the tag table"],"exampleFix":"// before\nerr = x.Context(ctx).Find(&TagList, &entity.Tag{})\n// after\nif err = x.Context(ctx).Find(&TagList, &entity.Tag{}); err != nil {\n    return fmt.Errorf(\"get tag failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if exists, _ := x.IsTableExist(&entity.Tag{}); !exists {\n    return fmt.Errorf(\"tag table missing; run prior migrations first\")\n}","typeGuard":null,"tryCatchPattern":"if err := updateTagCount(ctx, engine); err != nil {\n    log.Errorf(\"tag migration failed: %v\", err)\n    return err\n}","preventionTips":["Grant SELECT on all migrated tables to the migration user","Run all prior migrations before this one","Check connectivity before starting (ping the engine)","Wrap multi-step migrations in clear step logging"],"tags":["database","xorm","migration"],"backgroundTag":"migration-db-query-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}