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

infer_schema! panicked using sqlite db on master #605

Closed
beatgammit opened this Issue Feb 2, 2017 · 14 comments

Comments

Projects
None yet
5 participants
@beatgammit

beatgammit commented Feb 2, 2017

I ran into this when using diesel master in anticipation of a stable release:

infer_schema!("dotenv:DATABASE_URL");

And in .env:

DATABASE_URL=test.sqlite

My schema:

CREATE TABLE rooms (
    id INTEGER PRIMARY KEY NOT NULL,
    name TEXT NOT NULL,
    udp_port INTEGER NOT NULL,
    tcp_port INTEGER NOT NULL
)

And my struct:

#[derive(Serialize, Deserialize, Clone, Insertable, Queryable)]
#[table_name = "rooms"]
pub struct Room {
    pub id: i32,
    pub name: String,
    pub udp_port: i32,
    pub tcp_port: i32,
}

I'm using sqlite with features = ["sqlite"] defined in my Cargo.toml. Let me know if there's any more info you need to determine whether this is an issue with my code or diesel. It works fine (on nightly) when using the latest published crate, so this is either a regression in diesel or my misunderstanding of how to define DATABASE_URL for sqlite.

If I get time today I'll test against Postgres, though I prefer to prototype with sqlite since there's less hassle setting up/upgrading the db.

@beatgammit beatgammit changed the title from infer_schema! panicked to infer_schema! panicked using sqlite db on master Feb 2, 2017

@sgrif

This comment has been minimized.

Member

sgrif commented Feb 2, 2017

Can you provide the error message you received? Was the file actually present at the path you pointed to?

@drbawb

This comment has been minimized.

drbawb commented Feb 2, 2017

Not sure if this is related, but I'm also having issues w/ infer_schema! while trying to follow along with Getting Started, however I was using PostgreSQL instead of SQLite.

The error I receive:

$ rustc -V
rustc 1.16.0-nightly (df8debf6d 2017-01-25)

$ cargo build
   Compiling aqua v0.1.0
error: macro undefined: 'options!'
 --> src/schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro outside of the current crate

error: aborting due to previous error

error: Could not compile `aqua`.

This is the database connection string

$ cat .env
DATABASE_URL=postgres://drbawb@192.168.1.11/aqua_diesel

Let me know if there's any other debug information I could gather for you.

@killercup

This comment has been minimized.

Member

killercup commented Feb 2, 2017

error: macro undefined: 'options!'

Sound like we missed something in #565?

@fivethousand

This comment has been minimized.

fivethousand commented Feb 2, 2017

Same error here:

macro undefined 'options!'
(Linux/PostgreSQL/Rust nightly 1.16/Diesel 0.9.1)

@sgrif

This comment has been minimized.

Member

sgrif commented Feb 2, 2017

Nightlies later than nightly-2017-01-19 or so are busted. You can point diesel_codegen master to work around the problem. rust-lang/rust#39347

@fivethousand

This comment has been minimized.

fivethousand commented Feb 2, 2017

Oh.
The example (or at least the first steps) do compile and work after removing

#![feature(proc_macro)]

(as suggested).
Maybe this should be added to the tutorial until the issue is fixed.

@killercup

This comment has been minimized.

Member

killercup commented Feb 2, 2017

@beatgammit

This comment has been minimized.

beatgammit commented Feb 2, 2017

I'll try again on the beta compiler. I was using the latest nightly (from Tuesday I think).

Ok, here's the error I got when running with --verbose:

      Running `rustc --crate-name kingdoms src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=8803b6454b81cb08 -C extra-filename=-8803b6454b81cb08 --out-dir /home/otto/src/kingdoms/target/debug/deps -L dependency=/home/otto/src/kingdoms/target/debug/deps --extern serde=/home/otto/src/kingdoms/target/debug/deps/libserde-3b541f18042a189e.rlib --extern diesel_codegen=/home/otto/src/kingdoms/target/debug/deps/libdiesel_codegen-4fec4c5b49099acd.so --extern dotenv=/home/otto/src/kingdoms/target/debug/deps/libdotenv-75d8ce5725f9d0e8.rlib --extern tokio_core=/home/otto/src/kingdoms/target/debug/deps/libtokio_core-70b906545a29c574.rlib --extern serde_derive=/home/otto/src/kingdoms/target/debug/deps/libserde_derive-bb0d6dc974011064.so --extern futures=/home/otto/src/kingdoms/target/debug/deps/libfutures-e55d45cfd50e0707.rlib --extern serde_json=/home/otto/src/kingdoms/target/debug/deps/libserde_json-85c7805edd047502.rlib --extern router=/home/otto/src/kingdoms/target/debug/deps/librouter-2997412ffea4968d.rlib --extern iron=/home/otto/src/kingdoms/target/debug/deps/libiron-72125e3b31590887.rlib --extern clap=/home/otto/src/kingdoms/target/debug/deps/libclap-f2820a3ff71ece60.rlib --extern diesel=/home/otto/src/kingdoms/target/debug/deps/libdiesel-bf8106fecd2b1076.rlib --extern hyper=/home/otto/src/kingdoms/target/debug/deps/libhyper-f076905ec4b248f0.rlib -L native=/usr/lib -L native=/usr/lib`
