https://github.com/zkat/thisdiagnostic
Add nice user-facing diagnostics to your errors without being weird about it.
https://github.com/zkat/thisdiagnostic
Last synced: 8 months ago
JSON representation
Add nice user-facing diagnostics to your errors without being weird about it.
- Host: GitHub
- URL: https://github.com/zkat/thisdiagnostic
- Owner: zkat
- License: other
- Created: 2021-08-01T05:54:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-02T16:13:59.000Z (over 4 years ago)
- Last Synced: 2025-05-06T22:56:43.069Z (8 months ago)
- Language: Rust
- Size: 16.6 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# 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
```rust
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, 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,
}
```
### What You Get
```ignore
$ ./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](LICENSE.md).