Skip to main content

rskit_logging/
error.rs

1//! Error helpers for logging setup.
2
3/// Result type returned by fallible logging setup APIs.
4pub type LoggingResult<T> = rskit_errors::AppResult<T>;
5
6#[cfg(feature = "setup")]
7pub(crate) fn invalid_regex(
8    pattern: impl Into<String>,
9    cause: regex::Error,
10) -> rskit_errors::AppError {
11    use rskit_errors::{AppError, ErrorCode};
12    let pattern = pattern.into();
13    AppError::new(ErrorCode::InvalidFormat, "invalid masking regex pattern")
14        .with_detail("pattern", pattern)
15        .with_cause(cause)
16}
17
18#[cfg(feature = "setup")]
19pub(crate) fn log_file_open(
20    path: impl Into<String>,
21    cause: std::io::Error,
22) -> rskit_errors::AppError {
23    let path = path.into();
24    rskit_errors::AppError::from(cause)
25        .context("open log output file")
26        .with_detail("path", path)
27}
28
29#[cfg(feature = "otlp")]
30pub(crate) fn invalid_protocol(protocol: impl Into<String>) -> rskit_errors::AppError {
31    let protocol = protocol.into();
32    rskit_errors::AppError::invalid_input("otlp.protocol", "expected `grpc` or `http`")
33        .with_detail("protocol", protocol)
34}
35
36#[cfg(feature = "otlp")]
37pub(crate) fn grpc_headers_not_supported() -> rskit_errors::AppError {
38    rskit_errors::AppError::invalid_input(
39        "otlp.headers",
40        "custom headers are supported only with the `http` OTLP protocol",
41    )
42}
43
44#[cfg(feature = "otlp")]
45pub(crate) fn otlp_exporter(
46    cause: impl std::error::Error + Send + Sync + 'static,
47) -> rskit_errors::AppError {
48    rskit_errors::AppError::external_service("otlp", cause)
49}
50
51#[cfg(feature = "otlp")]
52pub(crate) fn otlp_shutdown(
53    cause: impl std::error::Error + Send + Sync + 'static,
54) -> rskit_errors::AppError {
55    rskit_errors::AppError::external_service("otlp", cause).context("shutdown logging exporter")
56}