AdguardTeam/AdGuardHome · error
parsing option code: %w
Error message
parsing option code: %w
What it means
Returned by parseDHCPOption when the first token of a 'code:type[:value]' option string fails to parse as an 8-bit unsigned decimal integer. DHCPv4 option codes must be 0–255; values like 256, 0x42, 'code', or an empty token trigger this.
Source
Thrown at internal/dhcpd/options_unix.go:184
func parseDHCPOption(s string) (code dhcpv4.OptionCode, val dhcpv4.OptionValue, err error) {
defer func() { err = errors.Annotate(err, "invalid option string %q: %w", s) }()
s = strings.TrimSpace(s)
parts := strings.SplitN(s, " ", 3)
var valStr string
if pl := len(parts); pl < 3 {
if pl < 2 || parts[1] != typDel {
return nil, nil, errors.Error("bad option format")
}
} else {
valStr = parts[2]
}
var code64 uint64
code64, err = strconv.ParseUint(parts[0], 10, 8)
if err != nil {
return nil, nil, fmt.Errorf("parsing option code: %w", err)
}
val, err = parseDHCPOptionVal(parts[1], valStr)
if err != nil {
// Don't wrap an error since it's informative enough as is and there
// also the deferred annotation.
return nil, nil, err
}
return dhcpv4.GenericOptionCode(code64), val, nil
}
// prepareOptions builds the set of DHCP options according to host requirements
// document and values from conf.
func (s *v4Server) prepareOptions() {
// Set default values of host configuration parameters listed in Appendix A
// of RFC-2131.
s.implicitOpts = dhcpv4.OptionsFromList(View on GitHub (pinned to b41aefbe51)
Solutions
- Use a decimal option code in 0–255 (convert hex from vendor docs, e.g. 0x2A → 42)
- Ensure the string is 'code:type' or 'code:type:value' with no leading/trailing spaces
- Look up the IANA DHCPv4 option registry to confirm the numeric code
Example fix
// before "0x42:hex:68656c6c6f" // -> parsing option code: strconv.ParseUint: parsing "0x42": invalid syntax // after "66:hex:68656c6c6f"
Defensive patterns
Strategy: validation
Validate before calling
func optionCodeOK(s string) bool {
v, err := strconv.ParseUint(strings.TrimSpace(s), 10, 8)
return err == nil && v <= 255
} Prevention
- Decimal codes 0–255 only
- Convert vendor hex codes (0x42 → 66) before entry
- Format strings as 'code:type:value' with no stray spaces
When it happens
Trigger: Submitting an option string like '300:ip:1.2.3.4', '0x42:hex:ab', or a malformed split where the code token is empty or non-numeric.
Common situations: Vendor option tables listing codes above 255 or in hex; typos; extra spaces producing an empty first token when splitting on ':'.
Related errors
AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27).
Data as JSON: /api/errors/01b3fe8a469f6480.
Report an issue: GitHub.