t8y2/dbx · error

sql is required

Error message

sql is required

What it means

Returned by the xugu driver's explain/getExplain path when the SQL statement to explain is empty after trimming. Explain generation requires the statement text; a missing or whitespace-only 'sql' parameter fails validation before any EXPLAIN is issued.

Source

Thrown at agents/drivers/xugu/main.go:3853

func selectXuguCatalogTableName(schema, table string, candidates []xuguCatalogTableName) (string, string, error) {
	for _, candidate := range candidates {
		if candidate.Schema == schema && candidate.Table == table {
			return candidate.Schema, candidate.Table, nil
		}
	}
	if len(candidates) == 1 {
		return candidates[0].Schema, candidates[0].Table, nil
	}
	if len(candidates) == 0 {
		return "", "", fmt.Errorf("table not found: %s.%s", schema, table)
	}
	return "", "", fmt.Errorf("table name is ambiguous: %s.%s; specify the catalog's exact case", schema, table)
}

func (s *server) getExplainInfo(sqlText string) (string, error) {
	if strings.TrimSpace(sqlText) == "" {
		return "", errors.New("sql is required")
	}
	rows, err := s.queryRowsWithTimeoutOnce("EXPLAIN "+trimStatementSQL(sqlText), nil, 0)
	if err != nil {
		return "", err
	}
	defer s.closeRows(rows)
	columns, err := rows.Columns()
	if err != nil {
		return "", err
	}
	var builder strings.Builder
	for rows.Next() {
		values, err := scanRow(rows, len(columns))
		if err != nil {
			return "", err
		}
		builder.WriteString(joinValues(values, "\t"))
		builder.WriteByte('\n')

View on GitHub (pinned to c0390bff16)

Solutions

  1. Pass the actual SQL statement text to getExplainInfo
  2. Trim and validate the SQL string before requesting an explain plan
  3. Guard UI/editor explain actions to be enabled only when statement text exists

Example fix

// before
plan, err := getExplainInfo("")
// after
if strings.TrimSpace(sqlText) == "" { return errors.New("sql is required") }
plan, err := getExplainInfo(sqlText)
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(sqlText) == "" {
    return fmt.Errorf("sql is required")
}

Type guard

func hasExplainableSQL(sql string) bool {
    return strings.TrimSpace(sql) != ""
}

Try / catch

plan, err := s.getExplainInfo(sqlText)
if err != nil {
    if err.Error() == "sql is required" {
        return "", fmt.Errorf("no statement to explain: %w", err)
    }
    return "", err
}

Prevention

When it happens

Trigger: Calling the explain-info path with an empty SQL string, e.g. a completion or plan-preview request whose statement field was never populated.

Common situations: Editor integrations sending an explain request before any statement text was typed, or refactored code that lost the statement variable.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/9467b48ba1546f3f. Report an issue: GitHub.