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("Pre-release error: {0}")]
35    Prerelease(String),
36
37    #[error("Invalid data: {0}")]
38    InvalidData(String),
39
40    #[error("Not found: {0}")]
41    NotFound(String),
42}
43
44/// Errors that can occur when working with workspaces
45#[derive(Debug, thiserror::Error)]
46pub enum WorkspaceError {
47    #[error("IO error: {0}")]
48    Io(#[from] io::Error),
49    #[error("No Cargo.toml with [workspace] found")]
50    NotFound,
51    #[error("Invalid Cargo.toml: {0}")]
52    InvalidToml(String),
53    #[error("Invalid workspace: {0}")]
54    InvalidWorkspace(String),
55}
56
57/// Helper to create an IO error with file path context
58pub fn io_error_with_path<P: AsRef<Path>>(error: io::Error, path: P) -> io::Error {
59    io::Error::new(
60        error.kind(),
61        format!("{}: {}", path.as_ref().display(), error),
62    )
63}