t8y2/dbx · error

SQL is required

Error message

SQL is required

What it means

getExplainInfo prefixes EXPLAIN to a SQL statement and executes it to capture the query plan. The statement text is trimmed (trimStatementSQL) and must be non-empty; an empty statement has nothing to explain, so this error is returned before touching the connection.

Source

Thrown at agents/drivers/argo-go/metadata.go:801

		}
		lines := make([]string, 0, len(result.Rows))
		for _, row := range result.Rows {
			if line := firstRowValue(row); line != "" {
				lines = append(lines, line)
			}
		}
		if len(lines) == 0 {
			continue
		}
		return strings.Join(lines, "\n") + "\n", nil
	}
	return "", nil
}

func (server *server) getExplainInfo(sqlText string) (string, error) {
	sqlText = trimStatementSQL(sqlText)
	if sqlText == "" {
		return "", errors.New("SQL is required")
	}
	result, err := server.executeQuery(queryOptions{SQL: "EXPLAIN " + sqlText, MaxRows: metadataQueryLimit})
	if err != nil {
		return "", err
	}
	lines := make([]string, 0, len(result.Rows))
	for _, row := range result.Rows {
		lines = append(lines, firstRowValue(row))
	}
	return strings.Join(lines, "\n"), nil
}

func (server *server) completionAssistantSearch(input completionAssistantRequest) (completionAssistantResponse, error) {
	maxResults := input.MaxResults
	if maxResults <= 0 {
		maxResults = 200
	}
	schemas := []string{firstNonEmpty(input.Schema, input.Database, server.config.Database)}

View on GitHub (pinned to c0390bff16)

Solutions

  1. Provide the actual SQL statement text in the explain request
  2. Check the input after trimming — statements made only of comments count as empty
  3. Ensure the calling UI/tool passes the current query buffer, not a stale empty variable
  4. Add client-side validation that the SQL field is non-blank before sending

Example fix

// before
plan, err := server.getExplainInfo(userInput) // userInput = "-- nothing"
// after
if strings.TrimSpace(strings.TrimPrefix(userInput, "--")) == "" {
    return errors.New("SQL is required")
}
plan, err := server.getExplainInfo(userInput)
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(strings.TrimPrefix(sqlText, "--")) == "" {
    return errors.New("SQL is required")
}

Try / catch

plan, err := server.getExplainInfo(sqlText)
if err != nil && err.Error() == "SQL is required" {
    return fmt.Errorf("cannot EXPLAIN empty statement")
}

Prevention

When it happens

Trigger: Calling getExplainInfo with "", whitespace-only text, or a string that consists solely of comments/terminators that trimStatementSQL strips away.

Common situations: Client sends explain request with an empty editor buffer; the SQL variable was never populated from a template; statement contained only a comment ('-- hint') which trims to empty; copy-paste lost the query text.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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