Add rich metadata access and better error handling#8
Merged
Conversation
Implements two agent-friendly features: 1. Rich Metadata Access (Issue #8) - Add --headers flag to show all email headers - Add --format raw to fetch RFC822 format from API - Add --tree flag to show thread hierarchical structure - New thread_tree.py module for building thread trees 2. Better Error Handling (Issue #10) - Add structured exception classes with error codes - Add centralized error handler with JSON/pretty output - Add input validators for message IDs, date ranges, FTS queries - Add --dry-run flag to sync command for preview Changes: - Modified: exceptions.py, cli.py, sync/engine.py, sync/client.py - Added: error_handler.py, validators.py, db/thread_tree.py - Tests: test_error_handling.py (11 tests), test_metadata.py (6 tests) All 47 tests passing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements two agent-friendly features for gmail-cli from Issue #6:
Note: Data extraction (Issue #9) is intentionally skipped - LLMs can extract structured data from the raw text we provide via JSON output.
Feature 1: Rich Metadata Access
Exposes full headers, RFC822 format, and thread tree structure.
New CLI Options
Implementation Details
--headersand--format rawoptions--treeflag for hierarchical viewdb/thread_tree.py- Builds thread trees using In-Reply-To headersGmailClient.get_message_raw()fetches RFC822 format from Gmail APIFeature 2: Better Error Handling
Structured error codes, query validation, dry-run mode, clear error messages.
New CLI Options
Implementation Details
New exception classes with error codes:
GmailCliException(base class)InvalidQueryError,RateLimitError,MessageNotFoundErrorSyncError,AuthenticationError,ValidationErrorCentralized error handler (
error_handler.py):Input validators (
validators.py):Dry-run support in sync command:
Files Changed
New Files (5)
src/gmail_cli/error_handler.py- Centralized error handlingsrc/gmail_cli/validators.py- Input validation functionssrc/gmail_cli/db/thread_tree.py- Thread tree buildertests/test_error_handling.py- 11 passing teststests/test_metadata.py- 6 passing testsModified Files (4)
src/gmail_cli/exceptions.py- Added 6 exception classessrc/gmail_cli/sync/engine.py- Dry-run supportsrc/gmail_cli/sync/client.py- RFC822 format fetchsrc/gmail_cli/cli.py- Enhanced read/thread commands, error handlingTesting
All tests passing ✓ (47/47)
pytest tests/ -v # ============================== 47 passed in 0.21s ==============================Related Issues
Closes #8
Closes #10
Part of #6