{"record":{"id":"cfabc727845531a3","repo":"iced-rs/iced","slug":"encode-input-message","errorCode":null,"errorMessage":"Encode input message","messagePattern":"Encode input message","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"beacon/src/client.rs","lineNumber":238,"sourceCode":"/// Otherwise, a default local server address will be returned.\npub fn server_address_from_env() -> String {\n    const DEFAULT_ADDRESS: &str = \"127.0.0.1:9167\";\n\n    std::env::var(\"ICED_BEACON_SERVER_ADDRESS\").unwrap_or_else(|_| String::from(DEFAULT_ADDRESS))\n}\n\nasync fn _connect() -> Result<net::TcpStream, io::Error> {\n    log::debug!(\"Attempting to connect to server...\");\n    let stream = net::TcpStream::connect(server_address_from_env()).await?;\n\n    stream.set_nodelay(true)?;\n    stream.writable().await?;\n\n    Ok(stream)\n}\n\nasync fn send(stream: &mut net::tcp::OwnedWriteHalf, message: Message) -> Result<(), io::Error> {\n    let bytes = bincode::serialize(&message).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 receive(\n    stream: &mut net::tcp::OwnedReadHalf,\n    buffer: &mut Vec<u8>,\n) -> Result<Command, Error> {\n    let size = stream.read_u64().await? as usize;\n\n    if buffer.len() < size {\n        buffer.resize(size, 0);\n    }","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/iced-rs/iced/blob/2cffa99b395d84fe469b44dccb56bbacd2f1a157/beacon/src/client.rs#L220-L256","documentation":"In iced's beacon debug bridge (the client an instrumented app uses to talk to the iced debug UI), `send` frames messages by bincode-serializing a `client::Message` and treating encoder failure as fatal via `.expect(\"Encode input message\")`. bincode's `serialize` only returns Err when the value's `Serialize` impl itself errors, so this is a protocol-invariant assertion, not a network error path.","triggerScenarios":"Any debug event sent after the beacon client connects (theme change, span finished, tasks spawned, subscriptions tracked, ...) goes through `send`. The panic fires only when serialization of that specific `Message` variant fails at runtime, e.g. a payload added to the protocol whose Serialize impl errors (skipped/malformed fields, invalid enum encoding).","commonSituations":"Extending iced's debug protocol with a new message variant that is not cleanly bincode-serializable; mixing an app built against one iced version with a beacon/debug UI built from another so the wire types differ; running with ICED_BEACON_SERVER_ADDRESS set during development.","solutions":["Fix the Message payload type so bincode can encode it (proper derived Serialize/Deserialize, no fallible serializer behavior)","Replace `.expect(...)` with `?` mapped into io::Error so a bad frame closes the connection instead of killing the app","Add a serialize+deserialize round-trip unit test covering every protocol variant","Unset ICED_BEACON_SERVER_ADDRESS or disable the debug feature to switch the bridge off while investigating"],"exampleFix":"// before\nlet bytes = bincode::serialize(&message).expect(\"Encode input message\");\n// after\nlet bytes = bincode::serialize(&message)\n    .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;","handlingStrategy":"validation","validationCode":"#[test]\nfn beacon_message_roundtrip() {\n    for msg in all_message_variants() { // helper enumerating every client::Message\n        let bytes = bincode::serialize(&msg).expect(\"serialize\");\n        let _back: Message = bincode::deserialize(&bytes).expect(\"deserialize\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the beacon protocol types' Serialize/Deserialize derived and covered by a round-trip test","Build the app and the iced debug UI from the same iced version so wire types match","Unset ICED_BEACON_SERVER_ADDRESS or disable the debug feature in release builds","Treat any payload added to Message/Command without derived serde as a breaking protocol change"],"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"}