{"record":{"id":"2eb4a4abd9653ae7","repo":"AdguardTeam/AdGuardHome","slug":"couldn-t-parse-mac-address-w","errorCode":null,"errorMessage":"couldn't parse MAC address: %w","messagePattern":"couldn't parse MAC address: %w","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"internal/dhcpd/http_unix.go","lineNumber":103,"sourceCode":"func leasesToStatic(leases []*dhcpsvc.Lease) (static []*leaseStatic) {\n\tstatic = make([]*leaseStatic, len(leases))\n\n\tfor i, l := range leases {\n\t\tstatic[i] = &leaseStatic{\n\t\t\tHWAddr:   l.HWAddr.String(),\n\t\t\tIP:       l.IP,\n\t\t\tHostname: l.Hostname,\n\t\t}\n\t}\n\n\treturn static\n}\n\n// toLease converts leaseStatic to Lease or returns error.\nfunc (l *leaseStatic) toLease() (lease *dhcpsvc.Lease, err error) {\n\taddr, err := net.ParseMAC(l.HWAddr)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"couldn't parse MAC address: %w\", err)\n\t}\n\n\treturn &dhcpsvc.Lease{\n\t\tHWAddr:   addr,\n\t\tIP:       l.IP,\n\t\tHostname: l.Hostname,\n\t\tIsStatic: true,\n\t}, nil\n}\n\n// leaseDynamic is the JSON form of dynamic DHCP lease.\ntype leaseDynamic struct {\n\tHWAddr   string     `json:\"mac\"`\n\tIP       netip.Addr `json:\"ip\"`\n\tHostname string     `json:\"hostname\"`\n\tExpiry   string     `json:\"expires\"`\n}\n","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/dhcpd/http_unix.go#L85-L121","documentation":"Converting a static-lease API payload (leaseStatic) to a Lease failed because HWAddr is not a parseable MAC address per net.ParseMAC. Raised in the HTTP layer when adding/updating a static lease.","triggerScenarios":"POSTing to the DHCP static-lease API (or UI form) with HWAddr empty, containing separators in the wrong places, invalid hex, or an IP address mistakenly supplied as the MAC.","commonSituations":"Typos in the UI form; pasting an IP into the MAC field; using unusual separator styles; sending already-normalized bytes instead of a string.","solutions":["Supply the MAC in a standard format like aa:bb:cc:dd:ee:ff","Double-check the field you are filling (HWAddr vs IP)","Trim whitespace/newlines from pasted values"],"exampleFix":"// before\n{\"hwaddr\": \"192.168.1.50\"}\n// after\n{\"hwaddr\": \"aa:bb:cc:dd:ee:ff\"}","handlingStrategy":"type-guard","validationCode":"if _, err := net.ParseMAC(req.HWAddr); err != nil { http.Error(w, \"invalid MAC\", 400); return }","typeGuard":"func isValidMAC(s string) bool { _, err := net.ParseMAC(s); return err == nil }","tryCatchPattern":"if _, err := net.ParseMAC(input); err != nil { /* 400 Bad Request, echo field name */ }","preventionTips":["Normalize/validate MAC client-side in forms","Use placeholder format hints (aa:bb:cc:dd:ee:ff)"],"tags":["dhcp","static-lease","mac-address","api"],"backgroundTag":"invalid-mac-address","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}