{"record":{"id":"ddea7f5be752bb0f","repo":"stride3d/stride","slug":"while-scanning-a-directive-could-not-find-expected-directive","errorCode":null,"errorMessage":"While scanning a directive, could not find expected directive name.","messagePattern":"While scanning a directive, could not find expected directive name\\.","errorType":"exception","errorClass":"SyntaxErrorException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Scanner.cs","lineNumber":2012,"sourceCode":"        ///      %TAG    !yaml!  tag:yaml.org,2002:  \\n\n        ///       ^^^\n        /// </summary>\n        private string ScanDirectiveName(Mark start)\n        {\n            StringBuilder name = new StringBuilder();\n\n            // Consume the directive name.\n\n            while (analyzer.IsAlpha())\n            {\n                name.Append(ReadCurrentCharacter());\n            }\n\n            // Check if the name is empty.\n\n            if (name.Length == 0)\n            {\n                throw new SyntaxErrorException(start, mark, \"While scanning a directive, could not find expected directive name.\");\n            }\n\n            // Check for an blank character after the name.\n\n            if (!analyzer.IsBlankOrBreakOrZero())\n            {\n                throw new SyntaxErrorException(start, mark, \"While scanning a directive, find unexpected non-alphabetical character.\");\n            }\n\n            return name.ToString();\n        }\n\n        private void SkipWhitespaces()\n        {\n            // Eat whitespaces.\n\n            while (analyzer.IsBlank())\n            {","sourceCodeStart":1994,"sourceCodeEnd":2030,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Scanner.cs#L1994-L2030","documentation":"Thrown by the YAML Scanner when a '%' starts a directive line ('%YAML', '%TAG', etc.) but no directive name characters follow before whitespace, line break, or end of input. A directive line must carry a name immediately after '%'.","triggerScenarios":"Parsing a YAML stream containing a bare '%' at the start of a line (e.g. '% ' or a lone '%' line), which the scanner reads as the start of a directive with an empty name.","commonSituations":"Template placeholders like '%name%' left unexpanded in YAML files; snippets pasted from LaTeX/protobuf syntax that use '%' comments; files generated by broken templating engines.","solutions":["Remove the stray '%' line if it was not intended as a YAML directive.","Complete the directive, e.g. '%YAML 1.1' followed by '---'.","If '%' must appear as content, quote it ('%name%') or move it after the '---' document start.","Fix the templating pipeline so placeholders are substituted before the YAML is parsed."],"exampleFix":"// before\n%name%\nkey: value\n// after\n---\nkey: \"%name%\"","handlingStrategy":"try-catch","validationCode":"// Detect bare directive lines with empty name\nbool HasBareDirective(string yaml) => yaml.Split('\\n').Any(l => l.TrimEnd().TrimEnd(' ', '\\t') == \"%\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var obj = Deserializer.FromFile(path);\n}\ncatch (SyntaxErrorException ex)\n{\n    Log.Error(ex, \"Malformed directive at line {Line}\", ex.Start.Line);\n    throw new YamlConfigException(\"Invalid YAML directive\", ex);\n}","preventionTips":["Ensure template placeholders (like %name%) are fully substituted before parsing","Only emit real YAML directives (%YAML, %TAG) and always with a name and arguments","Escape stray '%' characters by quoting the line as content"],"tags":["yaml","scanner","directive","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-15T23:17:13.987Z"}