Crate format_serde_error[−][src]
Expand description
Format serde errors in a way to make it obvious where the error in the source file was.
Example:
use format_serde_error::SerdeError; #[derive(Debug, serde::Serialize, serde::Deserialize)] struct Config { values: Vec<String>, } fn parse_config() -> Result<Config, anyhow::Error> { let config_str = "values: - 'first' - 'second' - third:"; let config = serde_yaml::from_str::<Config>(config_str) .map_err(|err| SerdeError::new(config_str.to_string(), err))?; Ok(config) }
The output will be:
Error:
| values:
| - 'first'
| - 'second'
4 | - third:
| ^ values[2]: invalid type: map, expected a string at line 4 column 10
Structs
SerdeError | Struct for formatting the error together with the source file to give a nicer output. |
Enums
ColoringMode | Different behaviors for the crate to allow overriding the colored output
behaviors. Creating the environment variable |
ErrorTypes | Supported error types by the crate. Currently only |
Constants
CONTEXT_LINES | Amount of lines to show before and after the line containing the error. |
Functions
always_color | Set coloring mode to never use color in the output
( |
never_color | Set coloring mode to always use color in the output
( |
set_coloring_mode | Change coloring mode across the library. See |
use_environment | Set coloring mode detect if color should be used in the output or not
( |