pedant_core/resolution/rust/error.rs
1//! Typed failures returned while loading a Cargo project.
2
3/// Failure encountered while reading a repository's Cargo manifests.
4#[derive(Debug, thiserror::Error)]
5pub enum RustProjectError {
6 /// The supplied root is not a directory holding a readable `Cargo.toml`.
7 #[error("invalid project root {path}: {reason}")]
8 InvalidRoot {
9 /// The rejected root.
10 path: Box<str>,
11 /// Why the root cannot anchor a project.
12 reason: Box<str>,
13 },
14 /// A path the loader reached is not inside the repository root.
15 #[error("path {path} lies outside the project root {root}")]
16 OutOfRoot {
17 /// The path that cannot be made repository-relative.
18 path: Box<str>,
19 /// The root that does not contain it.
20 root: Box<str>,
21 },
22 /// A path beneath the repository root is not valid UTF-8.
23 #[error("path {path} beneath the project root is not valid UTF-8")]
24 NonUtf8Path {
25 /// The offending path, rendered lossily for the message only.
26 path: Box<str>,
27 },
28 /// A manifest or a directory scanned for members could not be read.
29 #[error("failed to read {path}: {source}")]
30 ManifestRead {
31 /// The unreadable path.
32 path: Box<str>,
33 /// The underlying I/O failure.
34 #[source]
35 source: std::io::Error,
36 },
37 /// A manifest is not valid TOML, or does not match Cargo's schema.
38 #[error("failed to parse manifest {path}: {message}")]
39 ManifestParse {
40 /// The rejected manifest.
41 path: Box<str>,
42 /// The single-owner reason this manifest was rejected.
43 message: Box<str>,
44 },
45 /// A package declares no version and inherits none.
46 #[error("manifest {path} declares no package version")]
47 MissingPackageVersion {
48 /// The manifest without a resolvable version.
49 path: Box<str>,
50 },
51 /// A package inherits its version from a workspace that declares none.
52 #[error("manifest {path} inherits a package version that {workspace} does not declare")]
53 MissingWorkspacePackageVersion {
54 /// The inheriting manifest.
55 path: Box<str>,
56 /// The workspace manifest that owes the value.
57 workspace: Box<str>,
58 },
59 /// A resolved package version is not valid SemVer.
60 #[error("manifest {path} declares an invalid package version {version}: {source}")]
61 InvalidPackageVersion {
62 /// The manifest holding the rejected version.
63 path: Box<str>,
64 /// The exact rejected version text.
65 version: Box<str>,
66 /// The underlying SemVer failure.
67 #[source]
68 source: semver::Error,
69 },
70 /// A package declares an edition Cargo does not recognize.
71 #[error("manifest {path} declares an invalid package edition {edition}")]
72 InvalidPackageEdition {
73 /// The manifest holding the rejected edition.
74 path: Box<str>,
75 /// The exact rejected edition text.
76 edition: Box<str>,
77 },
78 /// A package inherits its edition from a workspace that declares none.
79 #[error("manifest {path} inherits a package edition that {workspace} does not declare")]
80 MissingWorkspacePackageEdition {
81 /// The inheriting manifest.
82 path: Box<str>,
83 /// The workspace manifest that owes the value.
84 workspace: Box<str>,
85 },
86 /// The project holds more manifests than the configured limit allows.
87 #[error("project holds more than {limit} manifests")]
88 LimitExceeded {
89 /// The configured manifest ceiling.
90 limit: u32,
91 },
92 /// Expanding the workspace member globs walked more of the tree than the
93 /// configured limit allows.
94 ///
95 /// Separate from [`Self::LimitExceeded`] because it is crossed before any
96 /// manifest is read: the subject is directories visited, not manifests
97 /// held, and the operator's fix is a narrower `members` pattern rather
98 /// than a higher manifest ceiling.
99 #[error("expanding the workspace members visited more than {limit} directory entries")]
100 MemberScanLimitExceeded {
101 /// The configured member-scan ceiling.
102 limit: u32,
103 },
104}