summaryrefslogtreecommitdiffstats
path: root/vendor/icu_provider/src/error.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/icu_provider/src/error.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/icu_provider/src/error.rs')
-rw-r--r--vendor/icu_provider/src/error.rs31
1 files changed, 24 insertions, 7 deletions
diff --git a/vendor/icu_provider/src/error.rs b/vendor/icu_provider/src/error.rs
index 05a48f9b7..23f141e02 100644
--- a/vendor/icu_provider/src/error.rs
+++ b/vendor/icu_provider/src/error.rs
@@ -101,6 +101,9 @@ pub struct DataError {
/// Additional context, if available.
pub str_context: Option<&'static str>,
+
+ /// Whether this error was created in silent mode to not log.
+ pub silent: bool,
}
impl fmt::Display for DataError {
@@ -110,10 +113,10 @@ impl fmt::Display for DataError {
write!(f, ": {}", self.kind)?;
}
if let Some(key) = self.key {
- write!(f, " (key: {})", key)?;
+ write!(f, " (key: {key})")?;
}
if let Some(str_context) = self.str_context {
- write!(f, ": {}", str_context)?;
+ write!(f, ": {str_context}")?;
}
Ok(())
}
@@ -129,6 +132,7 @@ impl DataErrorKind {
kind: self,
key: None,
str_context: None,
+ silent: false,
}
}
@@ -165,6 +169,7 @@ impl DataError {
kind: DataErrorKind::Custom,
key: None,
str_context: Some(str_context),
+ silent: false,
}
}
@@ -175,6 +180,7 @@ impl DataError {
kind: self.kind,
key: Some(key),
str_context: self.str_context,
+ silent: self.silent,
}
}
@@ -185,6 +191,7 @@ impl DataError {
kind: self.kind,
key: self.key,
str_context: Some(context),
+ silent: self.silent,
}
}
@@ -199,10 +206,13 @@ impl DataError {
/// If the "log_error_context" Cargo feature is enabled, this logs the whole request. Either way,
/// it returns an error with the resource key portion of the request as context.
#[cfg_attr(not(feature = "log_error_context"), allow(unused_variables))]
- pub fn with_req(self, key: DataKey, req: DataRequest) -> Self {
+ pub fn with_req(mut self, key: DataKey, req: DataRequest) -> Self {
+ if req.metadata.silent {
+ self.silent = true;
+ }
// Don't write out a log for MissingDataKey since there is no context to add
#[cfg(feature = "log_error_context")]
- if self.kind != DataErrorKind::MissingDataKey {
+ if !self.silent && self.kind != DataErrorKind::MissingDataKey {
log::warn!("{} (key: {}, request: {})", self, key, req);
}
self.with_key(key)
@@ -216,7 +226,9 @@ impl DataError {
#[cfg_attr(not(feature = "log_error_context"), allow(unused_variables))]
pub fn with_path_context<P: AsRef<std::path::Path> + ?Sized>(self, path: &P) -> Self {
#[cfg(feature = "log_error_context")]
- log::warn!("{} (path: {:?})", self, path.as_ref());
+ if !self.silent {
+ log::warn!("{} (path: {:?})", self, path.as_ref());
+ }
self
}
@@ -228,7 +240,9 @@ impl DataError {
#[inline]
pub fn with_display_context<D: fmt::Display + ?Sized>(self, context: &D) -> Self {
#[cfg(feature = "log_error_context")]
- log::warn!("{}: {}", self, context);
+ if !self.silent {
+ log::warn!("{}: {}", self, context);
+ }
self
}
@@ -240,7 +254,9 @@ impl DataError {
#[inline]
pub fn with_debug_context<D: fmt::Debug + ?Sized>(self, context: &D) -> Self {
#[cfg(feature = "log_error_context")]
- log::warn!("{}: {:?}", self, context);
+ if !self.silent {
+ log::warn!("{}: {:?}", self, context);
+ }
self
}
@@ -250,6 +266,7 @@ impl DataError {
kind: DataErrorKind::MismatchedType(core::any::type_name::<T>()),
key: None,
str_context: None,
+ silent: false,
}
}
}