googleapis/mcp-toolbox · error
unable to execute query: %w
Error message
unable to execute query: %w
What it means
Trino RunSQL wraps errors from QueryContext before any rows are read. QueryContext sends the statement to the Trino coordinator and fails on connectivity problems, auth rejection, SQL syntax/semantic errors, or an already-cancelled context. The driver error is preserved via %w.
Source
Thrown at internal/sources/trino/trino.go:119
return false
}
func (s *Source) SourceType() string {
return SourceType
}
func (s *Source) ToConfig() sources.SourceConfig {
return s.Config
}
func (s *Source) TrinoDB() *sql.DB {
return s.Pool
}
func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {
results, err := s.TrinoDB().QueryContext(ctx, statement, params...)
if err != nil {
return nil, fmt.Errorf("unable to execute query: %w", err)
}
defer results.Close()
cols, err := results.Columns()
if err != nil {
return nil, fmt.Errorf("unable to retrieve column names: %w", err)
}
// create an array of values for each column, which can be re-used to scan each row
rawValues := make([]any, len(cols))
values := make([]any, len(cols))
for i := range rawValues {
values[i] = &rawValues[i]
}
out := []any{}
for results.Next() {
err := results.Scan(values...)View on GitHub (pinned to 8cc6e09de2)
Solutions
- Run the statement directly via trino-cli with the same user/catalog/schema to see the raw error
- Check the wrapped error for Trino's error code (SYNTAX_ERROR, PERMISSION_DENIED, etc.)
- Verify the configured catalog/schema and user grants in Trino
- Increase queryTimeout and check context deadlines for long queries
- Confirm coordinator is up and pool connections haven't been dropped by idle timeouts
Example fix
// before results, err := db.QueryContext(ctx, "SELCT * FROM users") // after results, err := db.QueryContext(ctx, "SELECT * FROM users")
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check grants/catalog with a cheap probe query
if err := probe(ctx, db, "SELECT 1"); err != nil { return err } Try / catch
out, err := src.RunSQL(ctx, stmt, params)
if err != nil && strings.Contains(err.Error(), "unable to execute query") {
var trinoErr *trino.Error
if errors.As(err, &trinoErr) { log.Printf("trino code=%s msg=%s", trinoErr.Code, trinoErr.Message) }
} Prevention
- Validate SQL syntax against the same Trino version via trino-cli before deploying
- Grant the toolbox user SELECT on the target catalog/schema
- Set queryTimeout above expected query duration
- Handle context cancellation in callers so queries aren't killed prematurely
When it happens
Trigger: Source.RunSQL where s.TrinoDB().QueryContext(ctx, statement, params...) fails: malformed SQL, unknown catalog/schema/table, permission denied, session expired, or network failure at submission time.
Common situations: Typos in SQL or referencing tables outside the configured catalog/schema; user lacking SELECT grants in Trino; stale pool connections after coordinator restart; query cancelled because the incoming request context expired.
Related errors
- unable to execute query: %w
- unable to execute query: %w
- errors encountered by results.Scan: %w
- unable to execute query: %w
- unable to execute query: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/156c227568fc40ad.
Report an issue: GitHub.