{"record":{"id":"ef896470a67054ac","repo":"n0-computer/iroh","slug":"maxlengthexceedederror","errorCode":"MaxLengthExceededError","errorMessage":"max length exceeded","messagePattern":"max length exceeded","errorType":"validation","errorClass":"MaxLengthExceededError","httpStatus":null,"severity":"error","filePath":"iroh-dns/src/endpoint_info.rs","lineNumber":327,"sourceCode":"    /// The max byte length allowed for user-defined data.\n    ///\n    /// In DNS discovery services, the user-defined data is stored in a TXT record character string,\n    /// which has a max length of 255 bytes. We need to subtract the `user-data=` prefix,\n    /// which leaves 245 bytes for the actual user-defined data.\n    pub const MAX_LENGTH: usize = 245;\n}\n\n/// Error returned when an input value is too long for [`UserData`].\n#[allow(missing_docs)]\n#[stack_error(derive, add_meta)]\n#[error(\"max length exceeded\")]\npub struct MaxLengthExceededError {}\n\nimpl TryFrom<String> for UserData {\n    type Error = MaxLengthExceededError;\n\n    fn try_from(value: String) -> Result<Self, Self::Error> {\n        ensure!(value.len() <= Self::MAX_LENGTH, MaxLengthExceededError);\n        Ok(Self(value))\n    }\n}\n\nimpl FromStr for UserData {\n    type Err = MaxLengthExceededError;\n\n    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {\n        ensure!(s.len() <= Self::MAX_LENGTH, MaxLengthExceededError);\n        Ok(Self(s.to_string()))\n    }\n}\n\nimpl fmt::Display for UserData {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        write!(f, \"{}\", self.0)\n    }\n}","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/n0-computer/iroh/blob/2b4de030ce5e0133f272871a76f0c685c63f552a/iroh-dns/src/endpoint_info.rs#L309-L345","documentation":"MaxLengthExceededError from iroh-dns's UserData. UserData::try_from(String) validates that the string does not exceed UserData::MAX_LENGTH before wrapping it; longer strings are rejected. This bound exists because user data is embedded in DNS discovery records with strict size limits.","triggerScenarios":"Calling UserData::try_from(some_string) where some_string.len() > UserData::MAX_LENGTH.","commonSituations":"Publishing endpoint info to iroh DNS discovery with overly long user-data payloads (large JSON blobs, long descriptions); user input passed straight through into discovery metadata.","solutions":["Shorten the user data string to at most UserData::MAX_LENGTH bytes before constructing.","Compress or serialize the payload more compactly (e.g. minimal JSON, base64 of packed data).","Truncate or split the data and store the remainder out-of-band (e.g. in your own service, referenced by a short ID).","Check the length in application code before calling try_from to fail gracefully."],"exampleFix":"// before\nlet user_data = UserData::try_from(long_status_string)?; // panics on error path / MaxLengthExceededError\n// after\nlet s = &long_status_string[..UserData::MAX_LENGTH.min(long_status_string.len())];\nlet user_data = UserData::try_from(s.to_string())?;","handlingStrategy":"validation","validationCode":"fn fits_user_data(s: &str) -> Result<(), &'static str> {\n    if s.len() > UserData::MAX_LENGTH { Err(\"user data too long for DNS record\") } else { Ok(()) }\n}","typeGuard":null,"tryCatchPattern":"match UserData::try_from(value) {\n    Ok(ud) => ud,\n    Err(_) => UserData::try_from(truncate(&value, UserData::MAX_LENGTH))?,\n}","preventionTips":["Keep discovery user data small and compact","Truncate user-supplied input before publishing","Store large payloads out-of-band with a short reference","Check len() against UserData::MAX_LENGTH before constructing"],"tags":["dns","validation","size-limit","user-data"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"2b4de030ce5e0133f272871a76f0c685c63f552a","analyzedAt":"2026-09-08T04:26:47.755Z","contentChangedAt":"2026-09-08T04:26:47.755Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}