{"record":{"id":"b75a8035bde0d93d","repo":"Tencent/WeKnora","slug":"failed-to-get-row-count-w","errorCode":null,"errorMessage":"failed to get row count: %w","messagePattern":"failed to get row count: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/data_analysis.go","lineNumber":748,"sourceCode":"\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},\n\t}\n\n\tlogger.Infof(ctx, \"[Tool][DataAnalysis] Retrieved schema for table '%s' in session %s: %d columns, %d rows\",\n\t\ttableName, t.sessionID, len(columns), rowCount)\n\n\treturn schema, nil\n}\n","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/agent/tools/data_analysis.go#L730-L766","documentation":"LoadFromTable fails to obtain the table's row count while loading table-structured data for analysis; the COUNT(*) query executed against the analysis database returned an error (connection failure, permissions, or the quoted table name being invalid), aborting the load before schema info can be returned.","triggerScenarios":"Thrown at internal/agent/tools/data_analysis.go:748 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the analysis database connection is alive and the table exists","Check that the table name is properly quoted/escaped and not injection-prone","Confirm the querying role has SELECT permission on the table","Make row count optional so schema info can still be returned if COUNT(*) fails"],"exampleFix":null,"handlingStrategy":"try-catch","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"}