loco-rs/loco · error

only enum supported

Error message

only enum supported

What it means

Panic in `JobStatus`'s `Display` impl when `to_variant_name` cannot derive a variant name. `to_variant_name` only works on enum variants with unit payloads; a JobStatus value with data (or a non-enum) makes it fail, so the code panics with this message.

Solutions

  1. Avoid formatting JobStatus values that may carry payloads; match and format only known unit variants
  2. Implement Display with an explicit `match self` instead of relying on `to_variant_name`
  3. Update `to_variant_name` handling if a new JobStatus variant was added
  4. If it fires on stock variants, report a loco-rs bug

Example fix

// before
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    to_variant_name(self).expect("only enum supported").fmt(f)
}
// after
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    match self {
        JobStatus::Queued => write!(f, "queued"),
        JobStatus::Completed => write!(f, "completed"),
        other => write!(f, "{}", to_variant_name(other).unwrap_or_default()),
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

matches!(status, JobStatus::Queued | JobStatus::Completed) // only unit variants before formatting

Try / catch

let name = std::panic::catch_unwind(|| format!("{status}")).ok()
    .unwrap_or_else(|| "<non-unit job status>".to_string());

Prevention

When it happens

Trigger: Formatting a `JobStatus` (e.g. via `format!`/`println!`/logging) whose value is an enum variant carrying data or a serialized representation `to_variant_name` cannot handle.

Common situations: Logging job status values returned by queue backends that deserialize into non-unit variants; writing custom Display/log code around JobStatus after adding new variants.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of loco-rs/loco@23639d1e36 (2026-09-12). Data as JSON: /api/errors/29bd240f9eeab761. Report an issue: GitHub.

Appendix: source

Thrown at src/bgworker/mod.rs:67

impl std::str::FromStr for JobStatus {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "queued" => Ok(Self::Queued),
            "processing" => Ok(Self::Processing),
            "completed" => Ok(Self::Completed),
            "failed" => Ok(Self::Failed),
            "cancelled" => Ok(Self::Cancelled),
            _ => Err(format!("Invalid status: {s}")),
        }
    }
}

impl std::fmt::Display for JobStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        to_variant_name(self).expect("only enum supported").fmt(f)
    }
}

pub type JobId = String;
pub type JobData = JsonValue;

/// A background job, shared between the SQL-based (Postgres/`SQLite`) and
/// Redis queue providers.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Job {
    pub id: JobId,
    pub name: String,
    #[serde(rename = "task_data")]
    pub data: JobData,
    pub status: JobStatus,
    pub run_at: DateTime<Utc>,
    pub interval: Option<i64>,
    pub created_at: Option<DateTime<Utc>>,

View on GitHub (pinned to 23639d1e36)