{"record":{"id":"2c7435f62aa2b929","repo":"windmill-labs/windmill","slug":"yaml-emit-error","errorCode":null,"errorMessage":"YAML emit error: {}","messagePattern":"YAML emit error: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-yaml/src/lib.rs","lineNumber":943,"sourceCode":"    logs.push_str(\n        &update_versions(\"roles\", doc, role_versions)\n            .map_err(|e| anyhow!(\"Error updating role versions: {e}\"))?,\n    );\n    logs.push_str(\n        &update_versions(\"collections\", doc, collection_versions)\n            .map_err(|e| anyhow!(\"Error updating collection versions: {e}\"))?,\n    );\n\n    if !logs.is_empty() {\n        logs.push_str(\"WARNING: You might want to try adding manual versions for these, otherwise there could be breaking changes on deployed scripts\\n\");\n    }\n\n    let mut out_str = String::new();\n    {\n        let mut emitter = YamlEmitter::new(&mut out_str);\n        emitter\n            .dump(doc)\n            .map_err(|e| anyhow!(\"YAML emit error: {}\", e))?;\n    }\n\n    Ok((out_str, logs))\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_parse_ansible_assets() {\n        let p = r#\"\n---\ninventory:\n  - resource_type: ansible_inventory\n    # You can pin an inventory to this script by hardcoding the resource path:\n    # resource: u/user/your_resource\n# - name: hcloud.yml","sourceCodeStart":925,"sourceCodeEnd":961,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-yaml/src/lib.rs#L925-L961","documentation":"add_versions_to_requirements_yaml in windmill-parser-yaml re-serializes a parsed YAML document after injecting version pins into the requirements. When yaml-rust's YamlEmitter::dump fails to serialize the mutated document, the error is wrapped as 'YAML emit error: {}'. This is thrown by the ansible dependency parser when it cannot emit the resulting document back to a string.","triggerScenarios":"Calling add_versions_to_requirements_yaml (via the ansible_dep parser path) with a requirements YAML that, after version annotation, produces a document structure the YamlEmitter cannot dump — e.g. deeply non-standard or malformed nodes introduced by parsing odd input.","commonSituations":"An Ansible requirements.yml with unusual syntax (anchors, tags, non-string keys) that parses but re-emits badly; corrupted requirements file contents pasted from elsewhere; upstream yaml crate changes in serialization rules.","solutions":["Simplify the requirements YAML to standard list-of-mappings syntax (collections/roles with name/version keys)","Validate the YAML with a linter (yamllint) and fix non-standard constructs like anchors or duplicate keys","Pin the requirements to explicit 'name'/'version' string values instead of shorthand forms","Check the windmill-yaml-parser dependency version; upgrade if the yaml-rust emitter bug was fixed"],"exampleFix":"# before (shorthand, may emit badly)\ncollections:\n  - community.general\n\n# after\n collections:\n  - name: community.general\n    version: 8.0.0","handlingStrategy":"validation","validationCode":"// validate YAML structure before handing to parser\nlet doc: Yaml = serde_yaml::from_str(&req_yaml)?;\nfor c in doc.as_vec().ok_or(\"requirements must be a list\")? {\n    let m = c.as_hash().ok_or(\"each entry must be a mapping\")?;\n    assert!(m.contains_key(&Yaml::from_str(\"name\")), \"missing 'name' key\");\n}","typeGuard":null,"tryCatchPattern":"match add_versions_to_requirements_yaml(&yaml) {\n    Ok((out, logs)) => out,\n    Err(e) if e.to_string().contains(\"YAML emit error\") => {\n        tracing::warn!(\"requirements YAML could not be re-emitted: {e:#}\");\n        fallback_to_original(yaml)\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep requirements files in the canonical list-of-mappings form","Run yamllint on requirements files in CI","Avoid YAML anchors/aliases and exotic tags in requirements"],"tags":["yaml","rust","parsing"],"backgroundTag":"yaml-serialization-failed","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}