Skip to main content

codemode/
error.rs

1use thiserror::Error;
2
3/// Result type used throughout `codemode`.
4pub type CodeModeResult<T> = Result<T, CodeModeError>;
5
6/// Errors produced by the codemode engine and its extension points.
7#[derive(Debug, Error)]
8pub enum CodeModeError {
9    #[error("SearchCode requires a non-empty query")]
10    EmptySearchQuery,
11
12    #[error("native function not found: {name}")]
13    NativeFunctionNotFound { name: String },
14
15    #[error("failed to create codemode tokio runtime")]
16    TokioRuntimeInit {
17        #[source]
18        source: std::io::Error,
19    },
20
21    #[error("codemode worker join error: {reason}")]
22    WorkerJoin { reason: String },
23
24    #[error("failed to install codemode globals: {reason}")]
25    InstallGlobals { reason: String },
26
27    #[error("failed to compile code: {reason}")]
28    CompileCode { reason: String },
29
30    #[error("RunCode.code must be an async zero-arg function expression")]
31    InvalidClosureShape,
32
33    #[error("RunCode.code did not resolve to a callable function")]
34    ClosureNotCallable,
35
36    #[error("failed to execute code: {reason}")]
37    ExecuteCode { reason: String },
38
39    #[error("codemode isolate panicked during execution")]
40    IsolatePanicked,
41
42    #[error("fetch worker panicked")]
43    FetchWorkerPanicked,
44
45    #[error("failed to serialize native function names")]
46    NativeNamesSerialization {
47        #[source]
48        source: serde_json::Error,
49    },
50
51    #[error("invalid fetch method `{method}`: {reason}")]
52    InvalidFetchMethod { method: String, reason: String },
53
54    #[error("fetch init.headers must be an object")]
55    FetchHeadersNotObject,
56
57    #[error("invalid header name `{key}`: {reason}")]
58    InvalidHeaderName { key: String, reason: String },
59
60    #[error("header `{key}` must be a string")]
61    HeaderValueNotString { key: String },
62
63    #[error("invalid value for header `{key}`: {reason}")]
64    InvalidHeaderValue { key: String, reason: String },
65
66    #[error(transparent)]
67    Http {
68        #[from]
69        source: reqwest::Error,
70    },
71}