Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 15, 2025

This PR refactors the CLI error handling to use the miette library for rich, user-friendly error reporting. The changes provide better error messages with diagnostic codes, helpful suggestions, and improved formatting.

Changes Made

Dependencies

  • Added miette dependency with fancy feature for enhanced error formatting

Error Type Improvements

  • Enhanced ConfigError with miette diagnostic attributes and helpful suggestions
  • Enhanced FormatError with diagnostic codes and context-aware help messages
  • Added diagnostic codes for better error categorization (e.g., roughly::config::invalid, roughly::format::syntax)

CLI Error Reporting

  • Added report_diagnostic_error() function for consistent miette error display
  • Updated configuration error handling to use miette reporting
  • Updated format error handling to use miette reporting
  • Maintained backward compatibility with existing error types

Testing

  • Added comprehensive tests to verify miette integration
  • All existing tests continue to pass
  • New tests validate error formatting and diagnostic capabilities

Before vs After

Before:

error: invalid config file
failed to read config

After:

roughly::config::invalid

  × Invalid config file format
  ╰─▶ TOML parse error at line 4, column 17
        |
      4 | [invalid_section
        |                 ^
      invalid table header
      expected `.`, `]`
      
  help: Check the TOML syntax in your roughly.toml file

Key Benefits

  • Rich Error Context: Errors now include source code context and precise location information
  • Helpful Suggestions: Each error type provides actionable help messages
  • Diagnostic Codes: Structured error codes for better tooling integration
  • Improved UX: Better visual formatting with colors and clear hierarchy
  • Backward Compatibility: All existing functionality preserved

The implementation focuses on configuration and format errors as these are the most common user-facing errors, while maintaining the existing error handling patterns for other parts of the codebase.

Fixes #44.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Use miette library Implement miette library for enhanced CLI error reporting Jul 15, 2025
Copilot finished work on behalf of felix-andreas-copilot July 15, 2025 23:47
@felix-andreas-copilot
Copy link
Collaborator

@copilot please use miette in cli::check instead of custom formatting logic

Copy link
Contributor Author

Copilot AI commented Jul 16, 2025

@copilot please use miette in cli::check instead of custom formatting logic

I've successfully replaced the custom formatting logic in cli::check with miette-based error reporting. The changes include:

  • Added a new CheckDiagnostic enum with miette attributes for rich error display
  • Created a helper function to convert LSP diagnostics to miette format
  • Replaced ~70 lines of custom formatting code with miette's built-in capabilities
  • Added comprehensive tests to validate the new functionality

The check command now provides much better error display with proper source code context, highlighting, and consistent formatting. All tests are passing.

Commit: c9e9f9c

Copilot finished work on behalf of felix-andreas-copilot July 16, 2025 00:05
@felix-andreas felix-andreas force-pushed the main branch 2 times, most recently from b04cd93 to adeb2a3 Compare July 18, 2025 22:53
@felix-andreas felix-andreas force-pushed the main branch 3 times, most recently from 4b7acf8 to f74a5a2 Compare September 19, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use miette library

2 participants