Skip to content

Commit

Permalink
better error output
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrchen committed Aug 31, 2022
1 parent 59d3363 commit 1cccac4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requester/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xreq-lib"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
license = "MIT"
documentation = "https://docs.rs/xreq-lib"
Expand Down
15 changes: 8 additions & 7 deletions requester/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ impl DiffConfig {
}

pub fn get(&self, profile: &str) -> Result<&DiffContext> {
self.ctxs
.get(profile)
.ok_or_else(|| anyhow::anyhow!("profile {} not found", profile))
self.ctxs.get(profile).ok_or_else(|| {
anyhow::anyhow!(
"profile {} not found. Available profiles: {:?}.",
profile,
self.ctxs.keys()
)
})
}

pub async fn diff(&self, profile: &str) -> Result<DiffResult> {
let ctx = self
.ctxs
.get(profile)
.ok_or_else(|| anyhow::anyhow!("profile {} not found", profile))?;
let ctx = self.get(profile)?;

ctx.diff().await
}
Expand Down
19 changes: 11 additions & 8 deletions requester/src/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ impl RequestConfig {
}

pub fn get(&self, profile: &str) -> Result<&RequestContext> {
self.ctxs
.get(profile)
.ok_or_else(|| anyhow::anyhow!("profile {} not found", profile))
self.ctxs.get(profile).ok_or_else(|| {
anyhow::anyhow!(
"profile {} not found. Available profiles: {:?}.",
profile,
self.ctxs.keys()
)
})
}

pub async fn send(&self, profile: &str) -> Result<Response> {
let ctx = self
.ctxs
.get(profile)
.ok_or_else(|| anyhow::anyhow!("profile {} not found", profile))?;
let ctx = self.get(profile)?;

ctx.send().await
}
Expand Down Expand Up @@ -120,7 +121,9 @@ impl RequestContext {
match url.scheme() {
"http" | "https" => {
let qs = serde_qs::to_string(&self.params)?;
url.set_query(Some(&qs));
if !qs.is_empty() {
url.set_query(Some(&qs));
}
let client = Client::builder().user_agent(user_agent).build()?;

let mut builder = client
Expand Down
4 changes: 2 additions & 2 deletions xdiff/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xdiff"
version = "0.4.2"
version = "0.4.3"
edition = "2021"
license = "MIT"
documentation = "https://docs.rs/xdiff"
Expand All @@ -23,4 +23,4 @@ serde_json = "1.0.85"
serde_yaml = "0.9.10"

xreq-cli-utils = { version = "0.3.1", path = "../cli-utils" }
xreq-lib = { version = "0.4.0", path = "../requester" }
xreq-lib = { version = "0.4.1", path = "../requester" }
4 changes: 2 additions & 2 deletions xreq/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xreq"
version = "0.4.2"
version = "0.4.3"
edition = "2021"
license = "MIT"
documentation = "https://docs.rs/xreq"
Expand All @@ -25,4 +25,4 @@ serde_yaml = "0.9.10"
tokio = { version = "1.20.1", features = ["full"] }

xreq-cli-utils = { version = "0.3.1", path = "../cli-utils" }
xreq-lib = { version = "0.4.0", path = "../requester" }
xreq-lib = { version = "0.4.1", path = "../requester" }
1 change: 1 addition & 0 deletions xreq/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async fn run(output: &mut Vec<String>, args: RunArgs) -> Result<()> {
let resp = config.send().await?;

if atty::is(atty::Stream::Stdout) {
output.push(format!("Sending: {}\n\n", resp.url()));
print_status(output, &resp);
print_headers(output, &resp);
}
Expand Down

0 comments on commit 1cccac4

Please sign in to comment.