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

Remove cyclic dev-dependencies #310

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions edgedb-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ trybuild = "1.0.19"
[dev-dependencies]
bytes = "1.0.1"
edgedb-protocol = {path="../edgedb-protocol"}
edgedb-tokio = {path="../edgedb-tokio"}
serde = "1.0"
serde = {version="1.0", features=["derive"]}
serde_json = "1.0"

[lib]
Expand Down
8 changes: 1 addition & 7 deletions edgedb-errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ readme = "README.md"

[dependencies]
bytes = "1.0.1"
miette = { version="5.3.0", optional=true }

[dev-dependencies]
tokio = "1.0"
anyhow = "1.0"
edgedb-tokio = { path="../edgedb-tokio" }
miette = { version = "5.3.0", optional = true }

[lib]

74 changes: 1 addition & 73 deletions edgedb-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,79 +73,7 @@ Special care for errors must be taken in transactions. Generally:

# Nice Error Reporting

We use [miette] crate for including snippets in your error reporting code.

To make it work, first you need enable `fancy` feature in your top-level
crate's `Cargo.toml`:
```toml
[dependencies]
miette = { version="5.3.0", features=["fancy"] }
edgedb-tokio = { version="*", features=["miette-errors"] }
```

Then if you use `miette` all the way through your application, it just
works:
```rust,no_run
#[tokio::main]
async fn main() -> miette::Result<()> {
let conn = edgedb_tokio::create_client().await?;
conn.query::<String, _>("SELECT 1+2)", &()).await?;
Ok(())
}
```

However, if you use some boxed error container (e.g. [anyhow]), you
might need to downcast error for printing:
```rust,no_run
async fn do_something() -> anyhow::Result<()> {
let conn = edgedb_tokio::create_client().await?;
conn.query::<String, _>("SELECT 1+2)", &()).await?;
Ok(())
}

#[tokio::main]
async fn main() {
match do_something().await {
Ok(res) => res,
Err(e) => {
e.downcast::<edgedb_tokio::Error>()
.map(|e| eprintln!("{:?}", miette::Report::new(e)))
.unwrap_or_else(|e| eprintln!("{:#}", e));
std::process::exit(1);
}
}
}
```

In some cases, where parts of your code use `miette::Result` or
`miette::Report` before converting to the boxed (anyhow) container, you
might want a little bit more complex downcasting:

```rust,no_run
# async fn do_something() -> anyhow::Result<()> { unimplemented!() }
#[tokio::main]
async fn main() {
match do_something().await {
Ok(res) => res,
Err(e) => {
e.downcast::<edgedb_tokio::Error>()
.map(|e| eprintln!("{:?}", miette::Report::new(e)))
.or_else(|e| e.downcast::<miette::Report>()
.map(|e| eprintln!("{:?}", e)))
.unwrap_or_else(|e| eprintln!("{:#}", e));
std::process::exit(1);
}
}
}
```

Note that last two examples do hide error contexts from anyhow and do not
pretty print if `source()` of the error is `edgedb_errors::Error` but not
the top-level one. We leave those more complex cases as an excersize to the
reader.

[miette]: https://crates.io/crates/miette
[anyhow]: https://crates.io/crates/anyhow
Refer to documentation in the [edgedb-tokio](https://docs.rs/edgedb-tokio) crate.
*/
mod error;
mod traits;
Expand Down
2 changes: 2 additions & 0 deletions edgedb-tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ env_logger = "0.10"
thiserror = "1.0.30"
test-log = "0.2.8"
futures-util = "0.3.21"
miette = {version = "5.3.0", features = ["fancy"]}
edgedb-errors = {path = "../edgedb-errors", features = ["miette"]}

[features]
default = ["derive", "env"]
Expand Down
76 changes: 76 additions & 0 deletions edgedb-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,82 @@ async fn main() -> anyhow::Result<()> {
}
```
More [examples on github](https://github.com/edgedb/edgedb-rust/tree/master/edgedb-tokio/examples)

# Nice Error Reporting

We use [miette] crate for including snippets in your error reporting code.

To make it work, first you need enable `fancy` feature in your top-level
crate's `Cargo.toml`:
```toml
[dependencies]
miette = { version="5.3.0", features=["fancy"] }
edgedb-tokio = { version="*", features=["miette-errors"] }
```

Then if you use `miette` all the way through your application, it just
works:
```rust,no_run
#[tokio::main]
async fn main() -> miette::Result<()> {
let conn = edgedb_tokio::create_client().await?;
conn.query::<String, _>("SELECT 1+2)", &()).await?;
Ok(())
}
```

However, if you use some boxed error container (e.g. [anyhow]), you
might need to downcast error for printing:
```rust,no_run
async fn do_something() -> anyhow::Result<()> {
let conn = edgedb_tokio::create_client().await?;
conn.query::<String, _>("SELECT 1+2)", &()).await?;
Ok(())
}

#[tokio::main]
async fn main() {
match do_something().await {
Ok(res) => res,
Err(e) => {
e.downcast::<edgedb_tokio::Error>()
.map(|e| eprintln!("{:?}", miette::Report::new(e)))
.unwrap_or_else(|e| eprintln!("{:#}", e));
std::process::exit(1);
}
}
}
```

In some cases, where parts of your code use `miette::Result` or
`miette::Report` before converting to the boxed (anyhow) container, you
might want a little bit more complex downcasting:

```rust,no_run
# async fn do_something() -> anyhow::Result<()> { unimplemented!() }
#[tokio::main]
async fn main() {
match do_something().await {
Ok(res) => res,
Err(e) => {
e.downcast::<edgedb_tokio::Error>()
.map(|e| eprintln!("{:?}", miette::Report::new(e)))
.or_else(|e| e.downcast::<miette::Report>()
.map(|e| eprintln!("{:?}", e)))
.unwrap_or_else(|e| eprintln!("{:#}", e));
std::process::exit(1);
}
}
}
```

Note that last two examples do hide error contexts from anyhow and do not
pretty print if `source()` of the error is `edgedb_errors::Error` but not
the top-level one. We leave those more complex cases as an excersize to the
reader.

[miette]: https://crates.io/crates/miette
[anyhow]: https://crates.io/crates/anyhow
*/

#![cfg_attr(not(feature="unstable"),
Expand Down