find-exception-issues

Detect exception-handling issues in PHP code, including swallowed exceptions, overly broad catches, missing exception handling, rethrows without added context, and exceptions thrown from finally blocks.

Last repository push
GitHub Stars
109
Forks
26
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "find-exception-issues" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-7748e2199428ac4a2170b67c980c75ca16ffacd7085bac3921302db2c85233b4. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Detect exception-handling issues in PHP code, including swallowed exceptions, overly broad catches, missing exception handling, rethrows without added context, and exceptions thrown from finally blocks.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Detects exception handling issues in PHP code. Finds swallowed exceptions, generic catches, missing exception handling, re-throwing without context, exception in finally.
Inputs and outputs
```markdown
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: find-exception-issues
description: Detects exception handling issues in PHP code. Finds swallowed exceptions, generic catches, missing exception handling, re-throwing without context, exception in finally.

Exception Issue Detection

Analyze PHP code for exception handling problems.

Detection Patterns

1. Swallowed Exceptions (Empty Catch)

// BUG: Exception completely ignored
try {
    $this->riskyOperation();
} catch (Exception $e) {
    // Empty catch block - bug hidden
}

// BUG: Only logging, no handling
try {
    $this->process();
} catch (Exception $e) {
    $this->logger->error($e->getMessage());
    // No re-throw, no return, execution continues
}

2. Generic Exception Catching

// BUG: Catches everything
try {
    $this->save();
} catch (Exception $e) {
    // Catches TypeError, LogicException, etc.
}

// BUG: Using Throwable carelessly
try {
    $this->process();
} catch (Throwable $t) {
    // Catches Error too, hiding fatal issues
}

3. Missing Exception Handling

// BUG: Unchecked external call
$response = $httpClient->request('GET', $url); // May throw

// BUG: File operations without try
$content = file_get_contents($path); // Returns false on failure

// BUG: JSON without error check
$data = json_decode($json); // May return null on error

4. Re-throwing Without Context

// BUG: Lost context
try {
    $this->process();
} catch (DatabaseException $e) {
    throw new RuntimeException('Failed'); // Lost original exception
}

// FIXED: Preserve chain
throw new RuntimeException('Failed to process', 0, $e);

5. Exception in Finally Block

// BUG: Exception in finally hides original
try {
    $this->process();
} finally {
    $this->cleanup(); // If this throws, original exception is lost
}

// FIXED:
} finally {
    try {
        $this->cleanup();
    } catch (Exception $e) {
        $this->logger->warning('Cleanup failed', ['exception' => $e]);
    }
}

6. Catch Order Issues

// BUG: Parent before child
try {
    $this->process();
} catch (Exception $e) {
    // Catches everything
} catch (InvalidArgumentException $e) {
    // Never reached
}

7. Return in Finally

// BUG: Return in finally overrides exception
try {
    throw new Exception('Error');
} finally {
    return true; // Exception is suppressed
}

8. Using Exception for Control Flow

// BUG: Exception as goto
try {
    foreach ($items as $item) {
        if ($found) {
            throw new FoundException($item);
        }
    }
} catch (FoundException $e) {
    $result = $e->getItem();
}

9. Missing @throws Documentation

// BUG: Undocumented exception
public function process(): void
{
    if (!$valid) {
        throw new InvalidArgumentException(); // Not documented
    }
}

Grep Patterns

# Empty catch blocks
Grep: "catch\s*\([^)]+\)\s*\{\s*\}" --glob "**/*.php"

# Generic Exception catch
Grep: "catch\s*\(\s*(Exception|\\\\Exception)\s+" --glob "**/*.php"

# Throwable catch
Grep: "catch\s*\(\s*(Throwable|\\\\Throwable)\s+" --glob "**/*.php"

# throw new without previous
Grep: "throw new \w+Exception\([^,)]+\);" --glob "**/*.php"

# Return in finally
Grep: "finally\s*\{[^}]*return" --glob "**/*.php"

Severity Classification

Pattern Severity
Swallowed exception 🔴 Critical
Return in finally 🔴 Critical
Generic Throwable catch 🟠 Major
Lost exception chain 🟠 Major
Exception for control flow 🟡 Minor
Missing @throws 🟡 Minor

Best Practices

Specific Exception Handling

try {
    $this->save();
} catch (UniqueConstraintException $e) {
    throw new DuplicateEmailException($email, 0, $e);
} catch (ConnectionException $e) {
    throw new DatabaseUnavailableException(0, $e);
}
// Let other exceptions bubble up

Proper Exception Chain

throw new DomainException(
    sprintf('Failed to process order %s', $orderId),
    previous: $originalException
);

Safe Finally

try {
    $this->process();
} finally {
    try {
        $this->cleanup();
    } catch (Throwable $e) {
        // Log but don't throw
        $this->logger->error('Cleanup failed', ['exception' => $e]);
    }
}

Output Format

### Exception Issue: [Description]

**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Type:** [Swallowed|Generic Catch|Missing Chain|...]

**Issue:**
[Description of the exception handling problem]

**Code:**
```php
// Problematic code

Fix:

// Proper exception handling

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value75/100

Highlights

  • 提供 PHP 代码异常处理的检测能力,解决开发者常见痛点
  • 覆盖多种异常处理问题类型,具备明确实用价值
Trigger Precision95/100

Highlights

  • 触发词精准完整,明确描述检测 PHP 异常处理问题的功能
  • 列举具体问题类型,边界清晰,便于用户理解适用场景
Structure and Standards95/100

Areas to improve

  • 缺少 When to Use 章节 Reported severity: Minor

    文档结构完整,但缺少明确的'When to Use'使用场景说明章节

    Recommendation: 建议添加'When to Use'章节,说明何时使用此 Skill 最为合适

  • 文档较长 Reported severity: Minor

    文档内容较为详尽,总行数较多,可能影响阅读体验

    Recommendation: 可考虑将部分内容折叠或拆分为多个子章节,提升可读性

Highlights

  • 文档结构清晰,包含检测模式、grep 命令、严重性分级等完整内容
  • 提供丰富的代码示例和最佳实践,便于理解与执行
Execution Reliability85/100

Highlights

  • 提供具体的 grep 命令模式,便于直接执行检测
  • 对不同问题类型进行严重性分级,提升执行指导价值
Evidence Verifiability (mean of the first four)88/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.