linera-io/linera-protocol · error

Invalid parsing of GenericApplicationId

Error message

Invalid parsing of GenericApplicationId

What it means

GenericApplicationId::from_str accepts exactly two textual forms: the literal 'System' or 'User:<ApplicationId>' (the user application ID in its own Display format). Anything else raises this error. A common confusion is passing a bare application ID without the 'User:' prefix.

Source

Thrown at linera-base/src/identifiers.rs:473

                Display::fmt("User:", f)?;
                Display::fmt(&application_id, f)
            }
        }
    }
}

impl std::str::FromStr for GenericApplicationId {
    type Err = anyhow::Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        if s == "System" {
            return Ok(GenericApplicationId::System);
        }
        if let Some(result) = s.strip_prefix("User:") {
            let application_id = ApplicationId::from_str(result)?;
            return Ok(GenericApplicationId::User(application_id));
        }
        Err(anyhow!("Invalid parsing of GenericApplicationId"))
    }
}

impl<A> From<ApplicationId<A>> for AccountOwner {
    fn from(app_id: ApplicationId<A>) -> Self {
        if app_id.is_evm() {
            let hash_bytes = app_id.application_description_hash.as_bytes();
            AccountOwner::Address20(hash_bytes[..20].try_into().unwrap())
        } else {
            AccountOwner::Address32(app_id.application_description_hash)
        }
    }
}

impl From<AccountPublicKey> for AccountOwner {
    fn from(public_key: AccountPublicKey) -> Self {
        match public_key {
            AccountPublicKey::Ed25519(public_key) => public_key.into(),

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Prefix user application IDs with 'User:' before parsing
  2. Serialize with GenericApplicationId::to_string() and reuse that exact string
  3. For the system variant pass the exact literal 'System' (capital S)

Example fix

// before: bare application ID
let id: GenericApplicationId = app_id_str.parse()?; // Err

// after: prefixed form
let id: GenericApplicationId = format!("User:{app_id_str}").parse()?;
Defensive patterns

Strategy: type-guard

Validate before calling

fn looks_like_generic_app_id(s: &str) -> bool {
    s == "System" || s.starts_with("User:")
}

Type guard

fn parse_generic_app_id(s: &str) -> Option<GenericApplicationId> {
    s.parse().ok()
}

Prevention

When it happens

Trigger: Calling parse::<GenericApplicationId>() on a bare application ID like 'e40c...:7019...' (missing 'User:' prefix), a lowercase 'system' (case-sensitive), an empty string, or any other unprefixed value. Note 'User:' with an invalid remainder surfaces ApplicationId's own error instead.

Common situations: Glue code that formats the enum by hand; configuration files that store only the application ID; string formats that changed across Linera versions; frontend input passed straight to a GraphQL/API endpoint that parses this type.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/94f3a8e15646a563. Report an issue: GitHub.