rethinkdb / rethinkdb-rs

A native RethinkDB driver written in Rust
Apache License 2.0
210 stars 27 forks source link

InitializationError when trying to connect #22

Closed phenomax closed 6 years ago

phenomax commented 6 years ago

Hey! I followed the example code and opened a connection to my RethinkDB with my credentials like this:

 let r = Client::new();

 // Create an even loop
 let core = Core::new().unwrap();

 // Create a connection pool
 let conn = r.connect(args!(core.handle(), {host: "host", username: "username", password: "password"})).unwrap();

But when I want to run my program, it panics with the following error

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Driver(Io(Error { repr: Custom(Custom { kind: Other, error: InitializationError(None) }) }))', src\libcore\result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.

The connection to my database and my credentials work. I am on Windows 10 with rustc 1.21.0 and

futures = "0.1.17"
reql = "0.0.10"
reql-types = "0.0.2"
tokio-core = "0.1.10"

What did I do wrong? Thanks in advance.

rushmorem commented 6 years ago

Hey!

I'm sorry. Documentation is one of the things that this driver still seriously lacks.

In building this driver, I made an assumption that you would most likely be running a cluster of more than one server in production. So instead of host, connect() accepts an array of servers. Please see https://github.com/rethinkdb-rs/reql/blob/7ff6d3113c548776f73d47f3f0b3de702f60a990/examples/map.rs#L31 for an example that does this. You don't have to enumerate all the servers in your cluster though, just enough to make sure that at least one of those servers will be up when you try to connect for the first time. The rest will be discovered automatically. Also use user instead of username.

So

let conn = r.connect(args!(core.handle(), {host: "host", username: "username", password: "password"})).unwrap();

should be

let conn = r.connect(args!(core.handle(), {servers: ["host"], user: "username", password: "password"})).unwrap();
phenomax commented 6 years ago

Thanks for taking time! I don't think that you are lacking documentation. It is just some kind of weird to see Javascript examples for connection establishment. I think it would be a good idea to show a rust example there using the args macro, too.

rushmorem commented 6 years ago

Thanks for taking time!

No problem :) Did that solve your issue?

It is just some kind of weird to see Javascript examples for connection establishment.

I know. The commands are auto generated from the official Javascript documentation. Eventually, I would like to try and make the build script automatically convert those Javascript examples to Rust too but I don't have time to work on that right now.

phenomax commented 6 years ago

Yeah, I can connect now. Thanks again :D

rushmorem commented 6 years ago

My pleasure.