use std::path::PathBuf;
use thiserror::Error;
pub type WorkspaceResult<T> = Result<T, WorkspaceError>;
#[derive(Debug, Error)]
pub enum WorkspaceError {
#[error("workspace registry I/O error at {path}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("workspace registry serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error(
"unsupported workspace registry version {found}; expected {expected}. \
Run `sqry workspace init` to rebuild the registry."
)]
UnsupportedVersion {
found: u32,
expected: u32,
},
#[error("workspace repository with id '{id}' already exists")]
DuplicateRepository {
id: String,
},
#[error("workspace repository with id '{id}' not found")]
RepositoryNotFound {
id: String,
},
#[error(
"Too many repositories found in workspace: {found} exceeds limit of {limit}. \
Adjust SQRY_MAX_REPOSITORIES environment variable if needed."
)]
TooManyRepositories {
found: usize,
limit: usize,
},
#[error("failed to discover repositories in {root}: {source}")]
Discovery {
root: PathBuf,
#[source]
source: std::io::Error,
},
#[error("query parsing error: {message}")]
QueryParsing {
message: String,
},
}
impl WorkspaceError {
pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
WorkspaceError::Io {
path: path.into(),
source,
}
}
}