{"record":{"id":"45a4f9743fa39b3c","repo":"embassy-rs/embassy","slug":"invalid-value","errorCode":null,"errorMessage":"Invalid value {}","messagePattern":"Invalid value (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-net-adin1110/src/regs.rs","lineNumber":355,"sourceCode":"            11 => LedFunc::TxSop,\n            12 => LedFunc::RxSop,\n            13 => LedFunc::On,\n            14 => LedFunc::Off,\n            15 => LedFunc::Blink,\n            16 => LedFunc::TxLevel2P4,\n            17 => LedFunc::TxLevel1P0,\n            18 => LedFunc::Master,\n            19 => LedFunc::Slave,\n            20 => LedFunc::IncompatiableLinkCfg,\n            21 => LedFunc::AnLinkGood,\n            22 => LedFunc::AnComplete,\n            23 => LedFunc::TsTimer,\n            24 => LedFunc::LocRcvrStatus,\n            25 => LedFunc::RemRcvrStatus,\n            26 => LedFunc::Clk25Ref,\n            27 => LedFunc::TxTCLK,\n            28 => LedFunc::Clk120MHz,\n            e => panic!(\"Invalid value {}\", e),\n        }\n    }\n}\n\n/// LED Control Register\n#[cfg_attr(not(feature = \"generic-spi\"), allow(dead_code))]\n#[derive(Copy, Clone, PartialEq, Eq, Hash)]\npub struct LedCntrl(pub u16);\nbitfield_bitrange! {struct LedCntrl(u16)}\n\nimpl LedCntrl {\n    bitfield_fields! {\n        u8;\n        /// LED 0 Pin Function\n        pub from into LedFunc, led0_function, set_led0_function: 4, 0;\n        /// LED 0 Mode Selection\n        pub led0_mode, set_led0_mode: 5;\n        /// Qualify Certain LED 0 Options with Link Status.","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-net-adin1110/src/regs.rs#L337-L373","documentation":"This From<u8> impl converts the LED-function field of the ADIN1110 LED control register into the LedFunc enum; a value outside the 0–28 documented mapping panics with \"Invalid value\". The library throws it because the hardware field was expected to contain only datasheet-defined LED function codes.","triggerScenarios":"Reading the LED control register and converting its LED-function bits via LedFunc::from when the field holds a code > 28 (or a reserved value), or writing an out-of-range value into the field and echoing it back through the conversion.","commonSituations":"Constructing LED configuration from user-provided numbers; reading back reserved codes on newer silicon revisions; accidentally shifting the LED-function field and feeding the wrong bits into the conversion.","solutions":["Only pass values 0–28 into LedFunc::from; validate the field before converting.","Check bit-extraction code — ensure you are masking/shifting to the correct LED function field.","If a new silicon revision defines extra codes, extend the match table or switch to a fallible TryFrom<u8>."],"exampleFix":"// before\nlet func = LedFunc::from(value); // panics if value > 28\n// after\nlet func = LedFunc::try_from(value).unwrap_or(LedFunc::Off); // or handle the error","handlingStrategy":"validation","validationCode":"// Rust: check the LED-function field range before conversion\nfn is_valid_led_func(v: u8) -> bool { v <= 28 }\n\nlet field = (led_ctrl >> shift) & mask;\nassert!(is_valid_led_func(field), \"LED func {} out of range 0..=28\", field);","typeGuard":"// Rust: fallible conversion guard\nfn to_led_func(v: u8) -> Option<LedFunc> {\n    (v <= 28).then(|| LedFunc::from(v))\n}","tryCatchPattern":null,"preventionTips":["Mask and shift the correct bit field before converting to LedFunc.","Only use datasheet-defined codes (0–28) when writing LED configuration.","Handle reserved/newer-silicon codes explicitly instead of round-tripping raw values.","Use TryFrom for enum conversions over hardware-sourced data."],"tags":["embedded","rust","ethernet","led-control","enum","panic"],"backgroundTag":"invalid-enum-value","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}