error: custom derive attribute panicked
 --> src/schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: This is a bug. Please open a Github issue with your invocation of `infer_schema!
  = note: this error originates in a macro outside of the current crate

error: Could not compile `kingdoms`.

Caused by:
  process didn't exit successfully: `rustc --crate-name kingdoms src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=8803b6454b81cb08 -C extra-filename=-8803b6454b81cb08 --out-dir /home/otto/src/kingdoms/target/debug/deps -L dependency=/home/otto/src/kingdoms/target/debug/deps --extern serde=/home/otto/src/kingdoms/target/debug/deps/libserde-3b541f18042a189e.rlib --extern diesel_codegen=/home/otto/src/kingdoms/target/debug/deps/libdiesel_codegen-4fec4c5b49099acd.so --extern dotenv=/home/otto/src/kingdoms/target/debug/deps/libdotenv-75d8ce5725f9d0e8.rlib --extern tokio_core=/home/otto/src/kingdoms/target/debug/deps/libtokio_core-70b906545a29c574.rlib --extern serde_derive=/home/otto/src/kingdoms/target/debug/deps/libserde_derive-bb0d6dc974011064.so --extern futures=/home/otto/src/kingdoms/target/debug/deps/libfutures-e55d45cfd50e0707.rlib --extern serde_json=/home/otto/src/kingdoms/target/debug/deps/libserde_json-85c7805edd047502.rlib --extern router=/home/otto/src/kingdoms/target/debug/deps/librouter-2997412ffea4968d.rlib --extern iron=/home/otto/src/kingdoms/target/debug/deps/libiron-72125e3b31590887.rlib --extern clap=/home/otto/src/kingdoms/target/debug/deps/libclap-f2820a3ff71ece60.rlib --extern diesel=/home/otto/src/kingdoms/target/debug/deps/libdiesel-bf8106fecd2b1076.rlib --extern hyper=/home/otto/src/kingdoms/target/debug/deps/libhyper-f076905ec4b248f0.rlib -L native=/usr/lib -L native=/usr/lib` (exit code: 101)

diesel_codegen is using this commit: 7dd95eb.

rustup show (just updated today, though I can switch to the previous beta if you like):

Default host: x86_64-unknown-linux-gnu

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
beta-x86_64-unknown-linux-gnu
nightly-2016-12-16-x86_64-unknown-linux-gnu
nightly-2017-01-15-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu

active toolchain
----------------

beta-x86_64-unknown-linux-gnu (directory override for '/home/otto/src/kingdoms')
rustc 1.16.0-beta.1 (5276ba72e 2017-01-31)
@beatgammit

This comment has been minimized.

beatgammit commented Feb 2, 2017

I get the same problem on the nightly you listed using diesel_codegen master:

     Running `rustc --crate-name kingdoms src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=8803b6454b81cb08 -C extra-filename=-8803b6454b81cb08 --out-dir /home/otto/src/kingdoms/target/debug/deps -L dependency=/home/otto/src/kingdoms/target/debug/deps --extern futures=/home/otto/src/kingdoms/target/debug/deps/libfutures-e55d45cfd50e0707.rlib --extern tokio_core=/home/otto/src/kingdoms/target/debug/deps/libtokio_core-70b906545a29c574.rlib --extern diesel=/home/otto/src/kingdoms/target/debug/deps/libdiesel-bf8106fecd2b1076.rlib --extern router=/home/otto/src/kingdoms/target/debug/deps/librouter-2997412ffea4968d.rlib --extern iron=/home/otto/src/kingdoms/target/debug/deps/libiron-72125e3b31590887.rlib --extern dotenv=/home/otto/src/kingdoms/target/debug/deps/libdotenv-75d8ce5725f9d0e8.rlib --extern serde=/home/otto/src/kingdoms/target/debug/deps/libserde-3b541f18042a189e.rlib --extern serde_json=/home/otto/src/kingdoms/target/debug/deps/libserde_json-85c7805edd047502.rlib --extern hyper=/home/otto/src/kingdoms/target/debug/deps/libhyper-f076905ec4b248f0.rlib --extern clap=/home/otto/src/kingdoms/target/debug/deps/libclap-f2820a3ff71ece60.rlib --extern diesel_codegen=/home/otto/src/kingdoms/target/debug/deps/libdiesel_codegen-4fec4c5b49099acd.so --extern serde_derive=/home/otto/src/kingdoms/target/debug/deps/libserde_derive-bb0d6dc974011064.so -L native=/usr/lib -L native=/usr/lib`
error: custom derive attribute panicked
 --> src/schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: This is a bug. Please open a Github issue with your invocation of `infer_schema!
  = note: this error originates in a macro outside of the current crate

