{"record":{"id":"984dd8f32dc148e0","repo":"stride3d/stride","slug":"while-scanning-a-yaml-directive-did-not-find-expected","errorCode":null,"errorMessage":"While scanning a %YAML directive, did not find expected version number.","messagePattern":"While scanning a %YAML directive, did not find expected version number\\.","errorType":"exception","errorClass":"SyntaxErrorException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Scanner.cs","lineNumber":2293,"sourceCode":"            while (analyzer.IsDigit())\n            {\n                // Check if the number is too long.\n\n                if (++length > MaxVersionNumberLength)\n                {\n                    throw new SyntaxErrorException(start, mark, \"While scanning a %YAML directive, find extremely long version number.\");\n                }\n\n                value = value*10 + analyzer.AsDigit();\n\n                Skip();\n            }\n\n            // Check if the number was present.\n\n            if (length == 0)\n            {\n                throw new SyntaxErrorException(start, mark, \"While scanning a %YAML directive, did not find expected version number.\");\n            }\n\n            return value;\n        }\n\n        /// <summary>\n        /// Check if a simple key may start at the current position and add it if\n        /// needed.\n        /// </summary>\n        private void SaveSimpleKey()\n        {\n            // A simple key is required at the current position if the scanner is in\n            // the block context and the current column coincides with the indentation\n            // level.\n\n\n            bool isRequired = (flowLevel == 0 && indent == mark.Column);\n","sourceCodeStart":2275,"sourceCodeEnd":2311,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Scanner.cs#L2275-L2311","documentation":"Scanner.ScanVersionDirectiveValue finished reading a %YAML directive component but consumed zero digits, meaning the expected major or minor version number is missing. Since a %YAML directive requires 'major.minor', the scanner throws SyntaxErrorException.","triggerScenarios":"Directives like '%YAML' alone, '%YAML .' or '%YAML 1.' (missing minor), or '%YAML x.y' where a non-digit appears where the version number must start.","commonSituations":"Truncated directive lines from failed edits; placeholders like '%YAML {version}' left by templates; files concatenated so the version digits ended up on the next line.","solutions":["Write a complete version: '%YAML 1.1' (or 1.2).","Remove the %YAML directive entirely if version declaration is not needed.","Fix template placeholders so a literal version number is emitted.","Catch SyntaxErrorException and surface the mark/line for the user to fix the directive."],"exampleFix":"// before (input.yaml)\n%YAML 1.\n---\ndoc: true\n\n// after (input.yaml)\n%YAML 1.1\n---\ndoc: true","handlingStrategy":"validation","validationCode":"// C#\nvar m = System.Text.RegularExpressions.Regex.Match(yamlText ?? \"\", @\"^%YAML\\s+\\d+\\.\\d+\\s*$\", System.Text.RegularExpressions.RegexOptions.Multiline);\nif (yamlText != null && yamlText.Contains(\"%YAML\") && !m.Success)\n    throw new FormatException(\"%YAML directive must be of the form '%YAML major.minor' (e.g. '%YAML 1.1').\");","typeGuard":null,"tryCatchPattern":"try { deserializer.Deserialize(reader, targetType); }\ncatch (SyntaxErrorException ex) { throw new YamlConfigException($\"Incomplete %YAML version directive at line {ex.Start.Line}\", ex); }","preventionTips":["Templates must substitute a literal version number, never placeholders.","Validate directive lines with a regex before deserializing user-supplied YAML.","Drop the %YAML directive if you don't need an explicit version."],"tags":["yaml","directives","parsing"],"backgroundTag":"yaml-parse-error","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}