Skip to main content

propel_core/
error.rs

1use std::path::PathBuf;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error("failed to load config from {path}")]
8    ConfigLoad {
9        path: PathBuf,
10        source: std::io::Error,
11    },
12
13    #[error("failed to parse config at {path}")]
14    ConfigParse {
15        path: PathBuf,
16        source: toml::de::Error,
17    },
18
19    #[error("invalid include path {path:?}: {reason}")]
20    InvalidIncludePath { path: String, reason: &'static str },
21
22    // ── Cargo project discovery ──
23    #[error("cargo metadata failed for {manifest_path}: {detail}")]
24    CargoMetadata {
25        manifest_path: PathBuf,
26        detail: String,
27    },
28
29    #[error("failed to resolve project directory {path}")]
30    ProjectDirResolve {
31        path: PathBuf,
32        source: std::io::Error,
33    },
34
35    #[error(
36        "no package found in {dir}; workspace members: {}",
37        format_members(workspace_members)
38    )]
39    NoPackageInDir {
40        dir: PathBuf,
41        workspace_members: Vec<String>,
42    },
43
44    #[error("no binary target in package '{package}' — propel requires a binary to deploy")]
45    NoBinaryTarget { package: String },
46
47    #[error(
48        "multiple binary targets found: {}; set `default-run` in Cargo.toml to select one",
49        names.join(", ")
50    )]
51    MultipleBinaries { names: Vec<String> },
52}
53
54fn format_members(members: &[String]) -> String {
55    if members.is_empty() {
56        "(none)".to_owned()
57    } else {
58        members.join(", ")
59    }
60}