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

Switch from failure to anyhow #350

Merged
merged 2 commits into from
Apr 30, 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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-350.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: break
break:
description: Switch from failure to anyhow
links:
- https://github.com/palantir/conjure-rust/pull/350
2 changes: 1 addition & 1 deletion conjure-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ example-types = ["conjure-error", 'conjure-http']
proc-macro = ["quote/proc-macro", "proc-macro2/proc-macro"]

[dependencies]
anyhow = "1.0"
heck = "0.5"
quote = { version = "1.0", default-features = false }
prettyplease = "0.2.0"
proc-macro2 = { version = "1.0", default-features = false }
failure = "0.1"
toml = "0.8"
serde = { version = "1", features = ["derive"] }
syn = "2"
Expand Down
16 changes: 8 additions & 8 deletions conjure-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@

use crate::context::Context;
use crate::types::{ConjureDefinition, TypeDefinition};
use failure::{bail, Error, ResultExt};
use anyhow::{bail, Context as _, Error};
use proc_macro2::TokenStream;
use quote::quote;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -440,10 +440,10 @@ impl Config {

fn parse_ir(&self, ir_file: &Path) -> Result<ConjureDefinition, Error> {
let ir = fs::read_to_string(ir_file)
.with_context(|_| format!("error reading file {}", ir_file.display()))?;
.with_context(|| format!("error reading file {}", ir_file.display()))?;

let defs = conjure_serde::json::client_from_str(&ir)
.with_context(|_| format!("error parsing Conjure IR file {}", ir_file.display()))?;
.with_context(|| format!("error parsing Conjure IR file {}", ir_file.display()))?;

Ok(defs)
}
Expand Down Expand Up @@ -517,7 +517,7 @@ impl Config {
def: &ConjureDefinition,
) -> Result<(), Error> {
fs::create_dir_all(dir)
.with_context(|_| format!("error creating directory {}", dir.display()))?;
.with_context(|| format!("error creating directory {}", dir.display()))?;

let metadata = def
.extensions()
Expand Down Expand Up @@ -573,7 +573,7 @@ impl Config {
let file = dir.join("Cargo.toml");

fs::write(&file, manifest)
.with_context(|_| format!("error writing manifest file {}", file.display()))?;
.with_context(|| format!("error writing manifest file {}", file.display()))?;

Ok(())
}
Expand All @@ -585,7 +585,7 @@ disable_all_formatting = true

let file = dir.join("rustfmt.toml");

fs::write(file, contents).with_context(|_| "error writing rustfmt.toml")?;
fs::write(file, contents).with_context(|| "error writing rustfmt.toml")?;

Ok(())
}
Expand Down Expand Up @@ -623,7 +623,7 @@ impl ModuleTrie {

fn render(&self, dir: &Path, lib_root: bool) -> Result<(), Error> {
fs::create_dir_all(dir)
.with_context(|_| format!("error creating directory {}", dir.display()))?;
.with_context(|| format!("error creating directory {}", dir.display()))?;

for type_ in &self.types {
self.write_module(
Expand All @@ -648,7 +648,7 @@ impl ModuleTrie {
let formatted = prettyplease::unparse(&file);

fs::write(path, formatted)
.with_context(|_| format!("error writing module {}", path.display()))?;
.with_context(|| format!("error writing module {}", path.display()))?;
Ok(())
}

Expand Down
5 changes: 1 addition & 4 deletions conjure-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ fn main() {
let r = config.generate_files(&args.input_json, &args.output_directory);

if let Err(e) = r {
eprintln!("{}", e);
for e in e.iter_causes() {
eprintln!("Caused by: {}", e);
}
eprintln!("{e:?}");
process::exit(1);
}
}