{"record":{"id":"b08716df77970efa","repo":"hasura/graphql-engine","slug":"error-in-selecting-a-database-to-use-w","errorCode":null,"errorMessage":"error in selecting a database to use: %w","messagePattern":"error in selecting a database to use: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli/internal/metadatautil/sources.go","lineNumber":164,"sourceCode":"\n\treturn sources, nil\n}\n\nfunc DatabaseChooserUI(exportMetadata func() (io.Reader, error)) (string, error) {\n\tvar op internalerrors.Op = \"metadatautil.DatabaseChooserUI\"\n\n\tsources, err := GetSources(exportMetadata)\n\tif err != nil {\n\t\treturn \"\", internalerrors.E(op, fmt.Errorf(\"unable to get available databases: %w\", err))\n\t}\n\n\tif len(sources) == 0 {\n\t\treturn \"\", internalerrors.E(op, errors.New(\"no connected databases found in the server\"))\n\t}\n\n\tdatabaseName, err := util.GetSelectPrompt(\"Select a database to use\", sources)\n\tif err != nil {\n\t\treturn \"\", internalerrors.E(op, fmt.Errorf(\"error in selecting a database to use: %w\", err))\n\t}\n\n\treturn databaseName, nil\n}\n\nconst ChooseAllDatabases = \"All (all available databases)\"\n\nfunc DatabaseChooserUIWithAll(exportMetadata func() (io.Reader, error)) (string, error) {\n\tvar op internalerrors.Op = \"metadatautil.DatabaseChooserUIWithAll\"\n\n\tsources, err := GetSources(exportMetadata)\n\tif err != nil {\n\t\treturn \"\", internalerrors.E(op, fmt.Errorf(\"unable to get available databases: %w\", err))\n\t}\n\n\tif len(sources) == 0 {\n\t\treturn \"\", internalerrors.E(op, errors.New(\"no connected databases found in the server\"))\n\t}","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/internal/metadatautil/sources.go#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the command in an interactive TTY, or bypass the chooser by supplying the database name via flag/config so no prompt is needed","If in CI, provide all inputs non-interactively (flags/env) instead of relying on prompts","Check the wrapped prompt error for EOF/interrupt specifics"],"exampleFix":"// before\n// relies on interactive prompt only\n\n// after\nif databaseName != \"\" {\n    // use explicit --database flag value, skip chooser\n    return databaseName, nil\n}\ndatabaseName, err := metadatautil.DatabaseChooserUI(exportMetadata)","handlingStrategy":"try-catch","validationCode":"if !term.IsTerminal(int(os.Stdin.Fd())) {\n    return errors.New(\"database choice required: pass --database flag\")\n}","typeGuard":"func isInteractive() bool {\n    fi, _ := os.Stdin.Stat()\n    return fi.Mode()&os.ModeCharDevice != 0\n}","tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"selecting a database\") {\n        // fall back to flag-provided database name\n    }\n}","preventionTips":["Detect TTY before invoking prompts","Expose non-interactive flags for database selection in scripts/CI"],"tags":["go","hasura-cli","interactive-prompt","tty"],"backgroundTag":"non-interactive-terminal-prompt-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}