1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Error types for the MIB loading pipeline.
//!
//! The primary error type is [`LoadError`], returned by [`Loader::load`](crate::Loader::load)
//! and the free function [`load`](crate::load::load).
use crate::types::DiagnosticReport;
/// Errors returned by [`Loader::load`](crate::Loader::load) and the
/// free function [`load`](crate::load::load).
///
/// All variants carry enough context for callers to present useful error
/// messages. The [`Display`](std::fmt::Display) implementation produces
/// human-readable text for each case.
#[derive(Debug, thiserror::Error)]
pub enum LoadError {
/// No [`Source`](crate::Source)s were configured on the [`Loader`](crate::Loader).
#[error("no MIB sources provided")]
NoSources,
/// One or more explicitly requested modules were not found after resolution.
///
/// The contained `Vec` lists the missing module names.
#[error("requested modules not found: {}", .0.join(", "))]
MissingModules(Vec<String>),
/// A diagnostic exceeded the configured fail-at severity threshold.
///
/// `report` contains every diagnostic collected during the load, not
/// only those at or above the failure threshold. The diagnostics are
/// ordered by pipeline phase, code, effective severity, module, stable
/// source identity and label, half-open source range, and message. The
/// report retains every source document needed to derive locations after
/// the failed MIB has been dropped.
///
/// See [`DiagnosticConfig`](crate::DiagnosticConfig) for threshold configuration.
#[error("diagnostic threshold exceeded")]
DiagnosticThreshold {
/// All diagnostics and their retained sources from the failed load.
report: DiagnosticReport,
},
/// A [`Source`](crate::Source) implementation returned a custom error.
///
/// Use [`LoadError::from_source`] to construct this variant from an
/// arbitrary error type.
#[error("source error")]
Source(#[source] Box<dyn std::error::Error + Send + Sync>),
/// An I/O error occurred while reading MIB files from disk.
#[error("I/O error")]
Io(#[from] std::io::Error),
}
impl LoadError {
/// Wrap an arbitrary error as a [`LoadError::Source`].
///
/// Useful for custom [`Source`](crate::Source) implementations that
/// need to return domain-specific errors through the loading pipeline.
pub fn from_source(err: impl std::error::Error + Send + Sync + 'static) -> Self {
LoadError::Source(Box::new(err))
}
}