Skip to content

Add validation and warnings when auto-detection doesn't find all expected lists #7

@skempken

Description

@skempken

Problem

The detect_list_names() function currently doesn't validate whether all expected lists were found:

# things_jxa.py:74-77
detected_mapping = {}
for i, english_key in enumerate(english_keys):
    if i < len(list_names):
        detected_mapping[english_key] = list_names[i]

Issues:

  • If Things 3 returns fewer than 6 lists, some mappings are silently missing
  • No warning to the user that detection was incomplete
  • Subsequent commands may fail with confusing errors
  • No way to diagnose which lists were missing

Current Implementation

Location: things_jxa.py:74-77

The function:

  • Expects 6 lists: inbox, today, upcoming, anytime, someday, logbook
  • If fewer lists exist, simply doesn't create those mappings
  • Returns incomplete mapping without notification

Proposed Solution

Add validation and clear warnings:

def detect_list_names() -> Dict[str, str]:
    try:
        output = run_jxa(script)
        list_names = json.loads(output)

        # Expected built-in lists
        english_keys = ["inbox", "today", "upcoming", "anytime", "someday", "logbook"]
        
        detected_mapping = {}
        for i, english_key in enumerate(english_keys):
            if i < len(list_names):
                detected_mapping[english_key] = list_names[i]
        
        # Validate completeness
        missing_lists = [key for key in english_keys if key not in detected_mapping]
        if missing_lists:
            console.print(
                f"[yellow]Warning: Could not detect all lists. "
                f"Missing: {', '.join(missing_lists)}[/yellow]"
            )
            console.print(
                f"[yellow]Found {len(list_names)} lists, expected {len(english_keys)}[/yellow]"
            )
        
        # Handle Tomorrow detection...
        
        return detected_mapping
        
    except (RuntimeError, json.JSONDecodeError) as e:
        # ... error handling ...

Enhanced version with diagnostics

def validate_detected_lists(
    detected: Dict[str, str], 
    expected: List[str]
) -> List[str]:
    """
    Validate detected list mappings and return list of missing keys.
    
    Args:
        detected: Dictionary of detected list mappings
        expected: List of expected list keys
        
    Returns:
        List of missing list keys (empty if all found)
    """
    missing = [key for key in expected if key not in detected]
    
    if missing:
        console.print(
            f"[yellow]Locale detection incomplete:[/yellow]"
        )
        console.print(f"  Expected lists: {', '.join(expected)}")
        console.print(f"  Found lists: {', '.join(detected.keys())}")
        console.print(f"  Missing lists: {', '.join(missing)}")
        console.print(
            f"\n[dim]Tip: Try using '--locale de' or '--locale en' "
            f"to bypass auto-detection[/dim]"
        )
    
    return missing

# In detect_list_names():
missing = validate_detected_lists(detected_mapping, english_keys)

Impact

Priority: Medium - improves user experience and debuggability

Affected code: things_jxa.py:74-77

Breaking changes: None

Benefits:

  • Clear feedback when detection is incomplete
  • Easier troubleshooting for users
  • Helpful suggestions for workarounds
  • Better diagnostics for bug reports

Acceptance Criteria

  • Validation checks for all expected lists
  • Clear warning message if any lists are missing
  • Warning includes which lists were not found
  • Warning suggests using --locale as workaround
  • Validation can be reused/tested independently
  • Doesn't affect successful detection cases

Additional Context

This issue was identified during post-implementation review of #1 (multi-locale support).

Example scenarios where this helps:

  • User has customized Things 3 and hidden some lists
  • JXA returns unexpected data structure
  • Things 3 is running in limited/demo mode

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesterror-handlingImprovements to error handling and validationuxUser experience improvements

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions