Skip to content

Commit 2bff138

Browse files
authored
fix(tools): check for query execution error for pgxpool.Pool (#1969)
## Description Return error if there's error during query execution. AlloyDB AI NL tool was failing query silently. When this happened, the user was just receiving `nil` response and not informed of what the error was. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [x] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) - [x] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #1949
1 parent e1c4700 commit 2bff138

File tree

12 files changed

+59
-0
lines changed

12 files changed

+59
-0
lines changed

internal/tools/alloydbainl/alloydbainl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
179179
}
180180
out = append(out, vMap)
181181
}
182+
// this will catch actual query execution errors
183+
if err := results.Err(); err != nil {
184+
return nil, fmt.Errorf("unable to execute query: %w", err)
185+
}
182186

183187
return out, nil
184188
}

internal/tools/postgres/postgresdatabaseoverview/postgresdatabaseoverview.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
157157
out = append(out, rowMap)
158158
}
159159

160+
// this will catch actual query execution errors
161+
if err := results.Err(); err != nil {
162+
return nil, fmt.Errorf("unable to execute query: %w", err)
163+
}
164+
160165
return out, nil
161166
}
162167

internal/tools/postgres/postgreslistactivequeries/postgreslistactivequeries.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
170170
out = append(out, rowMap)
171171
}
172172

173+
// this will catch actual query execution errors
174+
if err := results.Err(); err != nil {
175+
return nil, fmt.Errorf("unable to execute query: %w", err)
176+
}
177+
173178
return out, nil
174179
}
175180

internal/tools/postgres/postgreslistavailableextensions/postgreslistavailableextensions.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
141141
out = append(out, vMap)
142142
}
143143

144+
// this will catch actual query execution errors
145+
if err := results.Err(); err != nil {
146+
return nil, fmt.Errorf("unable to execute query: %w", err)
147+
}
148+
144149
return out, nil
145150
}
146151

internal/tools/postgres/postgreslistindexes/postgreslistindexes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
192192
out = append(out, rowMap)
193193
}
194194

195+
// this will catch actual query execution errors
196+
if err := results.Err(); err != nil {
197+
return nil, fmt.Errorf("unable to execute query: %w", err)
198+
}
199+
195200
return out, nil
196201
}
197202

internal/tools/postgres/postgreslistinstalledextensions/postgreslistinstalledextensions.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
152152
out = append(out, vMap)
153153
}
154154

155+
// this will catch actual query execution errors
156+
if err := results.Err(); err != nil {
157+
return nil, fmt.Errorf("unable to execute query: %w", err)
158+
}
159+
155160
return out, nil
156161
}
157162

internal/tools/postgres/postgreslistschemas/postgreslistschemas.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
192192
out = append(out, rowMap)
193193
}
194194

195+
// this will catch actual query execution errors
196+
if err := results.Err(); err != nil {
197+
return nil, fmt.Errorf("unable to execute query: %w", err)
198+
}
199+
195200
return out, nil
196201
}
197202

internal/tools/postgres/postgreslistsequences/postgreslistsequences.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
167167
out = append(out, rowMap)
168168
}
169169

170+
// this will catch actual query execution errors
171+
if err := results.Err(); err != nil {
172+
return nil, fmt.Errorf("unable to execute query: %w", err)
173+
}
174+
170175
return out, nil
171176
}
172177

internal/tools/postgres/postgreslisttriggers/postgreslisttriggers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
194194
out = append(out, rowMap)
195195
}
196196

197+
// this will catch actual query execution errors
198+
if err := results.Err(); err != nil {
199+
return nil, fmt.Errorf("unable to execute query: %w", err)
200+
}
201+
197202
return out, nil
198203
}
199204

internal/tools/postgres/postgreslistviews/postgreslistviews.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessT
159159
out = append(out, rowMap)
160160
}
161161

162+
// this will catch actual query execution errors
163+
if err := results.Err(); err != nil {
164+
return nil, fmt.Errorf("unable to execute query: %w", err)
165+
}
166+
162167
return out, nil
163168
}
164169

0 commit comments

Comments
 (0)