{"record":{"id":"dc76676190504327","repo":"elkowar/eww","slug":"generated-well-known-name-is-invalid","errorCode":null,"errorMessage":"generated well-known name is invalid","messagePattern":"generated well-known name is invalid","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/notifier_host/src/host.rs","lineNumber":42,"sourceCode":"/// `org.freedesktop.StatusNotifierHost-{pid}-{nr}`, and registers it to active\n/// StatusNotifierWatcher. The name and the StatusNotifierWatcher proxy are returned.\n///\n/// You still need to call [`run_host`] to have the instance of [`Host`] be notified of new and\n/// removed items.\npub async fn register_as_host(\n    con: &zbus::Connection,\n) -> zbus::Result<(zbus::names::WellKnownName<'static>, proxy::StatusNotifierWatcherProxy<'static>)> {\n    let snw = proxy::StatusNotifierWatcherProxy::new(con).await?;\n\n    // get a well-known name\n    let pid = std::process::id();\n    let mut i = 0;\n    let wellknown = loop {\n        use zbus::fdo::RequestNameReply::*;\n\n        i += 1;\n        let wellknown = format!(\"org.freedesktop.StatusNotifierHost-{}-{}\", pid, i);\n        let wellknown: zbus::names::WellKnownName = wellknown.try_into().expect(\"generated well-known name is invalid\");\n\n        let flags = [zbus::fdo::RequestNameFlags::DoNotQueue];\n        match con.request_name_with_flags(&wellknown, flags.into_iter().collect()).await? {\n            PrimaryOwner => break wellknown,\n            Exists => {}\n            AlreadyOwner => {}\n            InQueue => unreachable!(\"request_name_with_flags returned InQueue even though we specified DoNotQueue\"),\n        };\n    };\n\n    // register it to the StatusNotifierWatcher, so that they know there is a systray on the system\n    snw.register_status_notifier_host(&wellknown).await?;\n\n    Ok((wellknown, snw))\n}\n\n/// Run the Host forever, calling its methods as signals are received from the StatusNotifierWatcher.\n///","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/elkowar/eww/blob/48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa/crates/notifier_host/src/host.rs#L24-L60","documentation":"register_as_host builds a D-Bus well-known name \"org.freedesktop.StatusNotifierHost-<pid>-<i>\" and converts it with WellKnownName::try_into; the expect panics if zbus rejects the name as syntactically invalid. Well-known names must match the D-Bus name grammar (elements of [A-Za-z0-9_], no element starting with a digit, total length ≤ 255).","triggerScenarios":"The generated name fails zbus validation — realistically only if pid or the counter formatting produces an invalid name, e.g. a pid with characters outside the allowed set (some namespaces can surface exotic pid strings) or, in older zbus versions, stricter validation rules rejecting otherwise-normal names.","commonSituations":"Running in containers/namespace setups with unusual pid representations, or with a zbus version whose WellKnownName validation changed, making previously accepted host names invalid.","solutions":["Check the zbus version; upgrade or pin zbus so WellKnownName validation matches the names eww generates (validation rules changed across zbus releases).","Sanitize the composed name: replace any character outside [A-Za-z0-9_] with '_' before try_into, and cap total length at 255.","Print the generated name in the panic message to diagnose which character/length violated the grammar.","Replace expect with `?` so a bad name is reported as an error and the host can retry with a different suffix."],"exampleFix":"// before\nlet wellknown = format!(\"org.freedesktop.StatusNotifierHost-{}-{}\", pid, i);\nlet wellknown: zbus::names::WellKnownName = wellknown.try_into().expect(\"generated well-known name is invalid\");\n// after\nlet raw = format!(\"org.freedesktop.StatusNotifierHost-{}-{}\", pid, i);\nlet wellknown: zbus::names::WellKnownName = raw\n    .try_into()\n    .with_context(|| format!(\"generated well-known name is invalid: {}\", raw))?;","handlingStrategy":"validation","validationCode":"fn is_valid_wellknown(name: &str) -> bool {\n    name.len() <= 255\n        && !name.is_empty()\n        && name.split('.').all(|el| !el.is_empty()\n            && el.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')\n            && !el.chars().next().unwrap().is_ascii_digit())\n}","typeGuard":null,"tryCatchPattern":"match zbus::names::WellKnownName::try_from(raw.as_str()) {\n    Ok(n) => /* request name */,\n    Err(e) => return Err(anyhow!(\"invalid well-known name {}: {}\", raw, e)),\n}","preventionTips":["Sanitize pid/counter segments to [A-Za-z0-9_] before composing the name","Cap name length at 255 characters","Pin/upgrade zbus deliberately; its name validation rules changed between versions","Use ? instead of expect so retries with a new suffix are possible"],"tags":["dbus","zbus","systray","naming"],"backgroundTag":"invalid-identifier-format","analyzedSha":"48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa","analyzedAt":"2026-09-08T03:13:26.897Z","contentChangedAt":"2026-09-08T03:13:26.897Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}