Giter Site home page Giter Site logo

sonro / narrate Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 0.0 199 KB

Rust CLI utility library. Error handling, status reporting, and exit codes.

License: Apache License 2.0

Rust 99.00% Shell 1.00%
cli error error-handling error-reporting library output reporting rust stderr

narrate's People

Contributors

sonro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

narrate's Issues

Tune up readme

Rewrite readme to be more in line with how this particular library should be used. At the moment it is missing several parts of the API

Relevant examples

  • Integration with anyhow
  • Reporting statuses
  • Reporting errors
  • Standalone error library
  • ExitCode implementation
  • CliError usage

Feature flags

  • report
  • error
  • cli-error
  • default: report, error, cli-error

Move anyhow integration behind a feature flag

BREAKING CHANGE

Hide Error::downcast and Error::from_anyhow behind an "anyhow" feature flag. These are currently the only public APIs using anyhow types. Moreover only publicly re-export anyhow crate behind the feature flag.

This allows the default API to keep the implementation separate from the user and the "anyhow" feature-set to allow conversion between the two types.

Compile error when using `narrate::{bail, error_from}` without specifying `anyhow` as dependency

Bug Report

Using narrate::{bail, error_from} in a project that doesn't specify anyhow as a dependency separately (regardless of if the anyhow feature of narrate is used) unconditionally triggers a compile error. (AFAIK this is a bug, as documentation doesn't specify that anyhow must also be a dependency.)

Example

Cargo.toml

[package]
name = "example"
version = "0.1.0"
edition = "2021"

[dependencies]
narrate = { version = "0.4.1", features = ["anyhow"] }
# The above line could also have simply been:
# narrate = "0.4.1"

src/main.rs

fn main() -> narrate::Result<()> {
    narrate::bail!("this should compile");
}

cargo build

See the triggered compiler error:

error[E0433]: failed to resolve: use of undeclared crate or module `anyhow`
 --> src/main.rs:2:5
  |
2 |     narrate::bail!("this should compile");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `anyhow`
  |
  = note: this error originates in the macro `$crate::error_from` which comes from the expansion of the macro `narrate::bail` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0433`.
error: could not compile `main` (bin "main") due to previous error

Cause

It seems that this issue stems from narrate not unconditionally requiring anyhow as a non-optional dependency. My best guess is that this was introduced in bdba927. This seems related to #4.

Remedy

In the meantime while awaiting a fix, adding anyhow as a dependency in Cargo.toml prevents the compile error.

Notes

Otherwise, narrate is a great library that does exactly what I was looking for!

Report status macros

Format report messages to standard colors.

  • success!: green
  • info!: blue
  • warning!: orange

4 varients:

varient output note
success!("hello") "success: hello"
info!("{}", msg) "info: msg string"
warning!("title", "hello") "title: hello" 'title' would be orange
success!("title", "{}", msg") "title: msg string" 'title' would be green

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.