Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo fix cannot be used with sqlx offline mode #1229

Closed
ihor-rud opened this issue May 16, 2021 · 4 comments
Closed

cargo fix cannot be used with sqlx offline mode #1229

ihor-rud opened this issue May 16, 2021 · 4 comments

Comments

@ihor-rud
Copy link

Hi,
Running cargo fix on a project that uses sqlx::query! in offline mode panics while compilation.

error: proc macro panicked
...
= help: message: Invalid `cargo metadata` output: Error("EOF while parsing a value", line: 1, column: 0)
= note: this error originates in the macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)

It look like calling cargo metadata under cargo fix has different behavior. It expects to receive additional argument if __CARGO_FIX_PLZ is set.

I'd be happy to submit a PR but I dont know what would be the best fix to that.

@Palmik
Copy link

Palmik commented Jun 28, 2021

I am having the same issue, but only when building within Docker. Did you find a workaround?

@frxstrem
Copy link
Contributor

I don't know if it's the best way to solve this, but it seems like the following patch is sufficient to get cargo fix to work with offline mode:

diff --git a/sqlx-macros/src/query/mod.rs b/sqlx-macros/src/query/mod.rs
index a2f17874..4e2ba900 100644
--- a/sqlx-macros/src/query/mod.rs
+++ b/sqlx-macros/src/query/mod.rs
@@ -81,6 +81,7 @@ static METADATA: Lazy<Metadata> = Lazy::new(|| {
         let output = Command::new(&cargo)
             .args(&["metadata", "--format-version=1"])
             .current_dir(&manifest_dir)
+            .env_remove("__CARGO_FIX_PLZ")
             .output()
             .expect("Could not fetch metadata");

@jplatte
Copy link
Contributor

jplatte commented Jul 29, 2021

You should probably just create a PR for that :)

Sounds like a fine workaround to me until this is (hopefully) fixed in cargo.

@abonander
Copy link
Collaborator

Closed by #1352

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

No branches or pull requests

5 participants