error: Could not compile `kingdoms`.

Caused by:
  process didn't exit successfully: `rustc --crate-name kingdoms src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=8803b6454b81cb08 -C extra-filename=-8803b6454b81cb08 --out-dir /home/otto/src/kingdoms/target/debug/deps -L dependency=/home/otto/src/kingdoms/target/debug/deps --extern futures=/home/otto/src/kingdoms/target/debug/deps/libfutures-e55d45cfd50e0707.rlib --extern tokio_core=/home/otto/src/kingdoms/target/debug/deps/libtokio_core-70b906545a29c574.rlib --extern diesel=/home/otto/src/kingdoms/target/debug/deps/libdiesel-bf8106fecd2b1076.rlib --extern router=/home/otto/src/kingdoms/target/debug/deps/librouter-2997412ffea4968d.rlib --extern iron=/home/otto/src/kingdoms/target/debug/deps/libiron-72125e3b31590887.rlib --extern dotenv=/home/otto/src/kingdoms/target/debug/deps/libdotenv-75d8ce5725f9d0e8.rlib --extern serde=/home/otto/src/kingdoms/target/debug/deps/libserde-3b541f18042a189e.rlib --extern serde_json=/home/otto/src/kingdoms/target/debug/deps/libserde_json-85c7805edd047502.rlib --extern hyper=/home/otto/src/kingdoms/target/debug/deps/libhyper-f076905ec4b248f0.rlib --extern clap=/home/otto/src/kingdoms/target/debug/deps/libclap-f2820a3ff71ece60.rlib --extern diesel_codegen=/home/otto/src/kingdoms/target/debug/deps/libdiesel_codegen-4fec4c5b49099acd.so --extern serde_derive=/home/otto/src/kingdoms/target/debug/deps/libserde_derive-bb0d6dc974011064.so -L native=/usr/lib -L native=/usr/lib` (exit code: 101)

To be clear, I can use the published crate on nightly, but using master breaks on all rustc that I've tried.

@beatgammit

This comment has been minimized.

beatgammit commented Feb 2, 2017

Nvm, it seems to fail regardless of what I try... in any case, I'm not blocked by this issue, I just wanted to make sure it was addressed before a new crate was published targeting the new rust 1.15.

Let me know if there's anything else I can do to help. If it's really a bug in rust, then there's not much we can do, but I can try to make a smaller test case to reproduce it if that'll help.

@beatgammit

This comment has been minimized.

beatgammit commented Feb 2, 2017

Ok, it looks like it's potentially partially my fault. I was messing with the URI in .env to try to get it to work on the beta release, and I then got errors from that. I'm working through the errors on the nightly mentioned earlier in this chain.

EDIT: I fixed the URI and it builds on nightly-2017-01-19 with the version from crates.io, but fails to build from diesel_codegen master.

@beatgammit

This comment has been minimized.

beatgammit commented Feb 2, 2017

Ok, I figured it out. I was using diesel_codegen from master, but diesel from crates.io and I had to set the "sqlite" feature when I updated to diesel master (I guess it was default on in diesel but not diesel_codegen before?). I rebuilt using the latest beta (1.16) and it worked.

So, TL;DR: update both diesel and diesel_codegen to the latest master and it compiles on the latest beta.

EDIT: as a bonus, it seems it also compiles on 1.15 stable, which was just released like 30 minutes ago!

EDIT: it also works with the versions published to crates.io. I guess I was just a worry wart. I thought it was going to be a 0.9.2 release or something, but having both at 0.10 makes sense. Thanks so much for your hard, I think this can be closed.

@sgrif

This comment has been minimized.

Member

sgrif commented Feb 2, 2017

Can you give an example of the .env file that was failing so I can make sure we give an error message than handles that case? Was the .env file itself invalid?

@beatgammit

This comment has been minimized.

beatgammit commented Feb 2, 2017

Yes, the .env file was invalid in my test. I threw a sqlite:// in front of the filename (to make it look more like postgres) thinking maybe it was just a poor error message, but it was failing before even getting to that point. As I mentioned above, it was a mismatch between diesel_codegen 0.10 and diesel 0.9, which was resolved by setting both to pull from master. The error message I got once it got past whatever it was panicking on was helpful:

= help: message: called Result::unwrap() on an Err value: StringError("Failed to establish a database connection at sqlite://test.sqlite. Error: BadConnection("Unable to open the database file")")
= note: this error originates in a macro outside of the current crate

The crates you just published work OOTB with my previously working .env entry, so this is now resolved and works with the stable compiler. So all I need to do is update my Cargo.toml to pull the latest crates from crates.io.

@sgrif sgrif closed this Feb 2, 2017

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