Skip to content

feat(typescript): implement exception classname metadata extraction #10

Description

@pleberre

Problem

The TypeScript parser does not extract exception classname metadata, resulting in incomplete error tracking data.

File Location

src/main/java/io/err0/client/languages/TypescriptSourceCodeParse.java:329

// TODO: extract exception classname meta data

Context

TypeScript has try-catch blocks similar to JavaScript but with type information:

// Standard Error
throw new Error("message");

// Custom error classes
class MyCustomError extends Error {
    constructor(message: string) {
        super(message);
    }
}

throw new MyCustomError("custom error");

// Try-catch
try {
    doSomething();
} catch (error: MyCustomError) {
    // Handle specific error type
}

Expected Behavior

Extract and store:

  • Error class names from throw statements
  • Error types from catch clauses
  • Custom error class definitions
  • Standard Error subclasses

Implementation Guidance

  1. Identify TypeScript error patterns:

    • throw new ErrorType() statements
    • catch (error: ErrorType) clauses
    • Error class definitions extending Error
    • Type annotations on error objects
  2. Extract error type information:

    • For throw new X(): extract "X"
    • For catch (e: X): extract "X"
    • For class definitions: extract class name if extends Error
  3. Store in token metadata

  4. Handle TypeScript-specific syntax:

    • Type annotations
    • Generic error types
    • Union types in catch clauses

Test Cases Needed

Add to src/test/testdata/ for TypeScript:

  • Throw with Error class
  • Throw with custom error
  • Catch with type annotation
  • Custom error class definition

Reference Files

  • src/main/java/io/err0/client/languages/JavascriptSourceCodeParse.java (base implementation)
  • src/main/java/io/err0/client/languages/JavaSourceCodeParse.java (exception handling pattern)

Acceptance Criteria

  • Exception class names extracted from TypeScript error patterns
  • Type annotations properly parsed for error types
  • TODO removed from TypescriptSourceCodeParse.java:329
  • Tests pass for TypeScript error handling
  • No regressions in existing TypeScript parsing

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions