Mercurial > hg
diff rust/hg-core/src/config/config.rs @ 46797:bcdcb4423ae3
rhg: Add more conversions between error types
This allows using the `?` operator in more places, as the next commit does.
Differential Revision: https://phab.mercurial-scm.org/D10238
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 19 Mar 2021 13:18:53 +0100 |
parents | 25e3dac511f0 |
children | b0e92313107e |
line wrap: on
line diff
--- a/rust/hg-core/src/config/config.rs Fri Mar 19 23:51:46 2021 +0100 +++ b/rust/hg-core/src/config/config.rs Fri Mar 19 13:18:53 2021 +0100 @@ -17,6 +17,7 @@ use format_bytes::{write_bytes, DisplayBytes}; use std::collections::HashSet; use std::env; +use std::fmt; use std::path::{Path, PathBuf}; use std::str; @@ -68,6 +69,21 @@ pub expected_type: &'static str, } +impl fmt::Display for ConfigValueParseError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + // TODO: add origin and line number information, here and in + // corresponding python code + write!( + f, + "config error: {}.{} is not a {} ('{}')", + String::from_utf8_lossy(&self.section), + String::from_utf8_lossy(&self.item), + self.expected_type, + String::from_utf8_lossy(&self.value) + ) + } +} + impl Config { /// Load system and user configuration from various files. ///