sampo_core/
errors.rs

1use std::io;
2use std::path::Path;
3
4/// Canonical result type for Sampo code
5pub type Result<T> = std::result::Result<T, SampoError>;
6
7/// Common error type for Sampo operations
8#[derive(Debug, thiserror::Error)]
9pub enum SampoError {
10    #[error("IO error: {0}")]
11    Io(#[from] io::Error),
12
13    #[error("Workspace error: {0}")]
14    Workspace(#[from] WorkspaceError),
15
16    #[error("Configuration error: {0}")]
17    Config(String),
18
19    #[error("Changeset error: {0}")]
20    Changeset(String),
21
22    #[error("Git error: {0}")]
23    Git(String),
24
25    #[error("GitHub error: {0}")]
26    GitHub(String),
27
28    #[error("Publish error: {0}")]
29    Publish(String),
30
31    #[error("Release error: {0}")]
32    Release(String),
33
34    #[error("Invalid data: {0}")]
35    InvalidData(String),
36
37    #[error("Not found: {0}")]
38    NotFound(String),
39}
40
41/// Errors that can occur when working with workspaces
42#[derive(Debug, thiserror::Error)]
43pub enum WorkspaceError {
44    #[error("IO error: {0}")]
45    Io(#[from] io::Error),
46    #[error("No Cargo.toml with [workspace] found")]
47    NotFound,
48    #[error("Invalid Cargo.toml: {0}")]
49    InvalidToml(String),
50    #[error("Invalid workspace: {0}")]
51    InvalidWorkspace(String),
52}
53
54/// Helper to create an IO error with file path context
55pub fn io_error_with_path<P: AsRef<Path>>(error: io::Error, path: P) -> io::Error {
56    io::Error::new(
57        error.kind(),
58        format!("{}: {}", path.as_ref().display(), error),
59    )
60}