Skip to content

PSAvoidUsingEmptyCatchBlock: Empty catch blocks silently swallow exceptions #6

@eigenverft

Description

@eigenverft

Issue

Multiple files contain empty catch blocks that silently swallow exceptions. This violates PowerShell error handling best practices and can make debugging extremely difficult.

Affected Files

Eigenverft.Manifested.Agent.InvokeCodexTask.ps1

Lines 633-635:

catch {
    # Ignore non-JSON lines.
}

Eigenverft.Manifested.Agent.InvokeGeminiTask.ps1

Lines 653-655:

catch {
    # Ignore invalid JSON payloads.
}

Eigenverft.Manifested.Agent.ps1

Lines 11-13:

catch {
    # Best effort only. Older hosts may already be configured appropriately.
}

Problems

  1. Silent failures - Errors are completely hidden from users and developers
  2. Debugging difficulty - No way to know when JSON parsing fails
  3. Best practice violation - PSScriptAnalyzer rule PSAvoidUsingEmptyCatchBlock
  4. Troubleshooting - Makes it hard to diagnose issues in production

Recommended Fix

Even if errors are expected and should be ignored, they should be logged:

# Option 1: Log to verbose stream
catch {
    Write-Verbose -Message "Failed to parse JSON: $_"
}

# Option 2: Use Write-Debug
catch {
    Write-Debug -Message "JSON parse skipped: $_"
}

# Option 3: Continue with explicit comment
catch {
    # Ignore non-JSON lines - this is expected behavior
    Write-Verbose -Message "Non-JSON line encountered: $($_.Exception.Message)"
}

PSScriptAnalyzer Rule

PSAvoidUsingEmptyCatchBlock

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions