mirror of
				https://github.com/haraldh/chainerror.git
				synced 2025-10-31 06:41:36 +01:00 
			
		
		
		
	chore: remove need for cargo readme
				
					
				
			Just use `#![doc = include_str!("../README.md")]`
Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
			
			
This commit is contained in:
		
							parent
							
								
									165c1b939c
								
							
						
					
					
						commit
						cf62d1a9f9
					
				
					 3 changed files with 3 additions and 121 deletions
				
			
		
							
								
								
									
										15
									
								
								.github/workflows/rust.yml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								.github/workflows/rust.yml
									
										
									
									
										vendored
									
									
								
							|  | @ -19,7 +19,7 @@ jobs: | ||||||
|     strategy: |     strategy: | ||||||
|       matrix: |       matrix: | ||||||
|         version: |         version: | ||||||
|           - 1.46.0 |           - 1.54.0 | ||||||
|           - stable |           - stable | ||||||
|           - beta |           - beta | ||||||
|           - nightly |           - nightly | ||||||
|  | @ -70,16 +70,3 @@ jobs: | ||||||
|         with: |         with: | ||||||
|           command: clippy |           command: clippy | ||||||
|           args: -- -D warnings |           args: -- -D warnings | ||||||
| 
 |  | ||||||
|   readme: |  | ||||||
|     name: cargo readme |  | ||||||
|     runs-on: ubuntu-latest |  | ||||||
|     steps: |  | ||||||
|       - uses: actions/checkout@v2 |  | ||||||
|       - uses: dtolnay/rust-toolchain@master |  | ||||||
|         with: |  | ||||||
|           toolchain: stable |  | ||||||
|           profile: minimal |  | ||||||
|           override: true |  | ||||||
|       - run: cargo install cargo-readme |  | ||||||
|       - run: cargo readme > README.md && git diff --exit-code |  | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
										
									
									
									
								
							|  | @ -1,9 +1,6 @@ | ||||||
