zed-industries/zed · error · anyhow::Error

invalid role '{value}'

Error message

invalid role '{value}'

What it means

Conversion guard in Role::try_from: a role string outside the closed set user/assistant/system/tool (e.g. from a deserialized payload or API response) cannot be mapped to the Role enum, so parsing fails naming the offending value.

Source

Thrown at crates/open_router/src/open_router.rs:60

#[derive(Clone, Copy, Serialize, Deserialize, Debug, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum Role {
    User,
    Assistant,
    System,
    Tool,
}

impl TryFrom<String> for Role {
    type Error = anyhow::Error;

    fn try_from(value: String) -> Result<Self> {
        match value.as_str() {
            "user" => Ok(Self::User),
            "assistant" => Ok(Self::Assistant),
            "system" => Ok(Self::System),
            "tool" => Ok(Self::Tool),
            _ => Err(anyhow!("invalid role '{value}'")),
        }
    }
}

impl From<Role> for String {
    fn from(val: Role) -> Self {
        match val {
            Role::User => "user".to_owned(),
            Role::Assistant => "assistant".to_owned(),
            Role::System => "system".to_owned(),
            Role::Tool => "tool".to_owned(),
        }
    }
}

#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
pub struct Model {

View on GitHub (pinned to 5a9b9558db)

Solutions

  1. Check the source payload for a misspelled or unexpected role value
  2. Update the OpenRouter schema handling if the API introduced a new role
  3. Sanitize/normalize role strings before conversion
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/open_router/src/open_router.rs:59 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20). Data as JSON: /api/errors/e063ed71374b2d7b. Report an issue: GitHub.