1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Error types for workspace registry operations.
use std::path::PathBuf;
use thiserror::Error;
/// Specialized result type for workspace operations.
pub type WorkspaceResult<T> = Result<T, WorkspaceError>;
/// Errors emitted by workspace registry and discovery routines.
#[derive(Debug, Error)]
pub enum WorkspaceError {
/// Failure while reading or writing registry files.
#[error("workspace registry I/O error at {path}: {source}")]
Io {
/// Path associated with the I/O failure.
path: PathBuf,
/// Source error.
#[source]
source: std::io::Error,
},
/// Registry JSON failed to serialize or deserialize.
#[error("workspace registry serialization error: {0}")]
Serialization(#[from] serde_json::Error),
/// The registry version stored on disk is unsupported.
#[error(
"unsupported workspace registry version {found}; expected {expected}. \
Run `sqry workspace init` to rebuild the registry."
)]
UnsupportedVersion {
/// Version read from disk.
found: u32,
/// Version supported by this build.
expected: u32,
},
/// Attempted to insert a repository that already exists.
#[error("workspace repository with id '{id}' already exists")]
DuplicateRepository {
/// Conflicting repository identifier.
id: String,
},
/// Attempted to remove or fetch a repository that does not exist.
#[error("workspace repository with id '{id}' not found")]
RepositoryNotFound {
/// Missing repository identifier.
id: String,
},
/// Too many repositories discovered during workspace scanning (`DoS` prevention).
///
/// This limit prevents denial-of-service attacks via workspaces containing
/// thousands of repositories (each one carrying its own
/// `.sqry/graph/` artifact tree). See RR-10 Gap #2.
#[error(
"Too many repositories found in workspace: {found} exceeds limit of {limit}. \
Adjust SQRY_MAX_REPOSITORIES environment variable if needed."
)]
TooManyRepositories {
/// Number of repositories found before limit was hit.
found: usize,
/// Maximum allowed repositories (configurable via `SQRY_MAX_REPOSITORIES`).
limit: usize,
},
/// Errors produced during repository discovery.
#[error("failed to discover repositories in {root}: {source}")]
Discovery {
/// Root scanned during discovery.
root: PathBuf,
/// Source error.
#[source]
source: std::io::Error,
},
/// Query parsing error during workspace operations.
#[error("query parsing error: {message}")]
QueryParsing {
/// Error message.
message: String,
},
}
impl WorkspaceError {
/// Helper for wrapping I/O failures with path context.
pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
WorkspaceError::Io {
path: path.into(),
source,
}
}
}