{"record":{"id":"7fcd3a9f6b974e0d","repo":"stride3d/stride","slug":"while-scanning-an-anchor-or-alias-did-not-find-expected","errorCode":null,"errorMessage":"While scanning an anchor or alias, did not find expected alphabetic or numeric character.","messagePattern":"While scanning an anchor or alias, did not find expected alphabetic or numeric character\\.","errorType":"exception","errorClass":"SyntaxErrorException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Yaml/Scanner.cs","lineNumber":1164,"sourceCode":"\n            // Consume the value.\n\n            StringBuilder value = new StringBuilder();\n            while (analyzer.IsAlpha())\n            {\n                value.Append(ReadCurrentCharacter());\n            }\n\n\n            // Check if length of the anchor is greater than 0 and it is followed by\n            // a whitespace character or one of the indicators:\n\n            //      '?', ':', ',', ']', '}', '%', '@', '`'.\n\n\n            if (value.Length == 0 || !(analyzer.IsBlankOrBreakOrZero() || analyzer.Check(\"?:,]}%@`\")))\n            {\n                throw new SyntaxErrorException(start, mark, \"While scanning an anchor or alias, did not find expected alphabetic or numeric character.\");\n            }\n\n            // Create a token.\n\n            if (isAlias)\n            {\n                return new AnchorAlias(value.ToString(), start, mark);\n            }\n            else\n            {\n                return new Anchor(value.ToString(), start, mark);\n            }\n        }\n\n        /// <summary>\n        /// Produce the TAG token.\n        /// </summary>\n        private void FetchTag()","sourceCodeStart":1146,"sourceCodeEnd":1182,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Yaml/Scanner.cs#L1146-L1182","documentation":"Stride.Core.Yaml's Scanner throws this while consuming an anchor (&name) or alias (*name) token in ScanAnchor. Immediately after '&' or '*', the next character must be blank, a line break, end-of-input, or one of the indicator characters '?:,]}%@`'. If the first character after '&'/'*' is an invalid indicator (e.g. another '&', '*', '!', '|', '>' or quote), the anchor/alias name would be empty or malformed, so a SyntaxErrorException is raised.","triggerScenarios":"Parsing a YAML document where an anchor starts with an invalid character (e.g. '&!foo' or '&|'), where an alias has an empty or invalid name ('*-' or '*!'), or where '&'/'*' is followed directly by a character that cannot begin a name, such as a quote or another anchor symbol. Any call path that tokenizes such YAML (Deserializer/Serializer round trips, YamlStream.Load) reaches ScanAnchor and throws.","commonSituations":"Hand-edited CI/CD or Kubernetes manifests with typos in anchors/aliases ('&-bad', '*&ref'), copy-paste artifacts where '&' or '*' lost the name characters, templating that emitted a bare '&' before an unparseable expression, or generated YAML from string concatenation that dropped the anchor name.","solutions":["Fix the YAML text: ensure every anchor has a valid non-empty name after '&' (letters/digits) and every alias references it via '*' followed by the same name, e.g. '&base' / '*base'.","Check the character immediately after '&' or '*' at the reported line/column; remove or escape stray indicators like '&!', '*-', '*!'.","If the YAML is generated, inspect the generator/templating code to confirm the anchor/alias name variable is populated before emission.","If you only need the document parsed loosely, pre-validate with a YAML linter (yamllint) to catch malformed anchors before loading.","Wrap deserialization in try/catch on YamlException to surface the Mark (line/column) in your own error reporting."],"exampleFix":"// before (invalid: '&' followed by '!')\nnode: &!config\n  key: value\nother: *!config\n\n// after (valid anchor and alias)\nnode: &config\n  key: value\nother: *config","handlingStrategy":"try-catch","validationCode":"static bool HasValidAnchorNames(string yaml)\n{\n    return System.Text.RegularExpressions.Regex.IsMatch(yaml, \"&[A-Za-z0-9][A-Za-z0-9_-]*\")\n        && !System.Text.RegularExpressions.Regex.IsMatch(yaml, \"[&*][^A-Za-z0-9 \\\\t\\\\n?:,\\\\]}%@`]\");\n}","typeGuard":"static bool IsValidAnchorName(string name) =>\n    !string.IsNullOrEmpty(name) && name.All(c => char.IsLetterOrDigit(c) || c == '-' || c == '_');","tryCatchPattern":"try\n{\n    var obj = deserializer.Deserialize<T>(input);\n}\ncatch (YamlException ex)\n{\n    // ex.Start/ex.End carry line & column of the bad anchor/alias\n    throw new FormatException($\"Invalid YAML anchor/alias at {ex.Start.Line}:{ex.Start.Column}: {ex.Message}\", ex);\n}","preventionTips":["Always give anchors non-empty alphanumeric names: &base, not & or &-foo","Alias names must exactly match a previously defined anchor","Lint YAML with yamllint in CI before deserialization","Avoid emitting '&' or '*' from templates without validating the name variable","Log ex.Start.Line/Column to pinpoint the offending character"],"tags":["yaml","parser","scanner","anchors"],"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"}