Skip to content

Handle empty files#109

Merged
MusicalNinjaDad merged 12 commits into
mainfrom
EOF
Nov 18, 2025
Merged

Handle empty files#109
MusicalNinjaDad merged 12 commits into
mainfrom
EOF

Conversation

@MusicalNinjaDad

@MusicalNinjaDad MusicalNinjaDad commented Nov 18, 2025

Copy link
Copy Markdown
Owner

workaround for golang/go#76338

Summary by Sourcery

Handle empty files as invalid ELF artifacts by mapping io.EOF to a FormatError and expanding tests and CLI behavior accordingly.

Bug Fixes:

Enhancements:

  • Introduce a P_empty test path and TestData entry with expected stderr for empty ELF files
  • Update elf.New to detect empty-file EOF and wrap it as an invalid ELF FormatError

Tests:

  • Add an 'empty file' case to elf_errors_test.go with conditional assertions for error type and content
  • Extend CLI and integration tests to include empty-file scenarios and adjust expected stderr stripping logic
  • Enhance internal test iterator to support ExpectedStderr for new error paths

Chores:

  • Bump snaggle version to 1.1.2

@sourcery-ai

sourcery-ai Bot commented Nov 18, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR enhances the ELF loader to properly handle empty files by translating bare io.EOF errors into FormatError and extends the test suite and utilities to include and validate an empty-file scenario, along with a version bump.

Sequence diagram for ELF loader handling empty files

sequenceDiagram
    participant "ELF Loader"
    participant "debug_elf.Open()"
    participant "Error Handler"
    "ELF Loader"->>"debug_elf.Open()": Open file
    "debug_elf.Open()"-->>"ELF Loader": io.EOF (if file is empty)
    "ELF Loader"->>"Error Handler": Check error type
    "Error Handler"-->>"ELF Loader": If io.EOF, wrap as FormatError
    "ELF Loader"-->>"Caller": Return FormatError for empty file
Loading

Entity relationship diagram for new empty file test data

erDiagram
    TESTDATA_PATH ||--o| TESTDATA : has
    TESTDATA {
        string Name
        string Path
        bool NonElf
        Elf Elf
        string StdErr
    }
    ELF {
        string Name
        string Path
        EI_CLASS Class
        Type Type
        string Interpreter
        string[] Dependencies
    }
    TESTDATA_PATH {
        string Path
    }
    TESTDATA o|--|{ ELF : contains
Loading

Class diagram for updated TestDetails and TestCase structs

classDiagram
    class TestDetails {
        bool Lib
        bool HasInterpreter
        elf.Elf Elf
        string StdErr
    }
    class TestCase {
        string Src
        string Dest
        string[] ExpectedStdout
        string[] ExpectedStderr
        map[string]string ExpectedFiles
        snaggle.Option[] Options
        string[] Flags
    }
Loading

File-Level Changes

Change Details Files
Detect and wrap empty-file errors in elf.New
  • Check for io.EOF after debug_elf.Open
  • Wrap io.EOF into debug_elf.FormatError to trigger ErrInvalidElf path
elf/elf.go
Introduce empty-file fixture and test data
  • Add P_empty path constant
  • Define TestData entry for P_empty with expected StdErr
internal/testpaths.go
internal/testing/testdata.go
Add empty-file cases and refine error assertions in tests
  • Include empty file in elf_errors_test, cli_test, and snaggle_test
  • Guard ErrorIs and ErrorAs assertions before checking message contents
  • Unify expected stderr handling via TestDetails.StdErr
elf/elf_errors_test.go
cmd/snaggle/cli_test.go
snaggle_test.go
Extend test iterator to support stderr expectations
  • Add ExpectedStderr field to TestCase
  • Populate ExpectedStderr from TestDetails.StdErr
internal/testing/testiterator.go
Bump CLI version to 1.1.2
  • Update Version constant
version.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • In TestData for P_empty, the Elf struct’s Name field is misspelled as “empyty”—updating it to “empty” will avoid confusion.
  • The nested asserts in TestInvalidElf can be simplified using require (or failing early) so that you don’t skip downstream checks when the primary error assertion fails.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In TestData for P_empty, the Elf struct’s `Name` field is misspelled as “empyty”—updating it to “empty” will avoid confusion.
- The nested asserts in TestInvalidElf can be simplified using require (or failing early) so that you don’t skip downstream checks when the primary error assertion fails.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov

codecov Bot commented Nov 18, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.59%. Comparing base (d6da66d) to head (b3aba28).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #109      +/-   ##
==========================================
+ Coverage   76.47%   76.59%   +0.12%     
==========================================
  Files          13       13              
  Lines         748      752       +4     
==========================================
+ Hits          572      576       +4     
  Misses        119      119              
  Partials       57       57              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MusicalNinjaDad MusicalNinjaDad enabled auto-merge (squash) November 18, 2025 08:18
@MusicalNinjaDad MusicalNinjaDad merged commit 2723337 into main Nov 18, 2025
16 checks passed
@MusicalNinjaDad MusicalNinjaDad deleted the EOF branch November 18, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant