{"record":{"id":"63a2806d5adeb1a7","repo":"hasura/graphql-engine","slug":"cockroach-run-sql-api-request-failed-d","errorCode":null,"errorMessage":"cockroach_run_sql api request failed %d","messagePattern":"cockroach_run_sql api request failed (.+?)","errorType":"http","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"cli/internal/hasura/sourceops/cockroach/run_sql.go","lineNumber":37,"sourceCode":"\t\tType: \"cockroach_run_sql\",\n\t\tArgs: input,\n\t}\n\n\tb := new(bytes.Buffer)\n\n\tresp, err := s.send(body, b)\n\tif err != nil {\n\t\treturn nil, errors.E(op, err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tif b.Len() > 0 {\n\t\t\treturn nil, errors.E(op, errors.KindHasuraAPI, b.String())\n\t\t} else {\n\t\t\treturn nil, errors.E(\n\t\t\t\top,\n\t\t\t\terrors.KindHasuraAPI,\n\t\t\t\tfmt.Errorf(\"cockroach_run_sql api request failed %d\", resp.StatusCode),\n\t\t\t)\n\t\t}\n\t}\n\n\tparsedResp := new(hasura.CockroachRunSQLOutput)\n\tif err = json.NewDecoder(b).Decode(parsedResp); err != nil {\n\t\treturn nil, errors.E(op, err)\n\t}\n\n\treturn parsedResp, nil\n}\n","sourceCodeStart":19,"sourceCodeEnd":49,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/internal/hasura/sourceops/cockroach/run_sql.go#L19-L49","documentation":"CockroachRunSQL returns this error when the Hasura server responds to the cockroach_run_sql metadata API call with a non-200 status code and an empty response body. With no server message to include, the CLI reports only the status code. The error is classified errors.KindHasuraAPI — the request reached Hasura but the run_sql execution was rejected.","triggerScenarios":"Calling cockroach_run_sql during migrations against a CockroachDB source where the server returns 401/403 (bad admin secret), 404 (cockroach source kind not registered/supported), or 5xx with an empty body (CockroachDB cluster unreachable, TLS/certificate failure, or invalid connection parameters).","commonSituations":"Misconfigured CockroachDB connection string (wrong port, missing sslmode/CA cert), expired DB credentials, wrong admin secret, server version without the cockroach backend, or a proxy stripping error bodies.","solutions":["Map the embedded status to a cause: 401/403 → admin secret; 404 → source kind support; 5xx → server/DB logs","Test the CockroachDB connection independently (cockroach sql with the same URL) to catch TLS/network/credential problems","Run the CLI with --debug for the full HTTP round trip","Verify the cockroach source in metadata and reload/fix inconsistencies","Match CLI and Hasura server versions"],"exampleFix":"// before\nout, err := c.CockroachRunSQL(args)\nif err != nil { return err }\n\n// after\nout, err := c.CockroachRunSQL(args)\nif err != nil {\n  if strings.Contains(err.Error(), \"cockroach_run_sql api request failed\") {\n    return fmt.Errorf(\"cockroach_run_sql rejected; check server/DB logs: %w\", err)\n  }\n  return err\n}","handlingStrategy":"try-catch","validationCode":"// Verify CockroachDB reachability from the Hasura host first\n// e.g. cockroach sql --url \"$SAME_URL\" -e 'SELECT 1' must succeed before run_sql flows","typeGuard":"func isEmptyBodyAPIError(err error) bool {\n  return err != nil && strings.Contains(err.Error(), \"api request failed\")\n}","tryCatchPattern":"out, err := c.CockroachRunSQL(args)\nif err != nil {\n  if isEmptyBodyAPIError(err) {\n    return diagnoseFromStatus(err)\n  }\n  return err\n}","preventionTips":["Include TLS/CA params in the Cockroach connection string","Run --debug to see the empty-body status yourself","Monitor server logs for the underlying 5xx cause"],"tags":["hasura","cockroachdb","run-sql","http-status","api-error","go"],"backgroundTag":"hasura-metadata-api-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}