| [](https://crates.io/crates/chainerror) | [](https://crates.io/crates/chainerror) | ||||||
| [](https://docs.rs/chainerror/) | [](https://docs.rs/chainerror/) | ||||||
| [](https://coveralls.io/github/haraldh/chainerror?branch=master) | [](https://codecov.io/gh/haraldh/chainerror) | ||||||
| [](https://github.com/haraldh/chainerror/actions?query=workflow%3A%22Rust%22) |  | ||||||
| [](https://isitmaintained.com/project/haraldh/chainerror "Average time to resolve an issue") |  | ||||||
| [](https://isitmaintained.com/project/haraldh/chainerror "Percentage of issues still open") |  | ||||||
|  |  | ||||||
| 
 | 
 | ||||||
| # chainerror | # chainerror | ||||||
|  | @ -93,11 +90,6 @@ Along with the `ChainError<T>` struct, `chainerror` comes with some useful helpe | ||||||
| 
 | 
 | ||||||
| Debug information is worth it! | Debug information is worth it! | ||||||
| 
 | 
 | ||||||
| ### Features |  | ||||||
| 
 |  | ||||||
| `display-cause` |  | ||||||
| : turn on printing a backtrace of the errors in `Display` |  | ||||||
| 
 |  | ||||||
| ## Tutorial | ## Tutorial | ||||||
| 
 | 
 | ||||||
| Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html) | Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html) | ||||||
|  |  | ||||||
							
								
								
									
										99
									
								
								src/lib.rs
									
										
									
									
									
								
							
							
						
						
									
										99
									
								
								src/lib.rs
									
										
									
									
									
								
							|  | @ -1,101 +1,4 @@ | ||||||
| //! `chainerror` provides an error backtrace without doing a real backtrace, so even after you `strip` your
 | #![doc = include_str!("../README.md")] | ||||||
| //! binaries, you still have the error backtrace.
 |  | ||||||
| //!
 |  | ||||||
| //! Having nested function returning errors, the output doesn't tell where the error originates from.
 |  | ||||||
| //!
 |  | ||||||
| //! ```rust
 |  | ||||||
| //! use std::path::PathBuf;
 |  | ||||||
| //!
 |  | ||||||
| //! type BoxedError = Box<dyn std::error::Error + Send + Sync>;
 |  | ||||||
| //! fn read_config_file(path: PathBuf) -> Result<(), BoxedError> {
 |  | ||||||
| //!     // do stuff, return other errors
 |  | ||||||
| //!     let _buf = std::fs::read_to_string(&path)?;
 |  | ||||||
| //!     // do stuff, return other errors
 |  | ||||||
| //!     Ok(())
 |  | ||||||
| //! }
 |  | ||||||
| //!
 |  | ||||||
| //! fn process_config_file() -> Result<(), BoxedError> {
 |  | ||||||
| //!     // do stuff, return other errors
 |  | ||||||
| //!     let _buf = read_config_file("foo.txt".into())?;
 |  | ||||||
| //!     // do stuff, return other errors
 |  | ||||||
| //!     Ok(())
 |  | ||||||
| //! }
 |  | ||||||
| //!
 |  | ||||||
| //! fn main() {
 |  | ||||||
| //!     if let Err(e) = process_config_file() {
 |  | ||||||
| //!         eprintln!("Error:\n{:?}", e);
 |  | ||||||
| //!     }
 |  | ||||||
| //! }
 |  | ||||||
| //! ```
 |  | ||||||
| //!
 |  | ||||||
| //! This gives the output:
 |  | ||||||
| //! ```console
 |  | ||||||
| //! Error:
 |  | ||||||
| //! Os { code: 2, kind: NotFound, message: "No such file or directory" }
 |  | ||||||
| //! ```
 |  | ||||||
| //! and you have no idea where it comes from.
 |  | ||||||
| //!
 |  | ||||||
| //!
 |  | ||||||
| //! With `chainerror`, you can supply a context and get a nice error backtrace:
 |  | ||||||
| //!
 |  | ||||||
| //! ```rust
 |  | ||||||
| //! use chainerror::prelude::v1::*;
 |  | ||||||
| //! use std::path::PathBuf;
 |  | ||||||
| //!
 |  | ||||||
| //! type BoxedError = Box<dyn std::error::Error + Send + Sync>;
 |  | ||||||
| //! fn read_config_file(path: PathBuf) -> Result<(), BoxedError> {
 |  | ||||||
| //!     // do stuff, return other errors
 |  | ||||||
| //!     let _buf = std::fs::read_to_string(&path).context(format!("Reading file: {:?}", &path))?;
 |  | ||||||
| //!     // do stuff, return other errors
 |  | ||||||
| //!     Ok(())
 |  | ||||||
| //! }
 |  | ||||||
| //!
 |  | ||||||
| //! fn process_config_file() -> Result<(), BoxedError> {
 |  | ||||||
| //!     // do stuff, return other errors
 |  | ||||||
| //!     let _buf = read_config_file("foo.txt".into()).context("read the config file")?;
 |  | ||||||
| //!     // do stuff, return other errors
 |  | ||||||
| //!     Ok(())
 |  | ||||||
| //! }
 |  | ||||||
| //!
 |  | ||||||
| //! fn main() {
 |  | ||||||
| //!     if let Err(e) = process_config_file() {
 |  | ||||||
| //!         eprintln!("Error:\n{:?}", e);
 |  | ||||||
| //! #       let s = format!("{:?}", e);
 |  | ||||||
| //! #       let lines = s.lines().collect::<Vec<_>>();
 |  | ||||||
| //! #       assert_eq!(lines.len(), 5);
 |  | ||||||
| //! #       assert!(lines[0].starts_with("src/lib.rs:"));
 |  | ||||||
| //! #       assert_eq!(lines[1], "Caused by:");
 |  | ||||||
| //! #       assert!(lines[2].starts_with("src/lib.rs:"));
 |  | ||||||
| //! #       assert_eq!(lines[3], "Caused by:");
 |  | ||||||
| //! #       assert_eq!(lines[4], "Os { code: 2, kind: NotFound, message: \"No such file or directory\" }");
 |  | ||||||
| //!     }
 |  | ||||||
| //! #   else { panic!(); }
 |  | ||||||
| //! }
 |  | ||||||
| //! ```
 |  | ||||||
| //!
 |  | ||||||
| //! with the output:
 |  | ||||||
| //! ```console
 |  | ||||||
| //! Error:
 |  | ||||||
| //! examples/simple.rs:14:51: read the config file
 |  | ||||||
| //! Caused by:
 |  | ||||||
| //! examples/simple.rs:7:47: Reading file: "foo.txt"
 |  | ||||||
| //! Caused by:
 |  | ||||||
| //! Os { code: 2, kind: NotFound, message: "No such file or directory" }
 |  | ||||||
| //! ```
 |  | ||||||
| //!
 |  | ||||||
| //! `chainerror` uses `.source()` of `std::error::Error` along with `#[track_caller]` and `Location` to provide a nice debug error backtrace.
 |  | ||||||
| //! It encapsulates all types, which have `Display + Debug` and can store the error cause internally.
 |  | ||||||
| //!
 |  | ||||||
| //! Along with the `ChainError<T>` struct, `chainerror` comes with some useful helper macros to save a lot of typing.
 |  | ||||||
| //!
 |  | ||||||
| //! `chainerror` has no dependencies!
 |  | ||||||
| //!
 |  | ||||||
| //! Debug information is worth it!
 |  | ||||||
| //!
 |  | ||||||
| //! # Tutorial
 |  | ||||||
| //!
 |  | ||||||
| //! Read the [Tutorial](https://haraldh.github.io/chainerror/tutorial1.html)
 |  | ||||||
| 
 |  | ||||||
| #![deny(clippy::all)] | #![deny(clippy::all)] | ||||||
| #![allow(clippy::needless_doctest_main)] | #![allow(clippy::needless_doctest_main)] | ||||||
| #![deny(missing_docs)] | #![deny(missing_docs)] | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue