AdguardTeam/AdGuardHome · error

parsing: %w

Error message

parsing: %w

What it means

Returned by parseLease when the decoded JSON passes initial checks but l.toLease() fails to convert it into a dhcpsvc.Lease. Typical causes are an invalid MAC address or an IP/hostname that violates lease invariants (e.g. multicast/unspecified IP). The wrapped error names the offending field.

Source

Thrown at internal/dhcpd/http_unix.go:662

// parseLease parses a lease from r.  If there is no error returns DHCPServer
// and *Lease.  r must be non-nil.
func (s *server) parseLease(r io.Reader) (srv DHCPServer, lease *dhcpsvc.Lease, err error) {
	l := &leaseStatic{}
	err = json.NewDecoder(r).Decode(l)
	if err != nil {
		return nil, nil, fmt.Errorf("decoding json: %w", err)
	}

	if !l.IP.IsValid() {
		return nil, nil, errors.Error("invalid ip")
	}

	l.IP = l.IP.Unmap()

	lease, err = l.toLease()
	if err != nil {
		return nil, nil, fmt.Errorf("parsing: %w", err)
	}

	if lease.IP.Is4() {
		srv = s.srv4
	} else {
		srv = s.srv6
	}

	return srv, lease, nil
}

// handleDHCPAddStaticLease is the handler for the POST
// /control/dhcp/add_static_lease HTTP API.
func (s *server) handleDHCPAddStaticLease(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()
	l := s.conf.Logger

	srv, lease, err := s.parseLease(r.Body)

View on GitHub (pinned to b41aefbe51)

Solutions

  1. Use a canonical MAC format such as AA:BB:CC:DD:EE:FF (verify with a regex or a MAC parser before sending)
  2. Pick a concrete unicast IP inside your DHCP range, never 0.0.0.0, 255.255.255.255, or multicast
  3. Sanitize hostname to RFC-allowed characters (letters, digits, hyphen)
  4. Read the wrapped message — it states exactly which field (mac/ip/hostname) failed

Example fix

// before
{"ip":"192.168.1.10","mac":"AA:BB:CC:DD:EE:FF","hostname":"my printer"}
// -> 400 parsing: bad mac

// after
{"ip":"192.168.1.10","mac":"AA:BB:CC:DD:EE:FF","hostname":"my-printer"}
Defensive patterns

Strategy: validation

Validate before calling

var macRe = regexp.MustCompile(`^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$`)
func leaseOK(ip, mac, hostname string) bool {
	p := net.ParseIP(ip)
	return p != nil && p.IsGlobalUnicast() && macRe.MatchString(mac)
}

Try / catch

if err := addStaticLease(lease); err != nil {
    if strings.Contains(err.Error(), "parsing:") {
        // invalid mac/hostname/ip: check wrapped field name and correct it
    }
}

Prevention

When it happens

Trigger: Adding/updating a static lease where mac is not 6/8 bytes of valid hex pairs, the hostname contains invalid characters, or the IP (after IPv4/IPv6 unmapping) is not acceptable to the lease constructor (e.g. 0.0.0.0 or multicast).

Common situations: Typing a MAC with O instead of 0 or wrong separator style; reserving 0.0.0.0 or a broadcast/multicast address; hostnames with spaces or underscores rejected by validation.

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/af9aa90361b3ca4a. Report an issue: GitHub.