Skip to content

WritePacket does not properly wrap errors, breaking errors.Is detection (should use %w not %v) #1213

Description

@siavashta

In writer.go, the WritePacket function uses %v when returning wrapped errors. This prevents errors.Is and errors.As from working correctly on underlying system errors (e.g. syscall.ENOSPC when the disk is full).

From writer.go
if err := w.writePacketHeader(ci); err != nil { return fmt.Errorf("error writing packet header: %v", err) }

This formats the error as a string but does not wrap it. As a result, error checks like this fail:
if errors.Is(err, syscall.ENOSPC) { // never triggered }

Even though the underlying error is ENOSPC, it gets lost because %v does not preserve the error.

Why This Matters
Applications relying on gopacket cannot reliably detect and handle system-level write failures (like disk full, permissions, etc.), because the root error is lost. This makes robust error handling (like throttled logging or retries) impossible.

Proposed Fix
Change all %v error wrapping in return paths to %w where propagation is intended, e.g.:

- return fmt.Errorf("error writing packet header: %v", err)
+ return fmt.Errorf("error writing packet header: %w", err)

Activity

  1. added a commit that references this issue on Apr 13, 2026
    fb17b33
  2. added a commit that references this issue on Apr 14, 2026
    caf8993
  3. alliasgher commented on Apr 14, 2026

    @alliasgher

    Opened #1226 for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions