hasura/graphql-engine · warning

error in selecting a database to use: %w

Error message

error in selecting a database to use: %w

What it means

DatabaseChooserUI wraps the error from util.GetSelectPrompt, the interactive select widget, when the user-facing database selection prompt fails. This is usually an environment problem (non-TTY terminal, prompt library failure) rather than a metadata issue.

Source

Thrown at cli/internal/metadatautil/sources.go:164

	return sources, nil
}

func DatabaseChooserUI(exportMetadata func() (io.Reader, error)) (string, error) {
	var op internalerrors.Op = "metadatautil.DatabaseChooserUI"

	sources, err := GetSources(exportMetadata)
	if err != nil {
		return "", internalerrors.E(op, fmt.Errorf("unable to get available databases: %w", err))
	}

	if len(sources) == 0 {
		return "", internalerrors.E(op, errors.New("no connected databases found in the server"))
	}

	databaseName, err := util.GetSelectPrompt("Select a database to use", sources)
	if err != nil {
		return "", internalerrors.E(op, fmt.Errorf("error in selecting a database to use: %w", err))
	}

	return databaseName, nil
}

const ChooseAllDatabases = "All (all available databases)"

func DatabaseChooserUIWithAll(exportMetadata func() (io.Reader, error)) (string, error) {
	var op internalerrors.Op = "metadatautil.DatabaseChooserUIWithAll"

	sources, err := GetSources(exportMetadata)
	if err != nil {
		return "", internalerrors.E(op, fmt.Errorf("unable to get available databases: %w", err))
	}

	if len(sources) == 0 {
		return "", internalerrors.E(op, errors.New("no connected databases found in the server"))
	}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Run the command in an interactive TTY, or bypass the chooser by supplying the database name via flag/config so no prompt is needed
  2. If in CI, provide all inputs non-interactively (flags/env) instead of relying on prompts
  3. Check the wrapped prompt error for EOF/interrupt specifics

Example fix

// before
// relies on interactive prompt only

// after
if databaseName != "" {
    // use explicit --database flag value, skip chooser
    return databaseName, nil
}
databaseName, err := metadatautil.DatabaseChooserUI(exportMetadata)
Defensive patterns

Strategy: try-catch

Validate before calling

if !term.IsTerminal(int(os.Stdin.Fd())) {
    return errors.New("database choice required: pass --database flag")
}

Type guard

func isInteractive() bool {
    fi, _ := os.Stdin.Stat()
    return fi.Mode()&os.ModeCharDevice != 0
}

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "selecting a database") {
        // fall back to flag-provided database name
    }
}

Prevention

When it happens

Trigger: Invoking DatabaseChooserUI in a non-interactive context (CI, piped stdin, no TTY) where the survey/prompt library cannot render, or when the prompt session is interrupted/EOF on stdin.

Common situations: Running CLI commands in CI or scripts where stdin is not a terminal; running over SSH with no PTY; EOF from piped input causing the prompt to abort.

Related errors


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