hasura/graphql-engine · error
unable to get available databases: %w
Error message
unable to get available databases: %w
What it means
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.
Source
Thrown at cli/internal/metadatautil/sources.go:155
sources, err := GetSourcesAndKind(exportMetadata)
if err != nil {
return nil, internalerrors.E(op, err)
}
if len(sources) == 0 {
return nil, internalerrors.E(op, ErrNoConnectedSources)
}
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"View on GitHub (pinned to 724551b9ae)
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
Example fix
// before
db, err := metadatautil.DatabaseChooserUI(exportMetadata)
// after
db, err := metadatautil.DatabaseChooserUI(exportMetadata)
if err != nil { return fmt.Errorf("choosing database: %w", err) } Defensive patterns
Strategy: validation
Validate before calling
sources, err := metadatautil.GetSources(exportMetadata)
if err != nil { /* avoid chooser, surface parse issue */ } Try / catch
if err != nil {
return fmt.Errorf("unable to list databases for chooser: %w", err)
} Prevention
- Verify endpoint and admin secret before prompting
- Validate metadata JSON before invoking the chooser
When it happens
Trigger: 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.
Common situations: Running CLI commands against an unreachable/misconfigured endpoint that returns HTML; corrupted metadata.json in the project; CLI/server version mismatch.
Related errors
- jsonparser: %w
- no connected databases found in the server
- error in selecting a database to use: %w
- error in getting user input: %w
- error in selecting framework: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/890e6dc700a51a86.
Report an issue: GitHub.