[PR #1140] [MERGED] Replace empty catch blocks with explicit exception handling in TarArchive validation methods #1576

Open
opened 2026-01-29 22:21:12 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/1140
Author: @Copilot
Created: 1/16/2026
Status: Merged
Merged: 1/16/2026
Merged by: @adamhathcock

Base: adam/async-creationHead: copilot/sub-pr-1132-another-one


📝 Commits (2)

  • 302cf2e Initial plan
  • 9fa686b Fix empty catch blocks in TarArchive.Factory.cs with explicit exception handling

📊 Changes

1 file changed (+12 additions, -4 deletions)

View changed files

📝 src/SharpCompress/Archives/Tar/TarArchive.Factory.cs (+12 -4)

📄 Description

Addresses code review feedback about empty catch blocks in TarArchive.Factory.cs. The IsTarFile and IsTarFileAsync methods use catch-all exception handling to detect invalid tar files, but the empty catch blocks obscured intent.

Changes

  • Replace catch { } with explicit catch (Exception) in both validation methods
  • Add comments explaining that all exceptions during header parsing indicate an invalid tar file
catch (Exception)
{
    // Catch all exceptions during tar header reading to determine if this is a valid tar file
    // Invalid tar files or corrupted streams will throw various exceptions
    return false;
}

The behavior is unchanged—these methods probe streams and return false for any exception rather than propagating to callers.


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/1140 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 1/16/2026 **Status:** ✅ Merged **Merged:** 1/16/2026 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `adam/async-creation` ← **Head:** `copilot/sub-pr-1132-another-one` --- ### 📝 Commits (2) - [`302cf2e`](https://github.com/adamhathcock/sharpcompress/commit/302cf2e14f987fc6a1825465158e361d2418813b) Initial plan - [`9fa686b`](https://github.com/adamhathcock/sharpcompress/commit/9fa686b8f9cce2f9393349e3a3ae5d0eac8133ef) Fix empty catch blocks in TarArchive.Factory.cs with explicit exception handling ### 📊 Changes **1 file changed** (+12 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Archives/Tar/TarArchive.Factory.cs` (+12 -4) </details> ### 📄 Description Addresses code review feedback about empty catch blocks in `TarArchive.Factory.cs`. The `IsTarFile` and `IsTarFileAsync` methods use catch-all exception handling to detect invalid tar files, but the empty catch blocks obscured intent. ## Changes - Replace `catch { }` with explicit `catch (Exception)` in both validation methods - Add comments explaining that all exceptions during header parsing indicate an invalid tar file ```csharp catch (Exception) { // Catch all exceptions during tar header reading to determine if this is a valid tar file // Invalid tar files or corrupted streams will throw various exceptions return false; } ``` The behavior is unchanged—these methods probe streams and return `false` for any exception rather than propagating to callers. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/adamhathcock/sharpcompress/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:21:12 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1576