Show More
@@ -416,12 +416,43 b' impl Config {' | |||||
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 => |
|
419 | None => { | |
|
420 | self.print_devel_warning(section, item)?; | |||
|
421 | Ok(None) | |||
|
422 | } | |||
420 | } |
|
423 | } | |
421 | } |
|
424 | } | |
422 | } |
|
425 | } | |
423 | } |
|
426 | } | |
424 |
|
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(()) | |||
|
454 | } | |||
|
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( |
General Comments 0
You need to be logged in to leave comments.
Login now