{"record":{"id":"d72f8ab5ccba6563","repo":"Tencent/WeKnora","slug":"error-iterating-schema-rows-w","errorCode":null,"errorMessage":"error iterating schema rows: %w","messagePattern":"error iterating schema rows: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/data_analysis.go","lineNumber":740,"sourceCode":"\t\tif err != nil {\n\t\t\t// Try with fewer columns\n\t\t\terr = rows.Scan(&colName, &colType, &nullable)\n\t\t\tif err != nil {\n\t\t\t\tlogger.Errorf(ctx, \"[Tool][DataAnalysis] Failed to scan column info: %v\", err)\n\t\t\t\treturn nil, fmt.Errorf(\"failed to scan column info: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tcolumns = append(columns, ColumnInfo{\n\t\t\tName:     colName,\n\t\t\tType:     colType,\n\t\t\tNullable: nullable,\n\t\t})\n\t}\n\n\tif err := rows.Err(); err != nil {\n\t\tlogger.Errorf(ctx, \"[Tool][DataAnalysis] Error iterating schema rows: %v\", err)\n\t\treturn nil, fmt.Errorf(\"error iterating schema rows: %w\", err)\n\t}\n\n\t// Get row count\n\tcountSQL := fmt.Sprintf(\"SELECT COUNT(*) FROM \\\"%s\\\"\", tableName)\n\tvar rowCount int64\n\tif err := t.db.QueryRowContext(ctx, countSQL).Scan(&rowCount); err != nil {\n\t\tlogger.Errorf(ctx, \"[Tool][DataAnalysis] Failed to get row count: %v\", err)\n\t\treturn nil, fmt.Errorf(\"failed to get row count: %w\", err)\n\t}\n\n\tschema := &TableSchema{\n\t\tTableName: tableName,\n\t\tColumns:   columns,\n\t\tRowCount:  rowCount,\n\t\tMetadata: map[string]interface{}{\n\t\t\t\"column_count\": len(columns),\n\t\t\t\"session_id\":   t.sessionID,\n\t\t},","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/data_analysis.go#L722-L758","documentation":"Iteration wrapper in LoadFromTable: after scanning all available rows, rows.Err() reported a driver-level failure during iteration over the schema/metadata query (connection drop, cancelled context, driver error). The loaded column list is abandoned and the whole table load fails with the cause wrapped.","triggerScenarios":"Thrown at internal/agent/tools/data_analysis.go:740 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped driver error; reconnect if the DB connection was lost","Retry the table load, checking for context cancellation/timeout","Reduce query scope or fix driver issues if large schema iterations fail repeatedly"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}