{"record":{"id":"abeb87bfa4f1015e","repo":"sxyazi/yazi","slug":"not-a-dict","errorCode":null,"errorMessage":"not a dict","messagePattern":"not a dict","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/data/data.rs","lineNumber":163,"sourceCode":"\t\tvalue.try_into().map(|s: &str| s.to_owned())\n\t}\n}\n\nimpl TryFrom<Data> for String {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: Data) -> Result<Self, Self::Error> {\n\t\tSStr::try_from(value).map(|s| s.into_owned())\n\t}\n}\n\nimpl TryFrom<&Data> for HashMap<DataKey, Data> {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: &Data) -> Result<Self, Self::Error> {\n\t\tmatch value {\n\t\t\tData::Dict(d) => Ok(d.clone()),\n\t\t\t_ => bail!(\"not a dict\"),\n\t\t}\n\t}\n}\n\nimpl TryFrom<Data> for HashMap<DataKey, Data> {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: Data) -> Result<Self, Self::Error> {\n\t\tmatch value {\n\t\t\tData::Dict(d) => Ok(d),\n\t\t\t_ => bail!(\"not a dict\"),\n\t\t}\n\t}\n}\n\nimpl TryFrom<Data> for UrlCow<'static> {\n\ttype Error = anyhow::Error;\n","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-shared/src/data/data.rs#L145-L181","documentation":"This error comes from `TryFrom<&Data> for HashMap<DataKey, Data>` in yazi-shared's Data layer. It is thrown when a `Data` value that is not a `Data::Dict` variant is converted into a dict map. The conversion only succeeds for the `Dict` variant; every other variant bails with \"not a dict\".","triggerScenarios":"Calling `.try_into()` / `HashMap::try_from(&data)` on a `&Data` holding `String`, `Bytes`, `Url`, `Path`, `Bool`, `Integer`, `Number`, or `Any` instead of `Data::Dict`.","commonSituations":"Plugin/config code that assumes a fetch/preload payload or Lua-bound value is a table (dict) but receives a scalar or URL because the producer emitted a different variant, or a field was extracted from the wrong key.","solutions":["Match on the Data value and confirm the variant is `Data::Dict` before converting.","Fix the producer so it wraps the map in `Data::Dict` (e.g. `Data::Dict(map)` or the dict constructor helper).","If the value may legitimately be scalar, handle each variant explicitly instead of a blanket try_into."],"exampleFix":"// before\nlet map: HashMap<DataKey, Data> = (&data).try_into()?;\n// after\nlet map: HashMap<DataKey, Data> = match &data {\n    Data::Dict(_) => (&data).try_into()?,\n    other => bail!(\"expected dict, got {other:?}\"),\n};","handlingStrategy":"type-guard","validationCode":"fn is_dict(data: &Data) -> bool { matches!(data, Data::Dict(_)) }","typeGuard":"fn as_dict(data: &Data) -> Option<&HashMap<DataKey, Data>> {\n    if let Data::Dict(d) = data { Some(d) } else { None }\n}","tryCatchPattern":"match HashMap::<DataKey, Data>::try_from(&data) {\n    Ok(map) => use_map(map),\n    Err(e) => log::warn!(\"expected dict payload: {e}\"),\n}","preventionTips":["Always construct payloads with explicit `Data::Dict` wrappers for map values.","Match on Data variants at API boundaries instead of assuming shapes.","Add debug logging of the Data variant when a conversion fails."],"tags":["rust","type-conversion","data"],"backgroundTag":"type-conversion-failed","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}