n0-computer/iroh · error · MaxLengthExceededError
MaxLengthExceededError
MaxLengthExceededError
Error message
max length exceeded
What it means
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.
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.
Example fix
// before let user_data = UserData::try_from(long_status_string)?; // panics on error path / MaxLengthExceededError // after let s = &long_status_string[..UserData::MAX_LENGTH.min(long_status_string.len())]; let user_data = UserData::try_from(s.to_string())?;
Defensive patterns
Strategy: validation
Validate before calling
fn fits_user_data(s: &str) -> Result<(), &'static str> {
if s.len() > UserData::MAX_LENGTH { Err("user data too long for DNS record") } else { Ok(()) }
} Try / catch
match UserData::try_from(value) {
Ok(ud) => ud,
Err(_) => UserData::try_from(truncate(&value, UserData::MAX_LENGTH))?,
} Prevention
- 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
When it happens
Trigger: Calling UserData::try_from(some_string) where some_string.len() > UserData::MAX_LENGTH.
Common situations: 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.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
AI-assisted analysis of n0-computer/iroh@2b4de030ce (2026-09-08).
Data as JSON: /api/errors/ef896470a67054ac.
Report an issue: GitHub.
Appendix: source
Thrown at iroh-dns/src/endpoint_info.rs:327
/// The max byte length allowed for user-defined data.
///
/// In DNS discovery services, the user-defined data is stored in a TXT record character string,
/// which has a max length of 255 bytes. We need to subtract the `user-data=` prefix,
/// which leaves 245 bytes for the actual user-defined data.
pub const MAX_LENGTH: usize = 245;
}
/// Error returned when an input value is too long for [`UserData`].
#[allow(missing_docs)]
#[stack_error(derive, add_meta)]
#[error("max length exceeded")]
pub struct MaxLengthExceededError {}
impl TryFrom<String> for UserData {
type Error = MaxLengthExceededError;
fn try_from(value: String) -> Result<Self, Self::Error> {
ensure!(value.len() <= Self::MAX_LENGTH, MaxLengthExceededError);
Ok(Self(value))
}
}
impl FromStr for UserData {
type Err = MaxLengthExceededError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
ensure!(s.len() <= Self::MAX_LENGTH, MaxLengthExceededError);
Ok(Self(s.to_string()))
}
}
impl fmt::Display for UserData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}View on GitHub (pinned to 2b4de030ce)