KindlyError

Enum KindlyError 

Source
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

Fields

§reason: String
§

InvalidConfig

Fields

§field: String
§reason: String
§

FileError(Error)

§

PathNotFound

Fields

§path: String
§

SerializationError(Error)

§

FormatError

Fields

§expected: String
§actual: String
§

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"
  }
}

Fields

§threat_type: String
§location: String
§

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

Fields

§resource: String
§limit: String
§

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

Fields

§endpoint: String
§reason: String
§

AuthError

CRITICAL: Authentication failure - possible credential attack.

Security Impact: CRITICAL - Unauthorized access attempt Recovery: ALWAYS FAIL CLOSED

Required Actions:

  1. Log to security audit with timestamp, IP, attempt details
  2. Increment auth failure counter for IP/client
  3. Apply progressive delay (2^n seconds after n failures)
  4. Trigger account lockout after threshold (e.g., 5 attempts)
  5. 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,
});

Fields

§reason: String
§

Unauthorized

CRITICAL: Authorization failure - privilege escalation attempt.

Security Impact: CRITICAL - Possible privilege escalation Recovery: DENY and audit

Required Actions:

  1. Deny the action immediately
  2. Log full context to security audit
  3. Check for authorization probe patterns
  4. 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

§action: String
§

ProtocolError

Fields

§code: i32
§message: String
§

MethodNotFound

Fields

§method: String
§

ConfigError(String)

§

Internal(String)

Implementations§

Source§

impl KindlyError

Source

pub const fn severity(&self) -> ErrorSeverity

Get the severity level of the error

Source

pub const fn is_retryable(&self) -> bool

Check if the error is retryable

Source

pub fn user_message(&self) -> String

Get a user-friendly error message

Source

pub const fn to_protocol_code(&self) -> i32

Convert to MCP protocol error code

Trait Implementations§

Source§

impl Debug for KindlyError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for KindlyError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for KindlyError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for KindlyError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for KindlyError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToLine for T
where T: Display,

Source§

fn to_line(&self) -> Line<'_>

Converts the value to a Line.
Source§

impl<T> ToSpan for T
where T: Display,

Source§

fn to_span(&self) -> Span<'_>

Converts the value to a Span.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToText for T
where T: Display,

Source§

fn to_text(&self) -> Text<'_>

Converts the value to a Text.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,