{"record":{"id":"01b3fe8a469f6480","repo":"AdguardTeam/AdGuardHome","slug":"parsing-option-code-w","errorCode":null,"errorMessage":"parsing option code: %w","messagePattern":"parsing option code: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dhcpd/options_unix.go","lineNumber":184,"sourceCode":"func parseDHCPOption(s string) (code dhcpv4.OptionCode, val dhcpv4.OptionValue, err error) {\n\tdefer func() { err = errors.Annotate(err, \"invalid option string %q: %w\", s) }()\n\n\ts = strings.TrimSpace(s)\n\tparts := strings.SplitN(s, \" \", 3)\n\n\tvar valStr string\n\tif pl := len(parts); pl < 3 {\n\t\tif pl < 2 || parts[1] != typDel {\n\t\t\treturn nil, nil, errors.Error(\"bad option format\")\n\t\t}\n\t} else {\n\t\tvalStr = parts[2]\n\t}\n\n\tvar code64 uint64\n\tcode64, err = strconv.ParseUint(parts[0], 10, 8)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"parsing option code: %w\", err)\n\t}\n\n\tval, err = parseDHCPOptionVal(parts[1], valStr)\n\tif err != nil {\n\t\t// Don't wrap an error since it's informative enough as is and there\n\t\t// also the deferred annotation.\n\t\treturn nil, nil, err\n\t}\n\n\treturn dhcpv4.GenericOptionCode(code64), val, nil\n}\n\n// prepareOptions builds the set of DHCP options according to host requirements\n// document and values from conf.\nfunc (s *v4Server) prepareOptions() {\n\t// Set default values of host configuration parameters listed in Appendix A\n\t// of RFC-2131.\n\ts.implicitOpts = dhcpv4.OptionsFromList(","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/dhcpd/options_unix.go#L166-L202","documentation":"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.","triggerScenarios":"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.","commonSituations":"Vendor option tables listing codes above 255 or in hex; typos; extra spaces producing an empty first token when splitting on ':'.","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"],"exampleFix":"// before\n\"0x42:hex:68656c6c6f\"\n// -> parsing option code: strconv.ParseUint: parsing \"0x42\": invalid syntax\n\n// after\n\"66:hex:68656c6c6f\"","handlingStrategy":"validation","validationCode":"func optionCodeOK(s string) bool {\n\tv, err := strconv.ParseUint(strings.TrimSpace(s), 10, 8)\n\treturn err == nil && v <= 255\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decimal codes 0–255 only","Convert vendor hex codes (0x42 → 66) before entry","Format strings as 'code:type:value' with no stray spaces"],"tags":["dhcp","options","validation","configuration","dhcp-option-code"],"backgroundTag":"invalid-option-code","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}