hasura/graphql-engine · error · errors.Error

run_sql api request failed %d

Error message

run_sql api request failed %d

What it means

MSSQLRunSQL returns this error when the Hasura server answers the mssql_run_sql metadata API call with a non-200 HTTP status and an empty body, so only the status code is included in the message. It is wrapped with errors.KindHasuraAPI, distinguishing a server rejection from a network/transport error produced earlier in Send.

Source

Thrown at cli/internal/hasura/sourceops/mssql/run_sql.go:35

		Type: "mssql_run_sql",
		Args: input,
	}

	b := new(bytes.Buffer)

	resp, err := c.send(body, b)
	if err != nil {
		return nil, errors.E(op, err)
	}

	if resp.StatusCode != http.StatusOK {
		if b.Len() > 0 {
			return nil, errors.E(op, errors.KindHasuraAPI, b.String())
		} else {
			return nil, errors.E(
				op,
				errors.KindHasuraAPI,
				fmt.Errorf("run_sql api request failed %d", resp.StatusCode),
			)
		}
	}

	o := new(hasura.MSSQLRunSQLOutput)

	err = json.NewDecoder(b).Decode(o)
	if err != nil {
		return nil, errors.E(op, err)
	}

	return o, nil
}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Use the embedded status code: 401/403 → fix admin secret; 404 → confirm mssql support; 5xx → read Hasura + SQL Server logs
  2. Verify SQL Server connectivity and auth from the Hasura host (sqlcmd with same params, check encryption settings)
  3. Run the CLI with --debug to capture the request/response since the body is empty
  4. Confirm the mssql source entry in metadata and resolve inconsistencies
  5. Upgrade CLI/server to versions that both support mssql_run_sql

Example fix

// before
out, err := c.MSSQLRunSQL(args)
if err != nil { return err }

// after
out, err := c.MSSQLRunSQL(args)
if err != nil {
  if strings.Contains(err.Error(), "run_sql api request failed") {
    return fmt.Errorf("mssql_run_sql rejected; check server and SQL Server logs: %w", err)
  }
  return err
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight SQL Server connectivity with the same params Hasura uses
// sqlcmd -S host,1433 -U user -P pass -Q "SELECT 1" before migrate apply

Type guard

func isEmptyBodyAPIError(err error) bool {
  return err != nil && strings.Contains(err.Error(), "api request failed")
}

Try / catch

out, err := c.MSSQLRunSQL(args)
if err != nil {
  if isEmptyBodyAPIError(err) {
    return diagnoseFromStatus(err)
  }
  return err
}

Prevention

When it happens

Trigger: Running migrations (InsertVersion/SetVersion etc. via mssql_run_sql) against a MSSQL source where Hasura replies 401/403 (admin secret mismatch), 404 (mssql source kind unsupported), or 5xx empty-body (SQL Server unreachable, auth failure, or driver-level error such as TLS/encryption mismatch).

Common situations: SQL Server credentials wrong or login locked out, server forcing encryption the driver can't negotiate, Hasura pointing at wrong host/instance/port, wrong admin secret, or version mismatch between CLI and server for the mssql_run_sql endpoint.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/c978b694c027f0c1. Report an issue: GitHub.