Skip to main content

systemprompt_models/execution/context/
context_error.rs

1//! Request-context construction error types.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use systemprompt_identifiers::TaskId;
7use systemprompt_traits::BoxedSource;
8use thiserror::Error;
9
10#[derive(Debug, Clone)]
11pub enum ContextIdSource {
12    Direct(String),
13    FromTask { task_id: TaskId },
14}
15
16#[derive(Debug, Error)]
17pub enum ContextExtractionError {
18    #[error("Missing required header: {0}")]
19    MissingHeader(String),
20
21    #[error("Missing Authorization header")]
22    MissingAuthHeader,
23
24    #[error("Invalid JWT token: {0}")]
25    InvalidToken(#[source] BoxedSource),
26
27    #[error("Token revoked")]
28    Revoked,
29
30    #[error("JWT missing required 'session_id' claim")]
31    MissingSessionId,
32
33    #[error("JWT missing required 'sub' (user_id) claim")]
34    MissingUserId,
35
36    #[error(
37        "Missing required 'x-context-id' header (for MCP routes) or contextId in body (for A2A \
38         routes)"
39    )]
40    MissingContextId,
41
42    #[error("Invalid header value: {header}, reason: {reason}")]
43    InvalidHeaderValue { header: String, reason: String },
44
45    #[error("Invalid user_id: {0}")]
46    InvalidUserId(String),
47
48    #[error("Database error: {context}: {source}")]
49    DatabaseError {
50        context: String,
51        #[source]
52        source: BoxedSource,
53    },
54
55    #[error("User not found: {0}")]
56    UserNotFound(String),
57
58    #[error("Forbidden header '{header}': {reason}")]
59    ForbiddenHeader { header: String, reason: String },
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
63pub enum RequestContextValidationError {
64    #[error("Missing task_id for task execution")]
65    MissingTaskId,
66
67    #[error("Missing authentication token")]
68    MissingAuthToken,
69
70    #[error("User is not authenticated")]
71    Unauthenticated,
72}