-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.rs
More file actions
129 lines (122 loc) · 4.86 KB
/
Copy patherrors.rs
File metadata and controls
129 lines (122 loc) · 4.86 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//! Error type for the live module ([LIVE-PACKAGING]).
//!
//! Mirrors the JSON-RPC fault model the LSP / MCP transports expose.
//! Each variant carries enough structured context that a transport
//! adapter can lift it into a JSON-RPC error without losing fields.
//! [`LiveErrorWire`] is the serialisable shape consumed by transports;
//! its definition lives in `docs/models/live-ipc.td` and is re-exported
//! here so callers keep the single import path they already use.
use std::path::PathBuf;
use thiserror::Error;
pub use crate::wire_generated::LiveErrorWire;
use crate::error::CoreError;
/// Errors produced by the live module.
#[derive(Debug, Error)]
pub enum LiveError {
/// The snippet or open-buffer range submitted to
/// `duplicates/findSimilar` could not be parsed by the registered
/// language parser.
#[error("unparseable input at bytes {start_byte}..{end_byte}: {message}")]
UnparseableInput {
/// Optional path of the file the range refers to.
path: Option<PathBuf>,
/// Inclusive start byte of the range.
start_byte: usize,
/// Exclusive end byte of the range.
end_byte: usize,
/// Parser-supplied diagnostic message.
message: String,
},
/// A snippet was submitted with a `language` field that no
/// registered [`crate::lang::LanguageParser`] claims.
#[error("language {requested} is not supported (registered: {registered:?})")]
UnsupportedLanguage {
/// Language id the caller asked for.
requested: String,
/// Languages the session has parsers for.
registered: Vec<String>,
},
/// `embedding/setModel` was called with a `provider_id` that does
/// not match a registered embedding provider.
#[error("provider {requested} is not supported (registered: {registered:?})")]
UnsupportedProvider {
/// Provider id the caller asked for.
requested: String,
/// Providers the session supports.
registered: Vec<String>,
},
/// A request referenced a path outside the live workspace root.
/// Live sessions never touch files outside the root they were
/// constructed against ([MCP-SAFETY]).
#[error("path {path:?} is outside workspace root {workspace_root:?}")]
PathOutsideWorkspace {
/// Offending path.
path: PathBuf,
/// Pinned workspace root.
workspace_root: PathBuf,
},
/// `cluster/byId` was called with an id that does not appear in
/// the current report.
#[error("unknown cluster id {id}")]
UnknownCluster {
/// Caller-supplied cluster id.
id: String,
},
/// An embedding provider could not be reached. Wraps the upstream
/// transport diagnostic.
#[error("embedding provider at {endpoint} unreachable: {message}")]
ProviderUnreachable {
/// Endpoint that failed to respond.
endpoint: String,
/// Upstream transport message.
message: String,
},
/// The scheduler refused to dispatch because it is already
/// processing an in-flight pass.
#[error("scheduler busy: {message}")]
SchedulerBusy {
/// Diagnostic context.
message: String,
},
/// The filesystem watcher could not be started — e.g. OS-level
/// permission denied on the workspace root ([LIVE-WATCHER]).
#[error("filesystem watcher failed to start: {message}")]
WatcherInit {
/// OS or `notify` diagnostic message.
message: String,
},
/// The session was constructed from a cached report but the
/// background pipeline pass that backs parser-driven queries has
/// not yet completed ([LIVE-CACHE-SEED]).
#[error("analysis pipeline not ready yet")]
AnalysisNotReady,
/// Wraps any [`CoreError`] surfaced by the underlying pipeline.
#[error(transparent)]
Core(#[from] CoreError),
}
impl LiveError {
/// Lifts `self` into the serialisable [`LiveErrorWire`] shape.
#[must_use]
pub fn to_wire(&self) -> LiveErrorWire {
LiveErrorWire {
code: self.code().to_owned(),
message: self.to_string(),
}
}
/// Returns the short code for this variant.
#[must_use]
pub const fn code(&self) -> &'static str {
match self {
Self::UnparseableInput { .. } => "unparseable_input",
Self::UnsupportedLanguage { .. } => "unsupported_language",
Self::UnsupportedProvider { .. } => "unsupported_provider",
Self::PathOutsideWorkspace { .. } => "path_outside_workspace",
Self::UnknownCluster { .. } => "unknown_cluster",
Self::ProviderUnreachable { .. } => "provider_unreachable",
Self::SchedulerBusy { .. } => "scheduler_busy",
Self::WatcherInit { .. } => "watcher_init",
Self::AnalysisNotReady => "analysis_not_ready",
Self::Core(_) => "core_error",
}
}
}