Skip to content

[sqlx-cli] ux bug with sqlx prepare #4383

Description

@1estart

I have found these related issues/pull requests

I've do some search in issues by sqlx prepare failed CARGO and just sqlx prepare and didn't find any relations with existing prepare command in just sqlx and always proposing error with redirecting to cargo sqlx invocation

Description

Title: sqlx prepare listed in help but fails with unclear error

Description:
prepare subcommand is listed in sqlx --help, but running it directly fails:

$ sqlx prepare
error: failed to get value of CARGO; prepare subcommand may only be invoked as cargo sqlx prepare

This is confusing because:

  1. The command is advertised in help output
  2. The error message is unclear — it mentions internal CARGO variable instead of telling the user what to do

Suggested fixes (any one of):

  • Remove prepare from sqlx --help if it only works via cargo sqlx
  • Improve error message: suggest using cargo sqlx prepare explicitly
  • Make sqlx prepare work standalone by locating Cargo.toml automatically

Workaround: Use cargo sqlx prepare instead of sqlx prepare.

Reproduction steps

$ sqlx prepare
error: failed to get value of CARGO; prepare subcommand may only be invoked as cargo sqlx prepare

SQLx version

0.9.0

Enabled SQLx features

"postgres", "runtime-tokio", "tls-native-tls"

Database server and version

Postgres

Operating system

Ubuntu 24.04.4 LTS

Rust version

1.94.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions