Giter Club home page Giter Club logo

errors's Introduction

errors

std::error::Error extensions

crates.io Documentation

This crate encourages usage of the std::error::Error trait for describing errors, providing the following utilities:

  • Error creation: The errors::new, errors::wrap, and errors::opaque functions ease the creation of simple error values.
  • Error inspection: Error source chains can be easily iterated with errors::iter iterators to find the error you're looking for.
  • Error formatting: The error values created with this crate provide simple yet powerful control over the formatting of errors and their source chains, and the errors::fmt adapter allows foreign error values to follow along.

Configuring Error Formatting

An Error likely has a message, it might have a cause, and someday, it may have a backtrace. How can a user decide how they should be formatted?

Output options:

  • Top message only

    ship exploded
    
  • Top message + message of source chain

    ship exploded: cat hair in generator
    
  • Top message + message of source chain + trace/frame

    ship exploded
        at main.rs:55
        at ship.rs:89
    Caused by: cat hair in generator
        at ship::parts::generator.rs:33
        at ship::parts::engine.rs:789
        at ship.rs:89
        at main.rs:55
    

Format flags

  • Default ({}): Print only the top-level message. This is inline with the recommendation for Error
    • Example: println!("top only = {}", err) outputs top only = ship exploded.
    • Alternative: This could also be achieved and possibly clearer by setting the "precision" flag to 0, such as println!("top only: {:.0}", err).
  • Message chain ({:+}): Prints the message, and the message of each source, joined by ": ".
    • Example: println!("chain = {:+}", err) outputs chain = ship exploded: cat hair in generator.
  • With trace/frame ({:#}): Prints the message and stack trace/frame
    • Example: println!("top trace = {:#}", err) outputs top trace = ship exploded\n at ship.rs:89.
  • Message chain with trace/frame ({:+#}): Prints the message and stack trace/frame, and message and trace for each source, joined by \nCaused by:.
  • Message chain maximum ({:+.2}): Sets the maximum messages that should be printed down the source chain.

errors's People

Contributors

seanmonstar avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

errors's Issues

Error format options

An Error likely has a message, it might have a cause, and someday, it may have a trace/frame. How should they be formatted? What is a good default, and how should a user configure to their needs?

Output options:

  • Top message only

    ship exploded
    
  • Top message + message of source chain

    ship exploded: cat hair in generator
    
  • Top message + message of source chain + trace/frame

    ship exploded
        at main.rs:55
        at ship.rs:89
    Caused by: cat hair in generator
        at ship::parts::generator.rs:33
        at ship::parts::engine.rs:789
        at ship.rs:89
        at main.rs:55
    

User format flags:

The user can specify some flags when trying to format a value:

  • Default: {}
  • Alternative: {:#}
  • Plus: {:+}
    • Currently only used by numerics, so Errors could interpret this differently.
  • Precision: {:.3}
    • Currently defined for floats and strings. For strings, implies a "maximum width" of a string.
    • We could hijack this for Errors to mean "maximum iterators down source chain"

Proposed usage

  • Default ({}): Print only the top-level message. This is inline with the recommendation for Error
    • Example: println!("top only = {}", err) outputs top only = ship exploded.
    • Alternative: This could also be achieved and possibly clearer by setting the "precision" flag to 0, such as println!("top only: {:.0}", err).
  • Message chain ({:+}): Prints the message, and the message of each source, joined by ": ".
    • Example: println!("chain = {:+}", err) outputs chain = ship exploded: cat hair in generator.
  • With trace/frame ({:#}): Prints the message and stack trace/frame
    • Example: println!("top trace = {:#}", err) outputs top trace = ship exploded\n at ship.rs:89.
  • Message chain with trace/frame ({:+#}): Prints the message and stack trace/frame, and message and trace for each source, joined by \nCaused by:.
  • Message chain maximum ({:+.2}): Sets the maximum messages that should be printed down the source chain.

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.