Skip to main content

zendriver_interception/
error.rs

1//! Interception-layer errors.
2
3/// Errors surfaced by the interception API.
4///
5/// The [`Self::Call`] variant is boxed so the enum stays small
6/// (`size_of::<usize>()` for the heavy arm). Without boxing, every
7/// `Result<T, InterceptionError>` would carry the full
8/// `zendriver_transport::CallError` payload — large enough to trip
9/// clippy's `result_large_err` lint at every fallible call site.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum InterceptionError {
13    #[error("call failed: {0}")]
14    Call(Box<zendriver_transport::CallError>),
15
16    #[error("invalid url pattern: {0}")]
17    InvalidPattern(String),
18
19    #[error("interception already started")]
20    AlreadyStarted,
21
22    #[error("interception not started")]
23    NotStarted,
24
25    #[error("subscription channel closed")]
26    SubscriptionClosed,
27
28    #[error("invalid response from CDP: {0}")]
29    InvalidResponse(String),
30
31    #[error("wrong interception stage: this action is only valid at the Response stage")]
32    WrongStage,
33}
34
35impl From<zendriver_transport::CallError> for InterceptionError {
36    fn from(e: zendriver_transport::CallError) -> Self {
37        Self::Call(Box::new(e))
38    }
39}
40
41#[cfg(test)]
42#[allow(clippy::panic, clippy::unwrap_used)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn display_invalid_pattern() {
48        let e = InterceptionError::InvalidPattern("**bad".into());
49        assert_eq!(e.to_string(), "invalid url pattern: **bad");
50    }
51}