Code Monkey home page Code Monkey logo

thisdiagnostic's Introduction

thisdiagnostic

thisdiagnostic is a Rust library for adding rich diagnostic metadata to errors, for some really fancy and customizable error reporting!

Example

What You Write

use thisdiagnostic::Diagnostic;
use thiserror::Error;

#[derive(Error, Debug, Diagnostic)]
pub enum ApiError {
    /// Returned when a generic http client-related error has occurred.
    #[label("mytool::api::generic_http")]
    #[error("Request error:\n\t{0}")]
    HttpError(Box<dyn std::error::Error + Send + Sync>, String),

    /// Returned when a URL failed to parse.
    #[label("mytool::api::invalid_url")]
    #[help("Check the URL syntax. URLs must include the protocol part (https://, etc)")]
    #[error(transparent)]
    UrlParseError(#[from] Box<dyn std::error::Error + Send + Sync>),

    /// An API key is required.
    #[label("mytool::api::needs_api_key")]
    #[help("Please supply an API key.")]
    #[error("Endpoint operation requires an API key.")]
    NeedsApiKey,

    /// Unexpected response
    #[label("mytool::api::unexpected_response")]
    #[help("This is likely a bug with the server API (or its documentation). Please report it.")]
    #[error("Unexpected or undocumented response.")]
    BadResponse,
}

What You Get

$ ./mytool
Error: mytool::api::needs_api_key

Endpoint operation requires an API key.

help: Please supply an API key.

License

This project and any contributions to it are licensed under Apache 2.0.

thisdiagnostic's People

Contributors

zkat avatar

Watchers

 avatar

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.