Skip to content

Track exception types in try/except blocks with name resolution #52

Description

@octo-youcef

User Outcome

A user can query which exceptions are caught where, trace error handling patterns, and identify unhandled exception types in the codebase.

Background

Currently we don't track exception handling. Knowing what exceptions are caught (and where) is valuable for:

  • Understanding error handling coverage
  • Finding bare except: clauses
  • Identifying exception hierarchies
  • Tracking custom exception usage

Proposal

Extract exception information from try/except blocks:

from myapp.exceptions import ValidationError

try:
    validate(data)
except ValidationError as e:
    log.error(e)
except (KeyError, ValueError):
    pass
except:  # bare except
    pass

Create relationships:

  • :Function -[:CATCHES]-> :ExceptionType
  • Track bare excepts as special case

Example Queries

// Functions that catch specific exception
MATCH (f:Function)-[:CATCHES]->(e {name: "ValidationError"})

// Functions with bare except (code smell)
MATCH (f:Function)-[:CATCHES]->(e {name: "*"})

// Most commonly caught exceptions
MATCH (f:Function)-[:CATCHES]->(e)
RETURN e.name, count(f) as catch_count
ORDER BY catch_count DESC

Benefits

  • Identify missing error handling
  • Find overly broad exception catches
  • Track custom exception usage
  • Code quality rule: "no bare excepts"
  • Understand error flow through system

Implementation

  1. Extend AST extractor to walk try/except nodes
  2. Extract exception types from except handlers
  3. Use name resolution to map exception names to FQNs
  4. Create ExceptionType nodes (or reference existing classes)
  5. Create CATCHES relationships
  6. Update schema documentation

Related

Acceptance Criteria

  • Exception types extracted from try/except
  • CATCHES relationships created
  • Name resolution maps exception names correctly
  • Bare except tracked appropriately
  • Query examples work
  • Schema documentation updated

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions