Add nice user-facing diagnostics to your errors without being weird about it.

Overview

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

, 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), /// 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, } ">
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.

You might also like...
Simple fake AWS Cognito User Pool API server for development.

Fakey Cognito 🏡 Homepage Simple fake AWS Cognito API server for development. ✅ Implemented features AdminXxx on User Pools API. Get Started # run wit

A tool to run web applications on AWS Lambda without changing code.
A tool to run web applications on AWS Lambda without changing code.

AWS Lambda Adapter A tool to run web applications on AWS Lambda without changing code. How does it work? AWS Lambda Adapter supports AWS Lambda functi

tri-angle trader without trade, just watch pair's price change, print arbtrage chance.

tri-angle trader without trade, just watch pair's price change, print arbtrage chance.

A program written in Rust, that allows the user to find the current location of the International Space Station and see it on a map.

ISS Location ViewFinder A program written in Rust, that allows the user to find the current location of the International Space Station and see it on

Take user input in Rust.

Take user input in Rust.

You can name anonymous Future from async fn without dyn or Box!

rename-future You can name anonymous Future from async fn without dyn or Box! PLEASE READ THIS THIS PROJECT NOT YET WELL TESTED! DON'T USE THIS IN PRO

Rust library to detect bots using a user-agent string

Rust library to detect bots using a user-agent string

An iterator adapter to peek at future elements without advancing the cursor of the underlying iterator.

multipeek An iterator adapter to peek at future elements without advancing the cursor of the underlying iterator. Check out the documentation for more

A simple *blazingly fast* Rust library to unzip an S3 archive without downloading.

S3-unzip A simple blazingly fast Rust library to unzip an S3 archive into S3's root directory. Works without downloading the archive or putting it int

Owner
Kat Marchán
beginner Rustacean, @NuGet team. Formerly @npmjs
Kat Marchán
Minimal virus genome coverage assessment for metagenomic diagnostics

vircov Minimal virus genome coverage assessment for metagenomic diagnostics Overview v0.5.0 Purpose Implementation Installation Usage Tests Concept Cl

Eike Steinig 14 Oct 17, 2022
wrap errors with automatic backtrace capture and print-on-result-unwrap

backtrace-error This is a tiny crate that provides a tiny error-wrapper struct BacktraceError with only two features: Captures a backtrace on From-con

Graydon Hoare 24 Nov 19, 2022
A rust interval arithmetic library which provides flags that detect domain errors.

intervals-good A Rust interval arithmetic library which provides flags that detect domain errors, supports more functions than any other interval arit

Oliver Flatt 3 Jul 27, 2022
Easily add emojis to your git commit messages 😎

gimoji A CLI tool that makes it easy to add emojis to your git commit messages. It's very similar to (and is based on) gitmoji-cli but written in Rust

Zeeshan Ali Khan 12 May 29, 2023
Hosts EDitor, it will add/update/delete host entries for you

Host EDitor A command-line tool to easily manage you hosts file. View Demo · Report Bug · Request Feature Table of Contents About The Project Built Wi

Arjen Wiersma 10 Nov 2, 2022
Build your service-server fast, easy (and without hosting!)

service-io is a library to build servers that offering services with really little effort. Choose an input connector. Choose an output connector. Choo

Luis Enrique Muñoz Martín 34 Jan 4, 2023
A Rust framework to develop and use plugins within your project, without worrying about the low-level details.

VPlugin: A plugin framework for Rust. Website | Issues | Documentation VPlugin is a Rust framework to develop and use plugins on applications and libr

VPlugin 11 Dec 31, 2022
hado-rshado — A little macro for writing haskell-like do expressions without too much ceremony

hado Monadic haskell-like expressions brought to rust via the hado! macro What? A little macro for writing haskell-like do expressions without too muc

Lucas David Traverso 44 Jul 31, 2022
Simple color picker that lets the user create harmonic palettes with ease.

epick Simple color picker that lets the user create harmonic palettes with ease. Get it You can checkout the web demo over here or get a native binary

Wojciech Kępka 101 Dec 19, 2022
A framework for iterating over collections of types implementing a trait without virtual dispatch

zero_v Zero_V is an experiment in defining behavior over collections of objects implementing some trait without dynamic polymorphism.

null 13 Jul 28, 2022