{"record":{"id":"30ab56ef3c55941c","repo":"iced-rs/iced","slug":"encode-input-message-30ab56","errorCode":null,"errorMessage":"Encode input message","messagePattern":"Encode input message","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"beacon/src/lib.rs","lineNumber":301,"sourceCode":"    stream: &mut net::tcp::OwnedReadHalf,\n    buffer: &mut Vec<u8>,\n) -> Result<client::Message, Error> {\n    let size = stream.read_u64().await? as usize;\n\n    if buffer.len() < size {\n        buffer.resize(size, 0);\n    }\n\n    let _n = stream.read_exact(&mut buffer[..size]).await?;\n\n    Ok(bincode::deserialize(buffer)?)\n}\n\nasync fn send(\n    stream: &mut net::tcp::OwnedWriteHalf,\n    command: client::Command,\n) -> Result<(), io::Error> {\n    let bytes = bincode::serialize(&command).expect(\"Encode input message\");\n    let size = bytes.len() as u64;\n\n    stream.write_all(&size.to_be_bytes()).await?;\n    stream.write_all(&bytes).await?;\n    stream.flush().await?;\n\n    Ok(())\n}\n\nasync fn delay() {\n    tokio::time::sleep(Duration::from_secs(2)).await;\n}\n","sourceCodeStart":283,"sourceCodeEnd":314,"githubUrl":"https://github.com/iced-rs/iced/blob/2cffa99b395d84fe469b44dccb56bbacd2f1a157/beacon/src/lib.rs#L283-L314","documentation":"The beacon crate's own `send` (the side that pushes `client::Command`s over the length-prefixed TCP protocol) bincode-serializes the command and aborts on encoder failure via `.expect(\"Encode input message\")`. As on the client side, bincode only errors when the `Serialize` implementation of `Command` itself fails, so this guards an internal protocol invariant rather than any I/O condition.","triggerScenarios":"Sending any `client::Command` once a beacon TCP session is established. The panic occurs when a `Command` variant fails to serialize — typically after the debug protocol gained a payload type with a fallible Serialize impl, or when app and debug tool were built from mismatched iced versions.","commonSituations":"Adding a new Command variant with non-derived or partially-skipped serialization; protocol drift between the iced version of the app and of the debug UI; running the beacon server on the default 127.0.0.1:9167 while iterating on debug-tool code.","solutions":["Fix the `Command` payload type so bincode encodes it cleanly (derive Serialize/Deserialize for every variant)","Map the error into io::Error instead of panicking so the session degrades instead of the process dying","Round-trip test every Command variant in CI","Align iced/beacon versions between both ends of the connection"],"exampleFix":"// before\nlet bytes = bincode::serialize(&command).expect(\"Encode input message\");\n// after\nlet bytes = bincode::serialize(&command)\n    .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;","handlingStrategy":"validation","validationCode":"#[test]\nfn beacon_command_roundtrip() {\n    for cmd in all_command_variants() { // helper enumerating every client::Command\n        let bytes = bincode::serialize(&cmd).expect(\"serialize\");\n        let _back: Command = bincode::deserialize(&bytes).expect(\"deserialize\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive Serialize/Deserialize for every Command variant and round-trip test them","Pin both ends of the beacon connection (app and debug UI) to the same iced commit/version","Avoid hand-written serde impls in the debug protocol — they are the only realistic fallible encoders","Run the beacon server on a known address via ICED_BEACON_SERVER_ADDRESS during development so failures are attributable"],"tags":["rust","iced","debug","beacon","bincode","serde","serialization","panic"],"backgroundTag":"serialization-failed","analyzedSha":"2cffa99b395d84fe469b44dccb56bbacd2f1a157","analyzedAt":"2026-08-16T19:41:49.083Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}