{"record":{"id":"890e6dc700a51a86","repo":"hasura/graphql-engine","slug":"unable-to-get-available-databases-w","errorCode":null,"errorMessage":"unable to get available databases: %w","messagePattern":"unable to get available databases: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/internal/metadatautil/sources.go","lineNumber":155,"sourceCode":"\n\tsources, err := GetSourcesAndKind(exportMetadata)\n\tif err != nil {\n\t\treturn nil, internalerrors.E(op, err)\n\t}\n\n\tif len(sources) == 0 {\n\t\treturn nil, internalerrors.E(op, ErrNoConnectedSources)\n\t}\n\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\"","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/internal/metadatautil/sources.go#L137-L173","documentation":"DatabaseChooserUI fails to list databases because the underlying GetSources call errored while parsing Hasura metadata. The wrapper adds context ('unable to get available databases') around the jsonparser failure, so the root cause is in the wrapped error chain.","triggerScenarios":"Invoking the interactive database chooser (any CLI command that asks 'Select a database to use') when the metadata export is malformed, the server returns non-JSON, or the sources key is missing/wrong type.","commonSituations":"Running CLI commands against an unreachable/misconfigured endpoint that returns HTML; corrupted metadata.json in the project; CLI/server version mismatch.","solutions":["Check the wrapped cause with errors.Unwrap / full message to find the jsonparser reason","Verify endpoint and admin secret env vars point at a live Hasura server","Re-export metadata and validate with jq","Match CLI version to server version"],"exampleFix":"// before\ndb, err := metadatautil.DatabaseChooserUI(exportMetadata)\n\n// after\ndb, err := metadatautil.DatabaseChooserUI(exportMetadata)\nif err != nil { return fmt.Errorf(\"choosing database: %w\", err) }","handlingStrategy":"validation","validationCode":"sources, err := metadatautil.GetSources(exportMetadata)\nif err != nil { /* avoid chooser, surface parse issue */ }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    return fmt.Errorf(\"unable to list databases for chooser: %w\", err)\n}","preventionTips":["Verify endpoint and admin secret before prompting","Validate metadata JSON before invoking the chooser"],"tags":["go","hasura-cli","interactive-prompt","metadata-parsing"],"backgroundTag":"json-parsing-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}