Expand description
§Error Handling for Fern Shell
This module provides a comprehensive error handling system designed for both developers and end users. It follows these principles:
-
Rich diagnostics — Errors include source locations, suggestions, and documentation links to help users fix problems.
-
Severity levels — Not all problems are equal. Warnings allow the shell to continue while errors require user intervention.
-
Notification-ready — Errors implement
Notifiableso they can be displayed as desktop notifications when the notification system is available. -
Type-safe error codes — Each error variant has a unique code that can be looked up in documentation.
§Error Hierarchy
FernError (top-level)
├── ConfigError — Configuration parsing and validation
├── IoError — File system operations
├── WatchError — File watching failures
└── IpcError — D-Bus communication errors§Usage
ⓘ
use fernctl::error::{Result, ConfigError, Severity};
fn validate_color(value: &str) -> Result<Color> {
parse_hex_color(value).map_err(|_| ConfigError::InvalidColor {
value: value.to_string(),
span: None,
})
}§Integration with miette
All error types implement [miette::Diagnostic], enabling rich terminal output:
Error: fern::config::invalid_color
× Invalid color format: #gg0000
╭─[config.toml:5:10]
4 │ [appearance]
5 │ accent = "#gg0000"
· ────────── this color value
╰────
help: Colors must be hex format: #RRGGBB or #RRGGBBAAModules§
- config 🔒
- Configuration Error Types
- notify 🔒
- Notification Integration for Errors
- severity 🔒
- Severity Levels for Errors and Notifications
Structs§
- Notification
- A notification ready to be sent to the desktop notification service.
Enums§
- Config
Error - Errors that occur during configuration parsing and validation.
- Fern
Error - The top-level error type for all fernctl operations.
- Severity
- Severity level for errors, warnings, and notifications.
Traits§
- Notifiable
- Trait for types that can be converted to user-facing notifications.