1use crate::scrub::scrub_secret;
6use std::fmt;
7
8#[derive(Debug)]
10pub struct ScanError {
11 message: String,
12}
13
14impl ScanError {
15 pub fn new(message: impl std::fmt::Display) -> Self {
17 Self {
18 message: crate::scrub::scrub(&message.to_string()),
19 }
20 }
21
22 pub fn with_secret(message: impl std::fmt::Display, secret: &str) -> Self {
24 Self {
25 message: scrub_secret(&message.to_string(), secret),
26 }
27 }
28}
29
30impl fmt::Display for ScanError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 f.write_str(&self.message)
33 }
34}
35
36impl std::error::Error for ScanError {}
37
38impl From<anyhow::Error> for ScanError {
39 fn from(err: anyhow::Error) -> Self {
40 Self::new(err)
41 }
42}
43
44impl From<sqlx::Error> for ScanError {
45 fn from(err: sqlx::Error) -> Self {
46 Self::new(err)
47 }
48}