Show More
@@ -8,7 +8,9 b'' | |||
|
8 | 8 | // GNU General Public License version 2 or any later version. |
|
9 | 9 | |
|
10 | 10 | use super::layer; |
|
11 | use crate::config::layer::{ConfigError, ConfigLayer, ConfigValue}; | |
|
11 | use crate::config::layer::{ | |
|
12 | ConfigError, ConfigLayer, ConfigParseError, ConfigValue, | |
|
13 | }; | |
|
12 | 14 | use std::path::PathBuf; |
|
13 | 15 | |
|
14 | 16 | use crate::repo::Repo; |
@@ -89,11 +91,11 b' impl Config {' | |||
|
89 | 91 | &self, |
|
90 | 92 | section: &[u8], |
|
91 | 93 | item: &[u8], |
|
92 | ) -> Result<Option<bool>, ConfigError> { | |
|
94 | ) -> Result<Option<bool>, ConfigParseError> { | |
|
93 | 95 | match self.get_inner(§ion, &item) { |
|
94 | 96 | Some((layer, v)) => match parse_bool(&v.bytes) { |
|
95 | 97 | Some(b) => Ok(Some(b)), |
|
96 |
None => Err(Config |
|
|
98 | None => Err(ConfigParseError { | |
|
97 | 99 | origin: layer.origin.to_owned(), |
|
98 | 100 | line: v.line, |
|
99 | 101 | bytes: v.bytes.to_owned(), |
@@ -7,6 +7,7 b'' | |||
|
7 | 7 | // This software may be used and distributed according to the terms of the |
|
8 | 8 | // GNU General Public License version 2 or any later version. |
|
9 | 9 | |
|
10 | use crate::errors::{HgError, IoResultExt}; | |
|
10 | 11 | use crate::utils::files::{ |
|
11 | 12 | get_bytes_from_path, get_path_from_bytes, read_whole_file, |
|
12 | 13 | }; |
@@ -99,20 +100,12 b' impl ConfigLayer {' | |||
|
99 | 100 | if let Some(m) = INCLUDE_RE.captures(&bytes) { |
|
100 | 101 | let filename_bytes = &m[1]; |
|
101 | 102 | let filename_to_include = get_path_from_bytes(&filename_bytes); |
|
102 |
|
|
|
103 |
( |
|
|
104 | layers.push(current_layer); | |
|
105 | layers.extend(Self::parse(&include_src, &data)?); | |
|
106 | current_layer = | |
|
107 |
|
|
|
108 | } | |
|
109 | (_, Err(e)) => { | |
|
110 | return Err(ConfigError::IncludeError { | |
|
111 | path: filename_to_include.to_owned(), | |
|
112 | io_error: e, | |
|
113 | }) | |
|
114 | } | |
|
115 | } | |
|
103 | let (include_src, result) = | |
|
104 | read_include(&src, &filename_to_include); | |
|
105 | let data = result.for_file(filename_to_include)?; | |
|
106 | layers.push(current_layer); | |
|
107 | layers.extend(Self::parse(&include_src, &data)?); | |
|
108 | current_layer = Self::new(ConfigOrigin::File(src.to_owned())); | |
|
116 | 109 | } else if let Some(_) = EMPTY_RE.captures(&bytes) { |
|
117 | 110 | } else if let Some(m) = SECTION_RE.captures(&bytes) { |
|
118 | 111 | section = m[1].to_vec(); |
@@ -145,11 +138,12 b' impl ConfigLayer {' | |||
|
145 | 138 | map.remove(&m[1]); |
|
146 | 139 | } |
|
147 | 140 | } else { |
|
148 |
return Err(Config |
|
|
141 | return Err(ConfigParseError { | |
|
149 | 142 | origin: ConfigOrigin::File(src.to_owned()), |
|
150 | 143 | line: Some(index + 1), |
|
151 | 144 | bytes: bytes.to_owned(), |
|
152 |
} |
|
|
145 | } | |
|
146 | .into()); | |
|
153 | 147 | } |
|
154 | 148 | } |
|
155 | 149 | if !current_layer.is_empty() { |
@@ -226,21 +220,17 b' impl ConfigOrigin {' | |||
|
226 | 220 | } |
|
227 | 221 | } |
|
228 | 222 | |
|
223 | #[derive(Debug)] | |
|
224 | pub struct ConfigParseError { | |
|
225 | pub origin: ConfigOrigin, | |
|
226 | pub line: Option<usize>, | |
|
227 | pub bytes: Vec<u8>, | |
|
228 | } | |
|
229 | ||
|
229 | 230 | #[derive(Debug, derive_more::From)] |
|
230 | 231 | pub enum ConfigError { |
|
231 | Parse { | |
|
232 | origin: ConfigOrigin, | |
|
233 | line: Option<usize>, | |
|
234 | bytes: Vec<u8>, | |
|
235 | }, | |
|
236 | /// Failed to include a sub config file | |
|
237 | IncludeError { | |
|
238 | path: PathBuf, | |
|
239 | io_error: std::io::Error, | |
|
240 | }, | |
|
241 | /// Any IO error that isn't expected | |
|
242 | #[from] | |
|
243 | IO(std::io::Error), | |
|
232 | Parse(ConfigParseError), | |
|
233 | Other(HgError), | |
|
244 | 234 | } |
|
245 | 235 | |
|
246 | 236 | fn make_regex(pattern: &'static str) -> Regex { |
General Comments 0
You need to be logged in to leave comments.
Login now