pub enum KindlyError {
Show 21 variants
DisplayError(String),
TerminalError,
ValidationError(String),
InvalidInput {
reason: String,
},
InvalidConfig {
field: String,
reason: String,
},
FileError(Error),
PathNotFound {
path: String,
},
SerializationError(Error),
FormatError {
expected: String,
actual: String,
},
ScannerError(String),
ThreatDetected {
threat_type: String,
location: String,
},
ResourceError {
resource: String,
limit: String,
},
TimeoutError(u64),
NetworkError(String),
ConnectionError {
endpoint: String,
reason: String,
},
AuthError {
reason: String,
},
Unauthorized {
action: String,
},
ProtocolError {
code: i32,
message: String,
},
MethodNotFound {
method: String,
},
ConfigError(String),
Internal(String),
}Expand description
KindlyGuard error types with actionable recovery strategies
Variants§
DisplayError(String)
TerminalError
ValidationError(String)
Command validation failed. This occurs when user input doesn’t meet expected format or contains forbidden patterns.
Security Impact: Medium - Could indicate probing for vulnerabilities Recovery: Fail fast, log attempt, increment failure counter Safe Handling: Never echo back the invalid input verbatim
InvalidInput
Invalid input detected during parameter validation.
Security Impact: High - Often precedes injection attacks Recovery: Reject immediately, audit log with sanitized details Safe Handling: Return generic “Invalid input” without specifics Example: SQL injection attempts, path traversal patterns
InvalidConfig
FileError(Error)
PathNotFound
SerializationError(Error)
FormatError
ScannerError(String)
ThreatDetected
CRITICAL SECURITY ERROR: Active threat detected in input/output.
When It Occurs:
- Unicode attacks (invisible characters, RTL override)
- Injection attempts (SQL, command, path traversal)
- Known malicious patterns
Security Impact: CRITICAL - Active attack in progress Recovery: ALWAYS FAIL CLOSED
- Block the request immediately
- Generate high-priority audit event
- Increment threat counter for client
- Consider temporary IP ban after repeated attempts
Safe Handling:
- NEVER include threat details in user-facing messages
- Log full details to secure audit log only
- Return generic “Security policy violation” to client
- Preserve evidence for forensic analysis
Example Response:
{
"error": {
"code": -32004,
"message": "Request blocked by security policy"
}
}ResourceError
Resource exhaustion detected - possible DoS attempt.
Security Impact: High - Resource exhaustion attacks Recovery: Rate limit, circuit break, graceful degradation Safe Handling: Generic message, preserve service availability
Common Scenarios:
- Memory limit exceeded (large file uploads)
- Connection pool exhausted (connection flood)
- CPU quota exceeded (computational DoS)
Response Strategy:
- Apply exponential backoff to client
- Shed load if necessary
- Return 503 Service Unavailable with Retry-After header
TimeoutError(u64)
Operation timeout - prevents indefinite resource holding.
Security Impact: Medium - Possible slowloris attack Recovery: Clean up resources, fail fast Safe Handling: No internal timing information in response
NetworkError(String)
ConnectionError
AuthError
CRITICAL: Authentication failure - possible credential attack.
Security Impact: CRITICAL - Unauthorized access attempt Recovery: ALWAYS FAIL CLOSED
Required Actions:
- Log to security audit with timestamp, IP, attempt details
- Increment auth failure counter for IP/client
- Apply progressive delay (2^n seconds after n failures)
- Trigger account lockout after threshold (e.g., 5 attempts)
- Alert on patterns (distributed attempts, timing attacks)
Safe Handling:
- NEVER reveal why authentication failed
- Use constant-time comparison for credentials
- Return identical error for “user not found” vs “wrong password”
- Generic message: “Authentication failed”
Logging Requirements:
audit_log.critical(AuditEvent::AuthFailure {
client_ip: ip,
user_id: sanitize(user_id), // Hash if sensitive
timestamp: SystemTime::now(),
failure_count: count,
});CRITICAL: Authorization failure - privilege escalation attempt.
Security Impact: CRITICAL - Possible privilege escalation Recovery: DENY and audit
Required Actions:
- Deny the action immediately
- Log full context to security audit
- Check for authorization probe patterns
- Consider session termination for repeated attempts
Safe Handling:
- Return minimal information: “Unauthorized”
- Don’t reveal what permissions are needed
- Don’t indicate if resource exists
Fields
ProtocolError
MethodNotFound
ConfigError(String)
Internal(String)
Implementations§
Source§impl KindlyError
impl KindlyError
Sourcepub const fn severity(&self) -> ErrorSeverity
pub const fn severity(&self) -> ErrorSeverity
Get the severity level of the error
Sourcepub const fn is_retryable(&self) -> bool
pub const fn is_retryable(&self) -> bool
Check if the error is retryable
Sourcepub fn user_message(&self) -> String
pub fn user_message(&self) -> String
Get a user-friendly error message
Sourcepub const fn to_protocol_code(&self) -> i32
pub const fn to_protocol_code(&self) -> i32
Convert to MCP protocol error code
Trait Implementations§
Source§impl Debug for KindlyError
impl Debug for KindlyError
Source§impl Display for KindlyError
impl Display for KindlyError
Source§impl Error for KindlyError
impl Error for KindlyError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for KindlyError
impl From<Error> for KindlyError
Auto Trait Implementations§
impl Freeze for KindlyError
impl !RefUnwindSafe for KindlyError
impl Send for KindlyError
impl Sync for KindlyError
impl Unpin for KindlyError
impl !UnwindSafe for KindlyError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more