Skip to content

Commit bde8a71

Browse files
committed
Improve error messages when one of the required attributes is missing
In the derive crate.
1 parent 81bb7ea commit bde8a71

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## Unreleased
99

10+
### Added
11+
12+
- Better error messages from the derive macro stwhen the schema or the query file path is not found.
13+
1014
## 0.5.0
1115

1216
### Added

graphql_query_derive/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ repository = "https://github.com/graphql-rust/graphql-client"
1010
proc-macro = true
1111

1212
[dependencies]
13+
failure = "0.1"
1314
syn = "0.15"
1415
proc-macro2 = { version = "0.4", features = [] }
1516
graphql_client_codegen = { path = "../graphql_client_codegen/", version = "0.5.0" }

graphql_query_derive/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
extern crate failure;
12
extern crate graphql_client_codegen;
23
extern crate proc_macro;
34
extern crate proc_macro2;
45
extern crate syn;
6+
7+
use failure::ResultExt;
58
use graphql_client_codegen::*;
69

710
use proc_macro2::TokenStream;
@@ -22,10 +25,14 @@ fn build_query_and_schema_path(
2225
let cargo_manifest_dir =
2326
::std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env variable is defined");
2427

25-
let query_path = attributes::extract_attr(input, "query_path").unwrap();
28+
let query_path = attributes::extract_attr(input, "query_path")
29+
.context("Extracting query path")
30+
.unwrap();
2631
let query_path = format!("{}/{}", cargo_manifest_dir, query_path);
2732
let query_path = ::std::path::Path::new(&query_path).to_path_buf();
28-
let schema_path = attributes::extract_attr(input, "schema_path").unwrap();
33+
let schema_path = attributes::extract_attr(input, "schema_path")
34+
.context("Extracting schema path")
35+
.unwrap();
2936
let schema_path = ::std::path::Path::new(&cargo_manifest_dir).join(schema_path);
3037
(query_path, schema_path)
3138
}

0 commit comments

Comments
 (0)