Skip to content

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

@siavashta

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions