Skip to main content

pdb_bindgen_codegen/config/
error.rs

1use crate::PdbFilenameErrorKind;
2use std::error::Error;
3use std::fmt;
4
5/// Describes a configuration validation failure.
6#[derive(Clone, Debug, Eq, PartialEq)]
7#[non_exhaustive]
8pub enum ConfigError {
9    /// A logical PDB filename is invalid.
10    InvalidPdbFilename {
11        /// The rejected filename.
12        filename: String,
13        /// The validation failure category.
14        reason: PdbFilenameErrorKind,
15    },
16    /// A logical image key is empty.
17    EmptyImageKey,
18    /// A directly supplied local PDB path is empty.
19    EmptyLocalPdbPath,
20    /// A cache directory path is empty.
21    EmptyCachePath,
22    /// A logical image key is already present.
23    DuplicateImageKey {
24        /// The duplicate exact key.
25        key: String,
26    },
27    /// A Symbol Server URL is invalid.
28    InvalidSymbolServer {
29        /// The rejected URL.
30        url: String,
31        /// The validation failure category.
32        reason: SymbolServerErrorKind,
33    },
34    /// A source root path is empty.
35    EmptySourceRoot,
36    /// A custom cfg atom name is not one Rust cfg identifier.
37    InvalidCfgName {
38        /// The rejected cfg name.
39        name: String,
40    },
41}
42
43impl fmt::Display for ConfigError {
44    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
45        match self {
46            Self::InvalidPdbFilename { filename, reason } => {
47                write!(
48                    formatter,
49                    "invalid logical PDB filename {filename:?}: {reason}"
50                )
51            }
52            Self::EmptyImageKey => formatter.write_str("image key must not be empty"),
53
54            Self::EmptyLocalPdbPath => formatter.write_str("local PDB path must not be empty"),
55            Self::EmptyCachePath => formatter.write_str("cache directory must not be empty"),
56            Self::DuplicateImageKey { key } => write!(formatter, "duplicate image key {key:?}"),
57            Self::InvalidSymbolServer { url, reason } => {
58                write!(formatter, "invalid Symbol Server URL {url:?}: {reason}")
59            }
60            Self::EmptySourceRoot => formatter.write_str("source root path must not be empty"),
61            Self::InvalidCfgName { name } => write!(
62                formatter,
63                "invalid cfg name {name:?}: expected one Rust cfg identifier"
64            ),
65        }
66    }
67}
68
69impl Error for ConfigError {}
70
71/// Describes why a Symbol Server URL is invalid.
72#[derive(Clone, Copy, Debug, Eq, PartialEq)]
73#[non_exhaustive]
74pub enum SymbolServerErrorKind {
75    /// The URL does not start with `http://` or `https://`.
76    Scheme,
77    /// The URL has no authority after its scheme.
78    MissingAuthority,
79    /// The URL contains characters not accepted by this configuration layer.
80    InvalidCharacter,
81}
82
83impl fmt::Display for SymbolServerErrorKind {
84    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
85        formatter.write_str(match self {
86            Self::Scheme => "expected an http:// or https:// URL",
87            Self::MissingAuthority => "server authority must not be empty",
88            Self::InvalidCharacter => {
89                "ASCII whitespace, control characters, queries, and fragments are not allowed"
90            }
91        })
92    }
93}