Module: lash-core (error types and formatting)
Dependencies: tasks.project-setup.md
Effort: 4-6 days
Priority: CRITICAL
Implement comprehensive, user-friendly error handling throughout Lash. Errors must be expressive for humans, structured for machines, and actionable for both users and agents.
From design-doc.md section 12:
- Expressive error messages (section 12.1)
- Structured, machine-readable error data (section 12.1)
- Stable error codes (section 12.1)
- Standardized exit codes (section 12.3)
Priority: CRITICAL Effort: 1-2 days Depends on: tasks.project-setup.md
Define the complete taxonomy of error types that can occur in Lash, with stable codes and hierarchical organization.
- Define
LashErrorenum- Top-level error categories:
-
Parse- Markdown parsing errors -
Lint- Linting/validation errors -
Index- Indexing/database errors -
Dependency- Dependency resolution errors -
Query- Query/search errors -
Config- Configuration errors -
IO- File system errors -
Internal- Internal/unexpected errors
-
- Each variant contains specific error details
- Top-level error categories:
- Define error codes
- Stable string codes (e.g.,
E_PARSE_INVALID_CHECKBOX,E_LINT_DUPLICATE_ID) - Hierarchical naming:
E_<CATEGORY>_<DESCRIPTION> - Document all codes in error catalog
- Stable string codes (e.g.,
- Implement error variants
- Parse errors:
- Invalid checkbox syntax
- Malformed annotation
- Invalid header format
- Unexpected depth
- Lint errors:
- Duplicate ID
- Unknown annotation
- Depth limit exceeded
- Status inconsistency (parent done, children open)
- Invalid label format
- Dependency errors:
- Broken reference (target not found)
- Circular dependency
- Invalid reference format
- Index errors:
- Database corruption
- Schema version mismatch
- Index out of sync
- IO errors:
- File not found
- Permission denied
- Invalid path
- Parse errors:
- Add error context
- File path
- Line and column numbers
- Relevant snippet (for parse/lint errors)
- Dependency chain (for dependency errors)
- Implement
std::error::Errortrait- Human-readable
Displayimplementation - Proper error implementation via thiserror
-
Debugimplementation with full context
- Human-readable
- Complete taxonomy covers all error scenarios
- Error codes are stable and well-documented
- Each error variant contains relevant context
- Errors implement standard traits
- Unit: Construct each error type
- Unit: Test error Display output
- Unit: Test error code stability
- Documentation: Error catalog is complete
Priority: CRITICAL Effort: 2-3 days Depends on: Task 1, tasks.cli-framework.md#3
Implement rich error formatting for both human and machine consumption.
- Implement
ErrorFormatterstruct-
format_human()- human-readable text -
format_json()- structured JSON - Support for colored output
-
- Implement human-readable formatting
- Use colored crate for color support
- Show:
- Error message (clear, concise)
- File path, line, column
- Code snippet with context lines
- Caret (^) pointing to error location
- Help text / suggestion
- Color coding:
- Red: error message
- Cyan: file path
- Yellow: warning text
- Gray: code snippet
- Implements rich formatting similar to rustc errors
- Implement JSON formatting
- Schema includes:
- code, severity, message, location, snippet, help, labels
- Include all context fields
- Stable schema via Diagnostic struct
- Schema includes:
- Implement error suggestions
- Contextual help for each error type
- Helper constructors include helpful messages
- All errors have actionable help text
- Add severity levels
- Error (must fix)
- Warning (should fix)
- Info (nice to fix)
- Hint (style suggestion)
- Human-readable errors are clear and actionable
- JSON errors are parseable and complete
- Color coding improves readability
- Suggestions help users fix errors quickly
- Unit: Test human formatting for each error type
- Unit: Test JSON formatting
- Unit: Validate JSON schema
- Snapshot: Capture formatted output for regression testing
- Manual: Visual inspection of formatted errors
Priority: HIGH Effort: 1-2 days Depends on: Task 1, Task 2
Implement error collection and aggregation for batch operations (linting, indexing).
- Define
ErrorReportstruct- List of errors
- Grouping (by file, by type, by severity, or none)
- Summary statistics
- Implement error collection
- Collect all errors (don't stop on first)
- Associate with source file/operation
- Maintain order (by file, then line)
- Implement error grouping
- Group by file (show all errors per file together)
- Group by error code (show all duplicates together)
- Group by severity
- Configurable grouping strategy via GroupBy enum
- Implement summary reporting
- Count errors by severity
- Count errors by type (error code)
- Show affected files count
- Summary includes error counts and breakdown
- Implement report rendering
- Text format: grouped errors with headers
- JSON format: array of error objects + summary
- Compact format for logs
- Add filtering
- Filter by severity
- Filter by file
- Filter by error code
- Error reports are comprehensive and organized
- Grouping makes large error sets manageable
- Summary provides quick overview
- Filtering works correctly
- Unit: Test error collection
- Unit: Test grouping strategies
- Integration: Generate report from fixture errors
- Integration: Test filtering
Priority: HIGH Effort: 1 day Depends on: Task 1, Task 2
Ensure error messages are optimized for AI agent consumption and error recovery.
- Add structured error context for agents
- Exact error location (file, line, col)
- Error code (for matching against documentation)
- Actionable fix suggestion (specific steps)
- Related context (affected dependencies, etc.)
- Implement error recovery hints
- "Run
lash formatto fix formatting" - "Remove duplicate ID or rename to unique value"
- "Update reference to:
correct/path.md#task:id"
- "Run
- Add error documentation links
- URL to error code documentation (if available)
- Inline explanation in JSON output
- Implement
--explainflag (optional)-
lash explain E_LINT_DUPLICATE_ID - Show detailed explanation of error code
- Show examples and fixes
-
- Ensure JSON errors are complete
- All fields populated
- No ambiguous or vague messages
- Include context needed for automated fixes
- Agents can parse and understand errors
- Recovery hints are actionable
- JSON output is complete and unambiguous
- Error explanations are helpful
- Integration: Generate errors, validate JSON completeness
- Integration: Test recovery hints
- Manual: Use errors with agent, assess usability
Priority: MEDIUM Effort: 1 day Depends on: Task 2, Task 3, tasks.cli-framework.md#7
Integrate error formatting and reporting into all CLI commands.
- Implement top-level error handler
- Catch
LashErrorfrom commands - Format based on output mode (text/JSON)
- Display to user
- Set exit code
- Catch
- Add error reporting to each command
-
lint: collect all errors, show report -
format: report formatting failures -
index: report parse and DB errors -
list: report query errors -
show: report not found errors -
search: report search errors -
graph: report dependency errors -
check-links: report broken links
-
- Implement progress-aware error display
- Show errors as they occur (streaming)
- Or collect and show at end (batch)
- Configurable via flag
- Add error verbosity control
- Quiet: only error count
- Normal: error messages (default)
- Verbose: error messages + context
- Debug: full error details + backtrace
- All commands report errors consistently
- Error formatting respects output mode
- Verbosity control works across commands
- Exit codes are set correctly
- Integration: Test error reporting for each command
- Integration: Test with different verbosity levels
- Integration: Verify exit codes
Priority: LOW Effort: 1 day Depends on: Task 1-4
Implement utilities for error recovery and validation to help users fix errors quickly.
- Implement
ErrorValidator- Validate that a file has no errors after fix
- Re-run lint after auto-fix
- Report remaining errors
- Implement auto-fix suggestions
- Detect fixable errors (whitespace, formatting)
- Generate fix suggestions
- Apply fixes with user confirmation
- Add error recovery workflow
-
lash lint --fix: apply auto-fixes -
lash lint --suggest: show fix suggestions - Iterate until no fixable errors remain
-
- Implement error diff
- Show before/after for fixes
- Highlight what changed
- Confirm before applying
- Auto-fix successfully resolves common errors
- Suggestions are helpful for manual fixes
- Recovery workflow is smooth
- Users can quickly fix errors
- Integration: Test auto-fix on various error types
- Integration: Test suggestion generation
- Integration: Verify fixes resolve errors
- Error telemetry or crash reporting to external service
- Interactive error fixing wizard
- Error translations (English only for v1)
- Custom error messages per user
- Error display: Stream errors as found or batch at end?
- Severity: Fail on warnings or only on errors?
- JSON schema: Version and document formally?
- Help URLs: Include links to docs or keep messages self-contained?
- Design doc section 12 (Error Handling & UX)
miettecrate: https://docs.rs/miette/ (for rich diagnostics)thiserrorcrate: https://docs.rs/thiserror/ (for error derive macros)- Error handling patterns: https://doc.rust-lang.org/book/ch09-00-error-handling.html