{"record":{"id":"156c227568fc40ad","repo":"googleapis/mcp-toolbox","slug":"unable-to-execute-query-w-156c22","errorCode":null,"errorMessage":"unable to execute query: %w","messagePattern":"unable to execute query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/trino/trino.go","lineNumber":119,"sourceCode":"\treturn false\n}\n\nfunc (s *Source) SourceType() string {\n\treturn SourceType\n}\n\nfunc (s *Source) ToConfig() sources.SourceConfig {\n\treturn s.Config\n}\n\nfunc (s *Source) TrinoDB() *sql.DB {\n\treturn s.Pool\n}\n\nfunc (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {\n\tresults, err := s.TrinoDB().QueryContext(ctx, statement, params...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\tdefer results.Close()\n\n\tcols, err := results.Columns()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to retrieve column names: %w\", err)\n\t}\n\n\t// create an array of values for each column, which can be re-used to scan each row\n\trawValues := make([]any, len(cols))\n\tvalues := make([]any, len(cols))\n\tfor i := range rawValues {\n\t\tvalues[i] = &rawValues[i]\n\t}\n\n\tout := []any{}\n\tfor results.Next() {\n\t\terr := results.Scan(values...)","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/trino/trino.go#L101-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nresults, err := db.QueryContext(ctx, \"SELCT * FROM users\")\n// after\nresults, err := db.QueryContext(ctx, \"SELECT * FROM users\")","handlingStrategy":"try-catch","validationCode":"// pre-check grants/catalog with a cheap probe query\nif err := probe(ctx, db, \"SELECT 1\"); err != nil { return err }","typeGuard":null,"tryCatchPattern":"out, err := src.RunSQL(ctx, stmt, params)\nif err != nil && strings.Contains(err.Error(), \"unable to execute query\") {\n    var trinoErr *trino.Error\n    if errors.As(err, &trinoErr) { log.Printf(\"trino code=%s msg=%s\", trinoErr.Code, trinoErr.Message) }\n}","preventionTips":["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"],"tags":["database","trino","query-execution","sql"],"backgroundTag":"query-execution-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}