Skip to content

Commit bcf3438

Browse files
committed
feat(config): add bounds validation for all numeric and URL fields
Validates max_diff_lines (10-10000), max_file_lines (10-1000), max_context_chars (1000-200000), timeout_secs (1-3600), temperature (0.0-2.0), and ollama_host URL scheme on config load.
1 parent 001bfcb commit bcf3438

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

src/config.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,53 @@ impl Config {
224224
format!("{:?}", self.provider).to_uppercase()
225225
)));
226226
}
227+
228+
if !(10..=10_000).contains(&self.max_diff_lines) {
229+
return Err(Error::Config(format!(
230+
"max_diff_lines must be 10–10000, got {}",
231+
self.max_diff_lines
232+
)));
233+
}
234+
235+
if !(10..=1_000).contains(&self.max_file_lines) {
236+
return Err(Error::Config(format!(
237+
"max_file_lines must be 10–1000, got {}",
238+
self.max_file_lines
239+
)));
240+
}
241+
242+
if !(1_000..=200_000).contains(&self.max_context_chars) {
243+
return Err(Error::Config(format!(
244+
"max_context_chars must be 1000–200000, got {}",
245+
self.max_context_chars
246+
)));
247+
}
248+
249+
if !(1..=3600).contains(&self.timeout_secs) {
250+
return Err(Error::Config(format!(
251+
"timeout_secs must be 1–3600, got {}",
252+
self.timeout_secs
253+
)));
254+
}
255+
256+
if !(0.0..=2.0).contains(&self.temperature) {
257+
return Err(Error::Config(format!(
258+
"temperature must be 0.0–2.0, got {}",
259+
self.temperature
260+
)));
261+
}
262+
263+
if self.ollama_host.is_empty() {
264+
return Err(Error::Config("ollama_host cannot be empty".into()));
265+
}
266+
267+
if !self.ollama_host.starts_with("http://") && !self.ollama_host.starts_with("https://") {
268+
return Err(Error::Config(format!(
269+
"ollama_host must start with http:// or https://, got '{}'",
270+
self.ollama_host
271+
)));
272+
}
273+
227274
Ok(())
228275
}
229276

0 commit comments

Comments
 (0)