Giter Site home page Giter Site logo

derive-error-chain's People

Contributors

arnavion avatar hcpl avatar jjedelsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

hcpl

derive-error-chain's Issues

Undocumented dependencies

It is undocumented that using a given version of derive_error_chain requires the use of a specific version of error_chain.

For example, to use derive-error-chain = "=0.11.2", one also has to specify error-chain = "=0.11.0" in Cargo.toml. otherwise, one gets unexpected errors from inside the procedural macro (Exact errors depend on specific version combination).

This should either be documented, or otherwise include error-chain as an explicit dependency (since one doesn't even need to extern crate error_chain in one's crate root)

Add `const("some string literal with {parameters}")` as a shorthand for `display()`

As a workaround, one can use a closure instead of a function path:

#[derive(Debug, error_chain)]
pub enum ErrorKind {
	Msg(String),

	#[error_chain(custom, display = "http_status_display")]
	HttpStatus(u32),
}

fn http_status_display(f: &mut ::std::fmt::Formatter, e: &u32) -> ::std::fmt::Result {
	write!(f, "http request returned an unsuccessful status code: {}", e)
}

can be written as

#[derive(Debug, error_chain)]
pub enum ErrorKind {
	Msg(String),

	#[error_chain(custom)]
	#[error_chain(display = r#"(|f: &mut ::std::fmt::Formatter, e| write!(f, "http request returned an unsuccessful status code: {}", e))"#)]
	HttpStatus(u32),
}

Replace `error_chain!`

With macros 1.1 on stable, do you think your crate could replace the upstream error_chain?

Documentation updates

  • ErrorKind must derive Debug
  • ErrorKind must be pub
  • If using both error-chain and derive-error-chain, #[macro_use] extern crate error_chain; must come before #[macro_use] extern crate derive_error_chain;
  • Doesn't need nightly compiler any more.
  • Document attributes like serde - enum vs field attributes, a description for each attribute.

Don't require `ErrorKind` to be `pub`

  • The ErrorKind must have pub visibility. error_chain! does this implicitly.

This rule exists because Error, Result and ResultExt are always emitted with pub, so the ErrorKind needs to be pub to avoid "private type is exposed publicly" errors.

Instead, those three should only be pub if the ErrorKind is pub.

Rename `#[derive(error_chain)]` to `#[derive(ErrorChain)]`

Per rust-lang/rust#38356 (comment) it is a compiler error to have a proc_macro_derive use its name for an attribute like this crate does (#[derive(error_chain)] and #[error_chain(...)]) since the latter is also the syntax for proc_macro_attribute macros.

#[derive(error_chain)] should be renamed to #[derive(ErrorChain)] and the attribute can continue to be #[error_chain(...)]. This is better than the other way around in that it's consistent with other proc macros, eg #[derive(Deserialize)] and #[serde(...)]

#[derive(error_chain)] could be kept around as well, so that code that doesn't use #[error_chain] can continue to use #[derive(error_chain)]. But this is only true of the simplest of ErrorKinds - those that have nothing except Msg(String) - so I don't think it's worth it.

This is a breaking change that requires bumping to v0.11.0 Luckily error-chain is going to go to v0.11.0 as well, so the timing might work.


Alas, there's another breakage that #[macro_use] extern crate error_chain; also conflicts with the custom derive name and the attribute name. Just renaming the custom derive is not a complete solution. Looks like the attribute will need to be renamed after all...

Future alias?

pub type Future<T> = ::futures::Future<Item = T, Error = Error>;

like the Result alias.

Opt-in via toplevel #[error_chain(future)] / #[error_chain(future = "Future")] attribute, of course.

Add `const("some string literal")` as a shorthand for `description()`

As a workaround, one can use a closure instead of a function path:

#[derive(Debug, error_chain)]
pub enum ErrorKind {
	Msg(String),

	#[error_chain(custom, description = "http_status_description")]
	HttpStatus(u32),
}

fn http_status_description(_: &u32) -> &str {
	"http request returned an unsuccessful status code"
}

can be written as

#[derive(Debug, error_chain)]
pub enum ErrorKind {
	Msg(String),

	#[error_chain(custom)]
	#[error_chain(description = r#"(|_| "http request returned an unsuccessful status code")"#)]
	HttpStatus(u32),
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.