{"record":{"id":"29bd240f9eeab761","repo":"loco-rs/loco","slug":"only-enum-supported","errorCode":null,"errorMessage":"only enum supported","messagePattern":"only enum supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/bgworker/mod.rs","lineNumber":67,"sourceCode":"\nimpl std::str::FromStr for JobStatus {\n    type Err = String;\n\n    fn from_str(s: &str) -> Result<Self, Self::Err> {\n        match s {\n            \"queued\" => Ok(Self::Queued),\n            \"processing\" => Ok(Self::Processing),\n            \"completed\" => Ok(Self::Completed),\n            \"failed\" => Ok(Self::Failed),\n            \"cancelled\" => Ok(Self::Cancelled),\n            _ => Err(format!(\"Invalid status: {s}\")),\n        }\n    }\n}\n\nimpl std::fmt::Display for JobStatus {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        to_variant_name(self).expect(\"only enum supported\").fmt(f)\n    }\n}\n\npub type JobId = String;\npub type JobData = JsonValue;\n\n/// A background job, shared between the SQL-based (Postgres/`SQLite`) and\n/// Redis queue providers.\n#[derive(Clone, Debug, Deserialize, Serialize)]\npub struct Job {\n    pub id: JobId,\n    pub name: String,\n    #[serde(rename = \"task_data\")]\n    pub data: JobData,\n    pub status: JobStatus,\n    pub run_at: DateTime<Utc>,\n    pub interval: Option<i64>,\n    pub created_at: Option<DateTime<Utc>>,","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/loco-rs/loco/blob/23639d1e360dbc618073642b507d6f8664adbaff/src/bgworker/mod.rs#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Avoid formatting JobStatus values that may carry payloads; match and format only known unit variants","Implement Display with an explicit `match self` instead of relying on `to_variant_name`","Update `to_variant_name` handling if a new JobStatus variant was added","If it fires on stock variants, report a loco-rs bug"],"exampleFix":"// before\nfn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n    to_variant_name(self).expect(\"only enum supported\").fmt(f)\n}\n// after\nfn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n    match self {\n        JobStatus::Queued => write!(f, \"queued\"),\n        JobStatus::Completed => write!(f, \"completed\"),\n        other => write!(f, \"{}\", to_variant_name(other).unwrap_or_default()),\n    }\n}","handlingStrategy":"try-catch","validationCode":"matches!(status, JobStatus::Queued | JobStatus::Completed) // only unit variants before formatting","typeGuard":null,"tryCatchPattern":"let name = std::panic::catch_unwind(|| format!(\"{status}\")).ok()\n    .unwrap_or_else(|| \"<non-unit job status>\".to_string());","preventionTips":["Only format JobStatus values that are known unit variants","Add tests for Display of every new JobStatus variant","Prefer explicit match-based Display implementations over to_variant_name"],"tags":["panic","enum","display","background-jobs"],"backgroundTag":"unsupported-operation","analyzedSha":"23639d1e360dbc618073642b507d6f8664adbaff","analyzedAt":"2026-09-12T01:47:20.769Z","contentChangedAt":"2026-09-12T01:47:20.769Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}