affaan-m/ECC · error · NotFoundError

User not found

Error message

User not found: {user_id}

What it means

Illustrative custom-exception example from the python-patterns skill: get_user's db lookup returned nothing for user_id, so a domain NotFoundError is raised instead of a generic exception. The unknown user_id is the invalid input, and the typed error lets callers handle missing resources distinctly.

Solutions

  1. Catch NotFoundError at the API layer and map it to 404
  2. Distinguish 'not found' from 'deleted'/'permission denied' with separate exception subclasses
  3. Log lookups that miss to detect probing or stale ids
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at skills/python-patterns/SKILL.md:194 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of affaan-m/ECC@d8409a4b08 (2026-08-26). Data as JSON: /api/errors/7ec3f3c290ec341e. Report an issue: GitHub.

Appendix: source

Thrown at skills/python-patterns/SKILL.md:194

```python
class AppError(Exception):
    """Base exception for all application errors."""
    pass

class ValidationError(AppError):
    """Raised when input validation fails."""
    pass

class NotFoundError(AppError):
    """Raised when a requested resource is not found."""
    pass

# Usage
def get_user(user_id: str) -> User:
    user = db.find_user(user_id)
    if not user:
        raise NotFoundError(f"User not found: {user_id}")
    return user
```

## Context Managers

### Resource Management

```python
# Good: Using context managers
def process_file(path: str) -> str:
    with open(path, 'r') as f:
        return f.read()

# Bad: Manual resource management
def process_file(path: str) -> str:
    f = open(path, 'r')
    try:
        return f.read()

View on GitHub (pinned to d8409a4b08)