stride3d/stride · error · SyntaxErrorException
While scanning an anchor or alias, did not find expected alp
Error message
While scanning an anchor or alias, did not find expected alphabetic or numeric character.
What it means
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.
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.
Example fix
// before (invalid: '&' followed by '!') node: &!config key: value other: *!config // after (valid anchor and alias) node: &config key: value other: *config
Defensive patterns
Strategy: try-catch
Validate before calling
static bool HasValidAnchorNames(string yaml)
{
return System.Text.RegularExpressions.Regex.IsMatch(yaml, "&[A-Za-z0-9][A-Za-z0-9_-]*")
&& !System.Text.RegularExpressions.Regex.IsMatch(yaml, "[&*][^A-Za-z0-9 \\t\\n?:,\\]}%@`]");
} Type guard
static bool IsValidAnchorName(string name) =>
!string.IsNullOrEmpty(name) && name.All(c => char.IsLetterOrDigit(c) || c == '-' || c == '_'); Try / catch
try
{
var obj = deserializer.Deserialize<T>(input);
}
catch (YamlException ex)
{
// ex.Start/ex.End carry line & column of the bad anchor/alias
throw new FormatException($"Invalid YAML anchor/alias at {ex.Start.Line}:{ex.Start.Column}: {ex.Message}", ex);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected '{0}', got '{1}' (at line {2}, character {3}).
- Did not find expected <stream-start>.
- Did not find expected <document start>.
- While parsing a node, find undefined tag handle.
- While parsing a node, did not find expected node content.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/7fcd3a9f6b974e0d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/Scanner.cs:1164
// Consume the value.
StringBuilder value = new StringBuilder();
while (analyzer.IsAlpha())
{
value.Append(ReadCurrentCharacter());
}
// Check if length of the anchor is greater than 0 and it is followed by
// a whitespace character or one of the indicators:
// '?', ':', ',', ']', '}', '%', '@', '`'.
if (value.Length == 0 || !(analyzer.IsBlankOrBreakOrZero() || analyzer.Check("?:,]}%@`")))
{
throw new SyntaxErrorException(start, mark, "While scanning an anchor or alias, did not find expected alphabetic or numeric character.");
}
// Create a token.
if (isAlias)
{
return new AnchorAlias(value.ToString(), start, mark);
}
else
{
return new Anchor(value.ToString(), start, mark);
}
}
/// <summary>
/// Produce the TAG token.
/// </summary>
private void FetchTag()View on GitHub (pinned to 96fad776d2)