use crate::resolution::read::ReadFault;
use super::limits::ResolutionLimits;
#[derive(Debug, thiserror::Error)]
pub enum RustSourceFault {
#[error("the source could not be read: {0}")]
Unreadable(#[source] std::io::Error),
#[error("{path} resolves outside the root the provider reads beneath, at {landing}")]
OutOfRoot {
path: Box<str>,
landing: Box<str>,
},
#[error("the provider already holds its ceiling of {ceiling} source files")]
SourceFiles {
ceiling: u64,
},
#[error("the source holds more than the provider's ceiling of {ceiling} bytes")]
SourceBytes {
ceiling: u64,
},
#[error("the source passes the provider's ceiling of {ceiling} total source bytes")]
TotalBytes {
ceiling: u64,
},
#[error("the source is not valid UTF-8: {reason}")]
InvalidUtf8 {
reason: Box<str>,
},
#[error("the source nests deeper than the provider's ceiling of {ceiling}")]
SyntaxDepth {
ceiling: u64,
},
#[error("the source is not valid Rust: {reason}")]
Unparsed {
reason: Box<str>,
},
#[error("{path} was already refused by this provider")]
Refused {
path: Box<str>,
},
}
impl RustSourceFault {
pub(crate) fn of_read(fault: ReadFault, limits: ResolutionLimits) -> Self {
match fault {
ReadFault::Unreadable(source) => Self::Unreadable(source),
ReadFault::SourceBytes => Self::SourceBytes {
ceiling: limits.max_source_file_bytes,
},
ReadFault::TotalBytes => Self::TotalBytes {
ceiling: limits.max_total_source_bytes,
},
}
}
}