comparison rust/hg-core/src/config/mod.rs @ 50808:67faf1bd8acd

rust-config: add devel warning when using undeclared config items This mirrors the Python implementation now that we're done catching up.
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 06 Jul 2023 11:44:30 +0200
parents 7f8f6fe13fa9
children d64df6b35007
comparison
equal deleted inserted replaced
50807:067edf5083a1 50808:67faf1bd8acd
414 if !fallback_to_default { 414 if !fallback_to_default {
415 return Ok(None); 415 return Ok(None);
416 } 416 }
417 match self.get_default(section, item)? { 417 match self.get_default(section, item)? {
418 Some(default) => Ok(default.try_into()?), 418 Some(default) => Ok(default.try_into()?),
419 None => Ok(None), 419 None => {
420 self.print_devel_warning(section, item)?;
421 Ok(None)
422 }
420 } 423 }
421 } 424 }
422 } 425 }
426 }
427
428 fn print_devel_warning(
429 &self,
430 section: &[u8],
431 item: &[u8],
432 ) -> Result<(), HgError> {
433 let warn_all = self.get_bool(b"devel", b"all-warnings")?;
434 let warn_specific = self.get_bool(b"devel", b"warn-config-unknown")?;
435 if !warn_all || !warn_specific {
436 // We technically shouldn't print anything here since it's not
437 // the concern of `hg-core`.
438 //
439 // We're printing directly to stderr since development warnings
440 // are not on by default and surfacing this to consumer crates
441 // (like `rhg`) would be more difficult, probably requiring
442 // something à la `log` crate.
443 //
444 // TODO maybe figure out a way of exposing a "warnings" channel
445 // that consumer crates can hook into. It would be useful for
446 // all other warnings that `hg-core` could expose.
447 eprintln!(
448 "devel-warn: accessing unregistered config item: '{}.{}'",
449 String::from_utf8_lossy(section),
450 String::from_utf8_lossy(item),
451 );
452 }
453 Ok(())
423 } 454 }
424 455
425 /// Returns an `Err` if the first value found is not a valid UTF-8 string. 456 /// Returns an `Err` if the first value found is not a valid UTF-8 string.
426 /// Otherwise, returns an `Ok(value)` if found, or `None`. 457 /// Otherwise, returns an `Ok(value)` if found, or `None`.
427 pub fn get_str( 458 pub fn get_str(