Skip to content

fix(ethernet): a non-string MAC address raises a bare TypeError, not ProtocolError #2222

Closed

Description

@JarryShaw

Describe the bug
Ethernet._make_mac_addr documents ProtocolError for a bad address, but a bool, int, None or float reaches PAT_MAC_ADDR.fullmatch and raises a bare TypeError, which except ProtocolError / except ValueError does not catch. #2166 closed the same gap in ARP._make_addr_resolve.

Reproduction

from pcapkit.protocols.link.ethernet import Ethernet
Ethernet(src=True)   # TypeError: expected string or bytes-like object, got 'bool'
Ethernet(dst=5)      # TypeError: expected string or bytes-like object, got 'int'
Ethernet(src=None)   # TypeError: expected string or bytes-like object, got 'NoneType'

Expected behavior
Follow ARP's Ethernet branch: a bool raises FieldValueError (checked first, since bool is an int), and anything not str, bytes or bytearray raises ProtocolError. Update the docstring's Raises: to match, and add a test per type.

System information
Linux, CPython 3.14.9, checkout main 91147a182.

Activity

  1. added
    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 26, 2026
  2. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 26, 2026
  3. added this to the PyPCAPKit v1.5 milestone on Oct 26, 2026
  4. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 26, 2026
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

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions